【问题标题】:HTML Purifier: allow user stylingHTML Purifier:允许用户样式
【发布时间】:2016-02-02 19:34:39
【问题描述】:

我们的软件最近因一项允许用户使用 HTML 和 CSS 设置自己的帖子样式的功能而受到 XSS 攻击。 是否可以在清理其他内容的同时允许用户对自己的论坛帖子进行样式设置?

这是我们目前的代码:

require_once 'module/purifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();

$config->set('Core.Encoding', 'ISO-8859-1');
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
$config->set('CSS.Trusted', true);
$config->set('HTML.Allowed', 'style,div[id|class]');

$purifier = new HTMLPurifier($config);
...
echo $purifier->purify($uheader); // $uheader contains the CSS code wrapped between "style" tags and a "div" class.

但是,在测试时,我仍然看不到应用了我的自定义样式。

更新 1

根据要求,HTML代码:

<img src="test"onerror="alert('XSS TEST')">
<style>
CSS_CODE_HERE
</style>
<div class="mainbar1-1">

我添加了“img src”标签只是为了确保正确过滤。

【问题讨论】:

  • 你能提供它不工作的html吗
  • 如果你不介意它真的很长,我可以。 :P
  • 不,只是询问其失败的特定标签
  • 添加了 HTML 代码。
  • 你使用 HTML Purifier 吗? htmlpurifier.org

标签: html css


【解决方案1】:

编辑 3:使用以下设置

$config->set('HTML.AllowedAttributes', '*.style');

【讨论】:

  • 这个不走运,样式标签仍在被过滤掉。
  • 对不起,使用我的设置没有 ---> $config->set('HTML.AllowedAttributes', array('*.style' => true));查看我的编辑
  • 去掉那条线后,“style”仍然会被过滤掉。但至少“div 类”不是。
  • 所以基本上你希望你的样式标签和带有类的 div 被 htmlpurifier rioght 忽略??
  • 是的,这两个标签都应该被允许,同时禁止任何其他标签。
猜你喜欢
  • 2011-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 1970-01-01
  • 2014-09-01
  • 1970-01-01
相关资源
最近更新 更多