过滤XSS的HTMLPurifier支持html5模块htmlpurifier-html5

      发布在:后端技术      评论:0 条评论

很多情况下过滤富文本恶意脚本攻击使用HTMLPurifier过滤,但是不支持html5,

有人通过设置配置让他支持,个人觉得很麻烦,于是谷歌搜索找到了htmlpurifier-html5。

安装参考

composer require xemlock/htmlpurifier-html5

创建函数

/* 过滤xss函数 */
public static function clearXSS($string){

$config = \HTMLPurifier_HTML5Config::createDefault();
$purifier = new \HTMLPurifier($config);
return $purifier->purify($string);
}

调用

$post['content'] = $this->request->post('content','','\app\Common::clearXSS');

来源:https://github.com/xemlock/htmlpurifier-html5

相关文章
热门推荐