用的白名单过滤,是我们的论坛自用的方法,也许考虑不周,欢迎来黑我们的论坛!
https://www.ebcms.com/forum.html

// 安全过滤
function safe_html($html){
$elements = [
'html' => [],
'body' => [],
'a' => ['target', 'href', 'title', 'class', 'style'],
'abbr' => ['title', 'class', 'style'],
'address' => ['class', 'style'],
'area' => ['shape', 'coords', 'href', 'alt'],
'article' => [],
'aside' => [],
'audio' => ['autoplay', 'controls', 'loop', 'preload', 'src', 'class', 'style'],
'b' => ['class', 'style'],
'bdi' => ['dir'],
'bdo' => ['dir'],
'big' => [],
'blockquote'=> ['cite', 'class', 'style'],
'br' => [],
'caption' => ['class', 'style'],
'center' => [],
'cite' => [],
'code' => ['class', 'style'],
'col' => ['align', 'valign', 'span', 'width', 'class', 'style'],
'colgroup' => ['align', 'valign', 'span', 'width', 'class', 'style'],
'dd' => ['class', 'style'],
'del' => ['datetime'],
'details' => ['open'],
'div' => ['class', 'style'],
'dl' => ['class', 'style'],
'dt' => ['class', 'style'],
'em' => ['class', 'style'],
'font' => ['color', 'size', 'face'],
'footer' => [],
'h1' => ['class', 'style'],
'h2' => ['class', 'style'],
'h3' => ['class', 'style'],
'h4' => ['class', 'style'],
'h5' => ['class', 'style'],
'h6' => ['class', 'style'],
'header' => [],
'hr' => [],
'i' => ['class', 'style'],
'img' => ['src', 'alt', 'title', 'width', 'height', 'id', 'class'],
'ins' => ['datetime'],
'li' => ['class', 'style'],
'mark' => [],
'nav' => [],
'ol' => ['class', 'style'],
'p' => ['class', 'style'],
'pre' => ['class', 'style'],
's' => [],
'section' => [],
'small' => [],
'span' => ['class', 'style'],
'sub' => ['class', 'style'],
'sup' => ['class', 'style'],
'strong' => ['class', 'style'],
'table' => ['width', 'border', 'align', 'valign', 'class', 'style'],
'tbody' => ['align', 'valign', 'class', 'style'],
'td' => ['width', 'rowspan', 'colspan', 'align', 'valign', 'class', 'style'],
'tfoot' => ['align', 'valign', 'class', 'style'],
'th' => ['width', 'rowspan', 'colspan', 'align', 'valign', 'class', 'style'],
'thead' => ['align', 'valign', 'class', 'style'],
'tr' => ['rowspan', 'align', 'valign', 'class', 'style'],
'tt' => [],
'u' => [],
'ul' => ['class', 'style'],
'video' => ['autoplay', 'controls', 'loop', 'preload', 'src', 'height', 'width', 'class', 'style'],
'embed' => ['src', 'height','align', 'width', 'class', 'style','type','pluginspage','wmode','play','loop','menu','allowscriptaccess','allowfullscreen'],
'source' => ['src', 'type']
];
$html = strip_tags($html,'<'.implode('><', array_keys($elements)).'>');
$xml = new \DOMDocument();
libxml_use_internal_errors(true);
if (!strlen($html)){
return '';
}
if ($xml->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . $html)){
foreach ($xml->getElementsByTagName("*") as $element){
if (!isset($elements[$element->tagName])){
$element->parentNode->removeChild($element);
}else{
for ($k = $element->attributes->length - 1; $k >= 0; --$k) {
if (!in_array($element->attributes->item($k) -> nodeName, $elements[$element->tagName])){
$element->removeAttributeNode($element->attributes->item($k));
}elseif (in_array($element->attributes->item($k) -> nodeName, ['href','src','style','background','size'])) {
$_keywords = ['javascript:','javascript.:','vbscript:','vbscript.:',':expression'];
$find = false;
foreach ($_keywords as $a => $b) {
if (false !== strpos(strtolower($element->attributes->item($k)->nodeValue),$b)) {
$find = true;
}
}
if ($find) {
$element->removeAttributeNode($element->attributes->item($k));
}
}
}
}
}
}
$html = substr($xml->saveHTML($xml->documentElement), 12, -14);
$html = strip_tags($html,'<'.implode('><', array_keys($elements)).'>');
return $html;
}

当然 还有一种漏洞就是url权限操作链接,可能引起版主误操作。

