使用 HTML Purifier 阻止指向自​​己网站的链接

发布于 2024-08-11 02:19:38 字数 524 浏览 4 评论 0原文

我使用了 HTML 净化器 来清除来自我面向公众的所见即所得编辑器的任何可疑内容。传入的 HTML 也会显示在网站的公共部分。

我已允许链接,并且还自动以纯文本形式链接 URL(使用净化器)。

有没有办法允许外部链接,但禁止链接到同一域?例如,我的域名是 www.example.com

http://www.google.com 将被链接。

http://www.example.com/logout/ 将不会被链接。

我正在考虑尽量减少恶意用户的干扰。我是否应该将注销链接为带有 POST 键/值对的表单操作来阻止这种情况发生?

谢谢

I have used HTML purifier to weed out any suspect stuff coming in from my public facing WYSIWYG editor. The incoming HTML is also displayed in the public portion of the website.

I have allowed links, and I also automatically linkify URLs in plain text (using the purifier).

Is there a way to allow external links, but ban links to the same domain? E.g my domain is www.example.com

http://www.google.com will be linked.

http://www.example.com/logout/ will not be linked.

I am looking at minimizing any interference from malicious users. Should I just make my logout link a form action with a POST key/value pair to stop this from happening?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

为人所爱 2024-08-18 02:19:38

您的登录/退出表单应始终为 POST-only。

不用担心验证值,但这是一个非常重要的安全问题 - 任何更改网络服务器状态的事务都应该是 POST 请求。您绝对不应该允许 http://example.com/object?action=delete 或任何其变体。 PHP 鼓励在这方面采取不良做法,但您应该始终使用其中之一,并且绝不允许同时使用两者。

如果您的用户可以将表单写入所见即所得编辑器,那么您将遇到比这更大的问题。

要回答您最初的问题,要禁用内部链接,请使用 URI.HostBlacklist 并确保设置 URI.MakeAbsolute

http://htmlpurifier.org/live/configdoc/plain.html#URI.HostBlacklist

Your login/out form should ALWAYS be POST-only.

Don't worry about a verification value, but this is a pretty important security issue - any transactions which change the state of the webserver should be POST requests. You should NEVER allow http://example.com/object?action=delete, or any variant thereof. PHP encourages bad practice in this matter, but you should ALWAYS use one or the other, and NEVER allow both.

If your users can write forms into your WYSIWYG editor, you've got far bigger problems than this.

To answer your original question, to disable internal links, use URI.HostBlacklist and be sure to set URI.MakeAbsolute:

http://htmlpurifier.org/live/configdoc/plain.html#URI.HostBlacklist

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