如何保护WYSIWYG免受XSS攻击

时间:2013-10-14 17:20:15

标签: php html xss wysiwyg

我正在使用WYSIWYG编辑器,我正在尝试允许安全的html属性,例如<table><a><img><strong>等,同时仍然阻止XSS。我使用HTML净化器和白名单标签的组合可以解决问题。

这是我的卫生设施:

function strip_tags_wysiwyg($string){
    include_once '../includes/htmlpurifier-4.5.0/library/HTMLPurifier.auto.php';
    $config = HTMLPurifier_Config::createDefault();
    $purifier = new HTMLPurifier($config);
    $clean_html = $purifier->purify($string);
    $clean_html=strip_tags($clean_html,"<a><address><em><strong><b><i><big><small><sub><sup><cite><code><img><ul><ol><li><dl><lh><dt><dd><br><p><table><th><td><tr><pre><blockquote><nowiki><h1><h2><h3><h4><h5><h6><hr>");

    return $clean_html;
}

今天,有人告诉我,当他们把这个HTML放进去时我仍然很脆弱:

<img src="x" onerror="alert(0)">

您有什么建议可以进一步保护我的代码?谢谢!

编辑:显然我正在运行PHP,因此PHP解决方案将是理想的。

0 个答案:

没有答案
相关问题