WMD Markdown 和服务器端

发布于 2024-07-27 21:59:00 字数 621 浏览 9 评论 0原文

过去 2 天我一直致力于 WMDMarkdown,我没有找到安全的股票数据解决方案。 我希望用户能够发布 HTML/XML (使用大规模杀伤性武器)在我的网站上。

目前,我以 Markdown 格式存储数据,但如果我禁用 JavaScript,用户可以轻松推送 XSS。 如果我 strip_tagshtml_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 技术交流群。

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

发布评论

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

评论(1

染火枫林 2024-08-03 21:59:00

要“清理”您的 HTML,您可以使用 HTML Purifier 之类的工具

基本上,它允许您指定允许哪些标签/属性,并且仅保留这些标签/属性。

它还生成有效的 (X)HTML 代码作为输出——这很好。

您可以在 演示页面 上看到,有一个示例几乎与您发布的 XSS 完全相同,顺便说一句; -)

例如,您可以尝试使用如下所示的一些 HTML:

test <img src="javascript:evil();" onload="evil();" /> 
test <img src="http://www.google.com/a.Png" /> test2

输出为:

test  test <img src="http://www.google.com/a.Png" alt="a.Png" /> test2

带有 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 :

test <img src="javascript:evil();" onload="evil();" /> 
test <img src="http://www.google.com/a.Png" /> test2

The output is :

test  test <img src="http://www.google.com/a.Png" alt="a.Png" /> test2

The img tag with XSS has not been kept ; the other one has ; and there's been an alt 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" ? )

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