php 一个过虑xxs的代码
一个过虑xxs的代码
public static function removeXSS($str) {
$str = str_replace('<!-- -->', '', $str);
$str = preg_replace('~/\*[ ]+\*/~i', '', $str);
$str = preg_replace('/\\\0{0,4}4[0-9a-f]/is', '', $str);
$str = preg_replace('/\\\0{0,4}5[0-9a]/is', '', $str);
$str = preg_replace('/\\\0{0,4}6[0-9a-f]/is', '', $str);
$str = preg_replace('/\\\0{0,4}7[0-9a]/is', '', $str);
$str = preg_replace('/�{0,8}[0-9a-f]{2};/is', '', $str);
$str = preg_replace('/�{0,8}[0-9]{2,3};/is', '', $str);
$str = preg_replace('/�{0,8}[0-9]{2,3};/is', '', $str); $str = htmlspecialchars($str);
//$str = preg_replace('/</i', '<', $str);
//$str = preg_replace('/>/i', '>', $str); // 非成对标签
$lone_tags = array("img", "param", "br", "hr");
foreach ($lone_tags as $key => $val)
{
$val = preg_quote($val);
$str = preg_replace('/<' . $val . '(.*)(\/?)>/isU', '<' . $val . "\\1\\2>", $str);
$str = self::transCase($str);
$str = preg_replace_callback('/<' . $val . '(.+?)>/i', create_function('$temp', 'return str_replace(""","\"",$temp[0]);'), $str);
}
$str = preg_replace('/&/i', '&', $str); // 成对标签
$double_tags = array("table", "tr", "td", "font", "a", "object", "embed", "p", "strong", "em", "u", "ol", "ul", "li", "div", "tbody", "span", "blockquote", "pre", "b", "font");
foreach ($double_tags as $key => $val)
{
$val = preg_quote($val);
$str = preg_replace('/<' . $val . '(.*)>/isU', '<' . $val . "\\1>", $str);
$str = self::transCase($str);
$str = preg_replace_callback('/<' . $val . '(.+?)>/i', create_function('$temp', 'return str_replace(""","\"",$temp[0]);'), $str);
$str = preg_replace('/<\/' . $val . '>/is', '</' . $val . ">", $str);
}
// 清理js
$tags = Array(
'javascript',
'vbscript',
'expression',
'applet',
'meta',
'xml',
'behaviour',
'blink',
'link',
'style',
'script',
'embed',
'object',
'iframe',
'frame',
'frameset',
'ilayer',
'layer',
'bgsound',
'title',
'base',
'font'
); foreach ($tags as $tag)
{
$tag = preg_quote($tag);
$str = preg_replace('/' . $tag . '\(.*\)/isU', '\\1', $str);
$str = preg_replace('/' . $tag . '\s*:/isU', $tag . '\:', $str);
} $str = preg_replace('/[\s]+on[\w]+[\s]*=/is', '', $str); Return $str;
}
链接地址:https://github.com/sillydong/CZD_Yaf_Extension/blob/master/library/Tools.php
不错的yaf封闭mysql地址 https://github.com/jonsonxu/yaf
php 一个过虑xxs的代码的更多相关文章
- 给 VS 2010 选一个好用的代码行数统计器(转)
给 VS 2010 选一个好用的代码行数统计器 分类: Tricks2011-02-25 05:40 3891人阅读 评论(0) 收藏 举报 2010c 推荐一个VS插件,支持2005/2008/20 ...
- 一个 11 行 Python 代码实现的神经网络
一个 11 行 Python 代码实现的神经网络 2015/12/02 · 实践项目 · 15 评论· 神经网络 分享到:18 本文由 伯乐在线 - 耶鲁怕冷 翻译,Namco 校稿.未经许可,禁止转 ...
- 做了一个简易的git 代码自动部署脚本
做了一个简易的git 代码自动部署脚本 http://my.oschina.net/caomenglong/blog/472665 发表于2个月前(2015-06-30 21:08) 阅读(200 ...
- 想做一个整合开源安全代码扫描工具的代码安全分析平台 - Android方向调研
想做一个整合开源安全代码扫描工具的代码安全分析平台 - Android方向调研 http://blog.csdn.net/testing_is_believing/article/details/22 ...
- 一个只有99行代码的JS流程框架(二)
欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 张镇圳,腾讯Web前端高级工程师,对内部系统前端建设有多年经验,喜欢钻研捣鼓各种前端组件和框架. 导语 前面写 ...
- html是什么?一个完整的html代码告诉你(完整实例版)
html什么意思?这篇文章主要为大家仔细的解释了HTML文档的一个基础的完整代码,还有具体的实例解释,让大家能一下就看懂HTML的基础结构和用法.下面我们一起来看看吧一.html是什么?点击查看htm ...
- 点击文字弹出一个DIV层窗口代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- (转)如何基于FFMPEG和SDL写一个少于1000行代码的视频播放器
原文地址:http://www.dranger.com/ffmpeg/ FFMPEG是一个很好的库,可以用来创建视频应用或者生成特定的工具.FFMPEG几乎为你把所有的繁重工作都做了,比如解码.编码. ...
- 推荐一个小而美的Python代码格式化工具
代码可读性是评判代码质量的标准之一,有一个衡量代码质量的标准是 Martin 提出的 “WFT” 定律,即每分钟爆出 “WTF” 的次数.你在读别人代码或者做 Code Review 的时候有没有 “ ...
随机推荐
- SpringBoot静态资源访问+拦截器+Thymeleaf模板引擎实现简单登陆
在此记录一下这十几天的学习情况,卡在模板引擎这里已经是四天了. 对Springboot的配置有一个比较深刻的认识,在此和大家分享一下初学者入门Spring Boot的注意事项,如果是初学SpringB ...
- 扩展gcd codevs 1200 同余方程
codevs 1200 同余方程 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 求关 ...
- [转]Intel haxm安装失败问题解决
在安装Intel haxm为安卓模拟器加速时,会遇到提示VT-X未开启问题,问题提示如下图 工具/原料 Intel haxm 安卓模拟器 方法/步骤 1 确认你的处理器是否是Intel的,如果是AMD ...
- Matlab 矩阵【Mark】
一.矩阵的表示在MATLAB中创建矩阵有以下规则: a.矩阵元素必须在”[ ]”内: b.矩阵的同行元素之间用空格(或”,”)隔开: c.矩阵的行与行之间用”;”(或回车符)隔开: d.矩阵的元素可以 ...
- Shell基础学习(三) 传递参数
我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 以下实例我们向脚本传递三个参数 ...
- char *p 与char p[]
char *p=a和char*p=&a 前者p是一个指针变量后者p是一个char型变量 char *p = "123"; 为全局数组,放在常量区,而非普通数据段(静态存储区 ...
- php curl 抓取
<?php set_time_limit(0); function curl_multi($urls) { if (!is_array($urls) or count($urls) == 0) ...
- Changing the Output Voltage of a Switching Regulator on the Fly
http://www.powerguru.org/changing-the-output-voltage-of-a-switching-regulator-on-the-fly/ There are ...
- gdb逆向调试
http://blog.csdn.net/yiling2012/article/details/35988361
- linux 多线程查看工具
参考: http://www.oschina.net/translate/command-line-tools-to-monitor-linux-performance?cmp&p=1 htt ...