Zend Framework 输入/输出 XSS 过滤:Strip Tags、Textile、BBCode
在我的 CMS 应用程序中,管理用户可以通过所见即所得编辑器添加 HTML 内容,该编辑器由 HTMLPurifier 过滤。我现在想添加留言板功能。我计划使用 Zend StripTags 过滤器 无需白名单即可删除所有 HTML,然后通过使用 Zend 的 BBCode 或 Textile 解析器。
我的问题是:
- 如果我没有白名单,XSS 可以通过
StripTags
吗? - 添加 BBCode 或 Textile 作为输出解析器是否会重新引入 XSS 的可能性?
In my CMS application, administration users can add HTML content via a WYSIWYG editor that gets filtered by HTMLPurifier. I am now wanting to add a message board functionality. I am planning on using the Zend StripTags Filter without a whitelist to remove all HTML, and then provide for rich markup by using Zend's BBCode or Textile parsers.
These are my questions:
- Can XSS make it through
StripTags
if I have no whitelist? - Does adding BBCode or Textile as an output parser reintroduce the possibility of XSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读一篇关于 Markdown 的文章之后,以及 该帖子的答案中链接的另一篇文章,看来在文档中重新引入 XSS 不仅是可能,但微不足道。为了安全起见,我需要通过 HTMLPurifier 运行内容,作为输出过滤器链。因为我担心 HTMLPurifier 作为输出过滤器的性能,所以我正在考虑使用 Wibble 代替。
这仍然没有回答第一个问题,但就我而言,这一步是不必要的。
我在尝试使用它们时发现 Zend 的 BBCode 和 Textile 有严重的错误。我改为使用 PHP Markdown。另外,Wibble 似乎还没有准备好投入生产。
我在数据库中使用了两列:
content
和html
。content
列保存用户提交的文本。保存记录时,我使用 PHP Markdowncontent 转换为 HTML >,将其传递给 HTMLPurifier ,然后将该值保存到html
列中。我不会以这种方式转换所有观点。实现细节
我把PHP Markdown放在这里:
library /markdown.php
。在我的活动记录模型中,使用Zend_Db_Table_Row_Abstract
,我使用_insert()
和_update()
挂钩在保存记录之前处理值:这是我的 HTMLPurifier 过滤器:
After reading a post about Markdown here on SO, and another article linked in an answer to that post, it appears that reintroducing XSS into a document is not only possible, but trivial. To be secure, I will need to run content through HTMLPurifier as the final step in the output filter chain. Because I am concerned with the performance of HTMLPurifier as an output filter, I am looking into using Wibble instead.
This still leaves the first question unanswered, but in my case, that step will be unnecessary.
I discovered when trying to use them, that Zend's BBCode and Textile are horribly buggy. I instead used PHP Markdown. Also, Wibble doesn't seem like it's production ready yet.
I used two columns in my database:
content
andhtml
. Thecontent
column holds the user-submitted text. When saving the record, I convertcontent
to HTML with PHP Markdown, pass it through HTMLPurifier and then save that value to thehtml
column. I am not converting will every view that way.Implementation Details
I put PHP Markdown here:
library/markdown.php
. In my active record model, usingZend_Db_Table_Row_Abstract
, I use the_insert()
and_update()
hooks to process the values before the record is saved:Here is my HTMLPurifier filter: