Skip to content
This repository was archived by the owner on Oct 16, 2022. It is now read-only.

Commit 3254d6c

Browse files
committed
Fix XSS vulnerability (#6)
1 parent 4c0cfd7 commit 3254d6c

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

ThinkPHP/Common/functions.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,24 +1033,31 @@ function is_ssl() {
10331033
* @param string $msg 重定向前的提示信息
10341034
* @return void
10351035
*/
1036-
function redirect($url, $time=0, $msg='') {
1036+
function redirect($url, $time = 0, $msg = '')
1037+
{
10371038
//多行URL地址支持
1038-
$url = str_replace(array("\n", "\r"), '', $url);
1039-
if (empty($msg))
1040-
$msg = "系统将在{$time}秒之后自动跳转到{$url}";
1039+
$url = str_replace(array("\n", "\r"), '', $url);
1040+
$url = htmlspecialchars(strip_tags($url), ENT_QUOTES, 'UTF-8', false);
1041+
1042+
if (empty($msg)) {
1043+
$msg = "系统将在{$time}秒之后自动跳转到{$url}";
1044+
}
1045+
10411046
if (!headers_sent()) {
10421047
// redirect
10431048
if (0 === $time) {
10441049
header('Location: ' . $url);
10451050
} else {
10461051
header("refresh:{$time};url={$url}");
1047-
echo($msg);
1052+
echo ($msg);
10481053
}
10491054
exit();
10501055
} else {
1051-
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
1052-
if ($time != 0)
1056+
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
1057+
if (0 != $time) {
10531058
$str .= $msg;
1059+
}
1060+
10541061
exit($str);
10551062
}
10561063
}

ThinkPHP/Mode/Api/functions.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -689,24 +689,31 @@ function dump($var, $echo=true, $label=null, $strict=true) {
689689
* @param string $msg 重定向前的提示信息
690690
* @return void
691691
*/
692-
function redirect($url, $time=0, $msg='') {
692+
function redirect($url, $time = 0, $msg = '')
693+
{
693694
//多行URL地址支持
694-
$url = str_replace(array("\n", "\r"), '', $url);
695-
if (empty($msg))
696-
$msg = "系统将在{$time}秒之后自动跳转到{$url}";
695+
$url = str_replace(array("\n", "\r"), '', $url);
696+
$url = htmlspecialchars(strip_tags($url), ENT_QUOTES, 'UTF-8', false);
697+
698+
if (empty($msg)) {
699+
$msg = "系统将在{$time}秒之后自动跳转到{$url}";
700+
}
701+
697702
if (!headers_sent()) {
698703
// redirect
699704
if (0 === $time) {
700705
header('Location: ' . $url);
701706
} else {
702707
header("refresh:{$time};url={$url}");
703-
echo($msg);
708+
echo ($msg);
704709
}
705710
exit();
706711
} else {
707-
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
708-
if ($time != 0)
712+
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
713+
if (0 != $time) {
709714
$str .= $msg;
715+
}
716+
710717
exit($str);
711718
}
712719
}
@@ -1106,4 +1113,4 @@ function think_filter(&$value){
11061113
if(preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i',$value)){
11071114
$value .= ' ';
11081115
}
1109-
}
1116+
}

0 commit comments

Comments
 (0)