xss过滤方法的更多相关文章

  1. XSS 防御方法总结

    1. XSS攻击原理 XSS原称为CSS(Cross-Site Scripting),因为和层叠样式表(Cascading Style Sheets)重名,所以改称为XSS(X一般有未知的含义,还有扩 ...

  2. Asp.net Mvc中利用ValidationAttribute实现xss过滤

    在网站开发中,需要注意的一个问题就是防范XSS攻击,Asp.net mvc中已经自动为我们提供了这个功能.用户提交数据时时,在生成Action参数的过程中asp.net会对用户提交的数据进行验证,一旦 ...

  3. XSS过滤JAVA过滤器filter 防止常见SQL注入

    Java项目中XSS过滤器的使用方法. 简单介绍: XSS : 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩 ...

  4. 如何在springboot项目中进行XSS过滤

    简单介绍 XSS : 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS.恶意 ...

  5. spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,guava限流,定时任务案例, 发邮件

    本文介绍spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,定时任务案例 集成swagger--对于做前后端分离的项目,后端只需要提供接口访问,swagger提供了接口 ...

  6. python(Django之组合搜索、JSONP、XSS过滤 )

    一.组合搜索 二.jsonp 三.xss过滤 一.组合搜索 首先,我们在做一个门户网站的时候,前端肯定是要进行搜索的,但是如果搜索的类型比较多的话,怎么做才能一目了然的,这样就引出了组合搜索的这个案例 ...

  7. 04: 使用BeautifulSoup封装的xss过滤模块

    目录: 1.1 xss攻击简介 1.2 xss攻击解决方法 1.1 xss攻击简介返回顶部 1.简介 1. 跨站脚本(cross site script)为了避免与样式css混淆,所以简称为XSS. ...

  8. Python开发【Django】:组合搜索、JSONP、XSS过滤

    组合搜索 做博客后台时,需要根据文章的类型做不同的检索 1.简单实现 关联文件: from django.conf.urls import url from . import views urlpat ...

  9. Bypass xss过滤的测试方法

    0x00 背景 本文来自于<Modern Web Application Firewalls Fingerprinting and Bypassing XSS Filters>其中的byp ...

随机推荐

  1. Returning array from function in C

    以下为了通俗易懂,使用意译. I've here very intersting discussion about the best and common ways to return an arra ...

  2. 能详细说一下action:=cafree这句吗?好多书都没说清楚!

    关闭一个窗口有几种方式:最小化这个窗口,隐藏这个窗口,释放这个窗口,这句话就是说但这个窗口关闭的时候释放这个窗口,它应该是在form的onclose事件里面的 就是form.onclose() beg ...

  3. /etc/passwd字段信息

    root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nol ...

  4. 实验----Java的二维数组的应用及杨辉三角的编写

    (1) 编写一个程序,生成一个10*10的二维随机整数数组,并将该数组的每行最大值保存于一个一维数组中,将每列平均值保存于另外一个一维数组中并分别输出. (2) 编程输出杨辉三角的前10行. 找出一个 ...

  5. 华为HCNA乱学Round 12:NAT和easy IP

  6. PostgreSQL unlogged表

    PostgreSQL有一种介于正常表和临时表之间的类型表,称之为unlogged表,在该表新建的索引也属于unlogged,该表在写入数据时候并不将数据写入到持久的write-ahead log文件中 ...

  7. Laravel-admin 表单提交同时验证俩个以上的字段唯一值

    $name = isset(request()->all()['name']) ? request()->all()['name'] : ''; $id = isset(request() ...

  8. WINDOWS7 系统中建立文件夹映射

    如何在WIN7中建立文件夹映射,还有以及MKLINK的具体使用方法: 步骤如下: 1.以映射d盘1文件夹为例: 2.按win+r,输入cmd,点击确定: 3.提示符后输入mklink /J " ...

  9. 从入门到自闭之Python自定义模块

    自定义模块 定义:一个文件就是一个模块(能被调用的文件,模块就是一个工具箱,工具就是函数) 作用: 将代码文家化管理,提高可读性,避免重复代码 拿来就用(避免重复造轮子),python中类库比较多,提 ...

  10. USB键盘驱动分析

    简介 本文介绍USB驱动程序编写的流程,分析一个键盘的USB程序,基于linux-2.6.39 USB驱动概要 分层 主机层面的USB驱动的整体架构可以分成4层,自顶到下依次是 1.USB设备驱动:本 ...