我应该允许用户生成内容的 HTML 标签白名单?
总之,
我正在使用 PHP 构建一个小型网站。在该网站中,我收到用户生成的文本内容。我想允许一些安全的 HTML 标签(例如,格式化)以及 MathML。如何为 strip_tags()
函数编译白名单?是否有我可以使用的公认的白名单?
All,
I am building a small site using PHP. In the site, I receive user-generated text content. I want to allow some safe HTML tag (e.g., formatting) as well as MathML. How do I go about compiling a white list for a strip_tags()
function? Is there a well accepted white list I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
标准的
strip_tags
函数对于安全性来说是不够的,因为它根本不验证属性。明确使用更完整的库来完全净化 HTML,例如 HTML Purifier。The standard
strip_tags
function is not enough for security, since it doesn't validate attributes at all. Use a more complete library explicitly for the purpose of completely sanitizing HTML like HTML Purifier.