0

TLDR;我想在替换邪恶数据时启用 xss_clean() 的数据库日志记录。


我想在 Security.php 中启用 xss_clean() 函数的数据库日志记录,基本上我想做的是知道我成功输入 xss_clean() 的输入是否被识别为其中包含被过滤掉的恶意数据或不。

所以基本上:

$str = '<script>alert();</script>';
$str = xss_clean($str);

对我来说理想的情况是:

  1. 从 XSS 中清除字符串
  2. 返回干净的 $str
  3. 将有关恶意数据(以及最终登录的用户)的信息输入到数据库中

据我在 Security.php 文件中看到的,没有什么可以为我解决这个问题,或者可以通过钩子等来解决这个问题。我当然可能弄错了。

由于没有记录在 Security.php 中进行了多少替换 - 我是否被迫扩展 Security.php,将当前代码复制粘贴到原始函数中并对其进行更改以支持这一点?或者对于 CodeIgniter 的未来更新(尤其是被篡改/扩展的文件)是否有更干净和安全的解决方案?

4

1 回答 1

1

您需要扩展 Security 类,但如果您只需要输入/输出的日志,则绝对不需要复制和粘贴任何代码。类似于以下内容的内容将允许您这样做:

Class My_Security extends CI_Security {

    public function xss_clean($str, $is_image = FALSE) {
        // Do whatever you need here with the input ... ($str, $is_image)

        $str = parent::xss_clean($str, $is_image);

        // Do whatever you need here with the output ... ($str)

        return $str;
    }

}

这样,您只是包装现有功能并弄乱输入/输出。如果您担心对底层方法的更改,则可以通过使用 PHP 函数get_args透明地传递参数对象来更加向前兼容。

于 2011-07-06T03:52:11.800 回答