Skip to content

Commit

Permalink
添加全局过滤机制(默认关闭)
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Dec 13, 2014
1 parent b7a76e2 commit e16645a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions ThinkPHP/Common/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function I($name,$default='',$filter=null,$datas=null) {
}else{ // 变量默认值
$data = isset($default)?$default:NULL;
}
is_array($data) && array_walk_recursive($data,'filter_exp');
is_array($data) && array_walk_recursive($data,'think_filter');
return $data;
}
Expand Down Expand Up @@ -1468,8 +1468,11 @@ function send_http_status($code) {
}
}

function filter_exp(&$value){
if(preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR)$/i',$value)){
function think_filter(&$value){
// TODO 其他安全过滤

// 过滤查询特殊字符
if(preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|LIKE|NOTLIKE|BETWEEN|IN)$/i',$value)){
$value .= ' ';
}
}
Expand Down
10 changes: 9 additions & 1 deletion ThinkPHP/Library/Think/App.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class App {
static public function init() {
// 加载动态应用公共文件和配置
load_ext_file(COMMON_PATH);

// 定义当前请求的系统常量
define('NOW_TIME', $_SERVER['REQUEST_TIME']);
define('REQUEST_METHOD',$_SERVER['REQUEST_METHOD']);
Expand All @@ -34,6 +34,13 @@ static public function init() {
// URL调度
Dispatcher::dispatch();

if(C('REQUEST_VARS_FILTER')){
// 全局安全过滤
array_walk_recursive($_GET, 'think_filter');
array_walk_recursive($_POST, 'think_filter');
array_walk_recursive($_REQUEST, 'think_filter');
}

// URL调度结束标签
Hook::listen('url_dispatch');

Expand Down Expand Up @@ -150,6 +157,7 @@ static public function exec() {
}
}
}
array_walk_recursive($args,'think_filter');
$method->invokeArgs($module,$args);
}else{
$method->invoke($module);
Expand Down

0 comments on commit e16645a

Please sign in to comment.