在我的页面上显示用户输入
在我们的应用程序中,我们允许用户使用所见即所得编辑器编写他们的简历,但它通常包含损坏我们页面的不良 HTML。在 iframe 中显示用户简介这样就不会影响页面的其余部分是个好主意吗?或者有更好的选择吗?
谢谢
In our application, we allow user's to write their Bio using a WYSIWYG editor, but it often contains bad HTML that breaks our page. Is it a good idea to show the user bio inside an iframe so it doesn't affect the rest of the page? Or any better options?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要考虑限制您的用户使用 Markdown,就像 Stack Overflow 用于个人资料、答案等。
如需进一步阅读,您可能需要检查以下内容:
You may want to consider limiting your users to Markdown, just like what Stack Overflow uses for profiles, answers, etc.
For further reading, you may want to check the following:
这不是一个坏主意,但为什么不在保存之前验证 html 呢?或者只是丑陋而已,并不坏?大多数编辑器都有 ie clean Office 格式。或者是业务要求允许输入 HTML?
但 iframe 是最安全的方法,我建议继续使用!
Its thats not a bad idea, but why dont you validate the html before you save it? Or is it not bad just plain ugly? Most editors do have i.e clean office formatting. Or is it a bussiness requirement to allow entering HTML?
But iframe is the most safe way of doing it, I'd say go for it!
解决方案是过滤 HTML,以确保其“正常”:
一个很棒的工具就是 HTMLPurifier (引用) :
基本上,一旦用户输入了 HTML,在将其保存到数据库之前,您将通过 HTML Purifier 传递它,这将确保其有效,并删除您未指定为的任何标记/属性“允许”。
A solution would be to filter the HTML, to make sure it's "OK" :
A great tool that does that is HTMLPurifier (quoting) :
Basically, once the HTML has been typed by the user, before saving it to your database, you'd pass it through HTML Purifier, which will make sure it's valid, and remove any tag/attribute that you didn't specify as "allowed".