WMD Markdown 和服务器端
过去 2 天我一直致力于 WMD 和 Markdown,我没有找到安全的股票数据解决方案。 我希望用户能够发布 HTML/XML (使用大规模杀伤性武器)在我的网站上。
目前,我以 Markdown 格式存储数据,但如果我禁用 JavaScript,用户可以轻松推送 XSS。 如果我 strip_tags
或 html_entities
所有数据,我都会丢失用户 HTML/XML 。 我该怎么做?
在我看来,我必须 html_entities
只是 pre /pre 之间的代码,但如何?! 我的数据是 Markdown 格式的。
之后,我该怎么做才能禁止 XSS 属性:
<img src="javascript:alert('xss');" />
I have worked the last 2 days on WMD and Markdown, and I don't find THE solution for stock data with security. I would like users to be able to post HTML/XML <code> (with WMD) on my site.
For the moment, I stock data in the Markdown format, but if I disable JavaScript the user can easily push XSS. If I strip_tags
or html_entities
all data I lose the user HTML/XML <code>. How can I do it?
In my opinion I must html_entities
just the code between pre /pre, but how?! My data is in Markdown.
After, what can I do to forbid XSS attributes:
<img src="javascript:alert('xss');" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要“清理”您的 HTML,您可以使用
HTML Purifier
之类的工具基本上,它允许您指定允许哪些标签/属性,并且仅保留这些标签/属性。
它还生成有效的 (X)HTML 代码作为输出——这很好。
您可以在 演示页面 上看到,有一个示例几乎与您发布的 XSS 完全相同,顺便说一句; -)
例如,您可以尝试使用如下所示的一些 HTML:
输出为:
带有 XSS 的
img
标记尚未保留; 另一个有; 并且添加了一个alt
属性,以符合标准。它可能无法解决您的所有问题,但如果您为用户提供了输入 HTML 的可能性,那么它绝对有用(我敢说“它是必备的”吗?)
To "clean" your HTML, you could use a tool like
HTML Purifier
Basically, it allows you to specify which tags/attributes are allowed, an only keeps those.
It also produces valid (X)HTML code as ouput -- which is nice.
You can see on the demo page there is an example that is almost exactly the XSS you posted, btw ;-)
For instance, you can try with some HTML like this one :
The output is :
The
img
tag with XSS has not been kept ; the other one has ; and there's been analt
attribute added, to be standard-compliant.It might not solve all your problems, but if you are giving users the possiblity to input HTML, is it definitly useful (would I dare saying "it's a must-have" ? )