我正在尝试purify一个字符串以防止XSS,但是如果一个字符串没有脚本标记,而是具有html属性,那么这个字符串就不是purify。
示例:
$str = 'http://www.example.com/54f74"onmouseover%3d"alert(1)"style%3d"position%3aabsolute%3bwidth%3a100%25%3bheight%3a100%25%3btop%3a0%3bleft%3a0%3b"54f74';
$purifier = new CHtmlPurifier();
var_dump(
$str,
$purifier->purify($str)
);结果:
string 'http://www.example.com/54f74"onmouseover%3d"alert(1)"style%3d"position%3aabsolute%3bwidth%3a100%25%3bheight%3a100%25%3btop%3a0%3bleft%3a0%3b"54f74' (length=145)
string 'http://www.example.com/54f74"onmouseover%3d"alert(1)"style%3d"position%3aabsolute%3bwidth%3a100%25%3bheight%3a100%25%3btop%3a0%3bleft%3a0%3b"54f74' (length=145)发布于 2015-07-20 16:44:23
是的,因为该字符串是有效的XSS无关HTML。如果您计划在属性中使用它,则可以使用HTML的内部AttrDef类手动净化它。对于URL,您可能需要HTMLPurifier_AttrDef_URI
$def = new HTMLPurifier_AttrDef_URI();
$config = HTMLPurifier_Config::default();
$context = new HTMLPurifier_Context();
$pure_url = $def->validate($your_url, $config, $context);https://stackoverflow.com/questions/31517359
复制相似问题