【问题标题】:Is this code realy XSS proof?这段代码真的是 XSS 证明吗?
【发布时间】:2016-03-27 14:48:27
【问题描述】:

我有以下php XSS过滤功能:

<?php
function xssfilter($inp){
    $inp = html_entity_decode(urldecode($inp));
    $inp = preg_replace('/!/','',$inp);
    if (preg_match('/script|on|xmlns|data/iu',$inp)){
        while(preg_match('/script|on|xmlns|data/iu',$inp)){
            $inp = preg_replace('/(script)|(on)|(xmlns)|(data)/iu','NO!',$inp);
        }
    }
    return $inp;
}
?>

显然您可以在此处上传远程脚本,但我的问题是您是否可以通过某种方式绕过正则表达式?

【问题讨论】:

  • 这个问题听起来像个小问题。
  • 看起来编写函数的人对如何清理内容并没有很好的了解。 URL 解码、实体解码、替换感叹号、替换一些关键字......看起来他们只是在问题上扔东西,希望它能解决问题。

标签: php regex validation xss user-input


【解决方案1】:

不,这至少有一个明显的缺陷。您可以像这样插入包含 JavaScript 的链接标签:

<a href="&#x26;&#x23;&#x78;&#x36;&#x41;&#x3B;&#x26;&#x23;&#x78;&#x36;&#x31;&#x3B;&#x26;&#x23;&#x78;&#x37;&#x36;&#x3B;&#x26;&#x23;&#x78;&#x36;&#x31;&#x3B;&#x26;&#x23;&#x78;&#x37;&#x33;&#x3B;&#x26;&#x23;&#x78;&#x36;&#x33;&#x3B;&#x26;&#x23;&#x78;&#x37;&#x32;&#x3B;&#x26;&#x23;&#x78;&#x36;&#x39;&#x3B;&#x26;&#x23;&#x78;&#x37;&#x30;&#x3B;&#x26;&#x23;&#x78;&#x37;&#x34;&#x3B;: alert('XSS');">Innocent Link</a>

在 Chrome 中阻止这种攻击的唯一方法是它内置了 XSS 保护。你的 XSS 保护并不能阻止它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 2015-07-19
    相关资源
    最近更新 更多