在我的页面上显示用户输入

发布于 2024-08-23 14:47:55 字数 120 浏览 9 评论 0原文

在我们的应用程序中,我们允许用户使用所见即所得编辑器编写他们的简历,但它通常包含损坏我们页面的不良 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

断舍离 2024-08-30 14:47:55

这不是一个坏主意,但为什么不在保存之前验证 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!

泪冰清 2024-08-30 14:47:55

解决方案是过滤 HTML,以确保其“正常”:

  • 有效的 HTML
  • 仅包含您想要允许的标签
  • 并且不会导致任何安全问题。

一个很棒的工具就是 HTMLPurifier (引用)

HTML Purifier 是一个符合标准的
用 PHP 编写的 HTML 过滤器库。
HTML Purifier 不仅会删除所有
恶意代码(更广为人知的名称是 XSS)
经过彻底审核,安全可靠
宽容的白名单,它也会
确保您的文件
符合标准

基本上,一旦用户输入了 HTML,在将其保存到数据库之前,您将通过 HTML Purifier 传递它,这将确保其有效,并删除您未指定为的任何标记/属性“允许”

A solution would be to filter the HTML, to make sure it's "OK" :

  • Valid HTML
  • That only contain the tags you want to allow
  • And doesn't cause any security problem.

A great tool that does that is HTMLPurifier (quoting) :

HTML Purifier is a standards-compliant
HTML filter library written in PHP.
HTML Purifier will not only remove all
malicious code (better known as XSS)
with a thoroughly audited, secure yet
permissive whitelist, it will also
make sure your documents are
standards compliant

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文