gpt4 book ai didi

php - 避免javascript执行的最佳方法

转载 作者:可可西里 更新时间:2023-11-01 00:49:51 24 4
gpt4 key购买 nike

我在我的应用程序中使用 PHP 和 Zend Framework。用户可以输入一些 HTML,管理员可以看到这个 HTML。我想避免 XSS 注入(inject)。除了任何 javascript 之外,所有 HTML 都应按原样显示。我试图删除 script 标签,但它不安全。用户可以将 javascript 添加到 onclick 或其他事件。

谢谢。

最佳答案

如果您希望像这样从 XSS 中清理用户输入,我会考虑使用 HTML purifier

仅删除脚本标签是不够的,您会错过任何人们可以添加的 javascript 内联,等等。

HTML purifier但是会为您删除所有内容。从他们的网站:

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, something only achievable with a comprehensive knowledge of W3C's specifications.

关于php - 避免javascript执行的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9942725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com