用的白名单过滤,是我们的论坛自用的方法,也许考虑不周,欢迎来黑我们的论坛!
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. ANSI C遍历二维数组指针地址

    #include <stdio.h> int main() { ][] = {,,,}; //等价于{{1,2},{3,4}}; ; i < ; i++) { ; j < ; ...

  2. Python实现将不规范的英文名字首字母大写

    Python实现将不规范的英文名字首字母大写 这篇文章给大家主要介绍的是利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.文中给出了三种解决方法,大家可以根据需要选 ...

  3. python中复制文件

    1.复制单个文件 1.把home下的test.yml复制到root目录下 In [43]: import shutil In [42]: shutil.copy('/home/test.yml','/ ...

  4. WPF 非UI线程更新UI界面的各种方法小结

    转载:https://www.cnblogs.com/bdbw2012/articles/3777594.html 我们知道只有UI线程才能更新UI界面,其他线程访问UI控件被认为是非法的.但是我们在 ...

  5. Keil version 2汉字显示乱码的解决方案

    Keil version 2汉字显示乱码的解决方案 Keil2对汉字的支持不好,在删除汉字字符时,一不小心会删除一半而留一半,这时并不显示错误或乱码,而是貌似都删除了,但编译程序可能会报错,这时再查错 ...

  6. U盘安装Ubuntu Server CD-ROM挂载失败

    U盘安装 Ubuntu Server 发生Failed to copy file from CD-ROM问题 使用UltraISO制作Ubuntu Server安装盘,在安装过程中出现[!!] Loa ...

  7. jmeter性能测试总结

    一.性能测试问题记录: Ⅰ.秒杀的失败率了在96.45%,原因 Query对于 活动的秒杀采用的是0.5秒,刷新缓存的策略在活动中优惠券被秒杀一空 下架前,短暂的时间内仍能够查询到 这个活动架构中采用 ...

  8. HTML笔记(三) 表格和列表

    本篇记录表格 (table) 和有序列表 (ordered list) \ 无序列表 (unordered list) 的部分用法 1.表格table 表格标签 使用 <table> 定义 ...

  9. ABC050D/ARC066D Xor Sum

    题目链接 题目大意 可表为 $(a \xor b, a + b)$ 的二元组有多少个? $a, b$ 满足下列约束条件: ① $a, b$ 是非负整数: ② $a + b \le N$,$N$ 是给定 ...

  10. java循环队列实现代码

    public class Queue { //队首指针 private int front; //队尾指针 private int rear; //数组 private int[] arr; //数组 ...