本帖最后由 jshnr006 于 2014-11-14 09:51 编辑
最近搭建Discuz!x3.2和Ucenter1.6.0的时候,发现经常报通知失败,跟踪发现Discuz!x2.5是不存在该问题的,原因是 source/class/discuz/discuz_application.php
该文件有一个校验函数叫 _xss_check
下面是源码
Discuz!x2.5
- private function _xss_check() {
- $temp = strtoupper(urldecode(urldecode($_SERVER['REQUEST_URI'])));
- if(strpos($temp, '<') !== false || strpos($temp, '"') !== false || strpos($temp, 'CONTENT-TRANSFER-ENCODING') !== false) {
- system_error('request_tainting');
- }
- return true;
- }
复制代码 Discuz!x3.2
- private function _xss_check() {
- static $check = array('"', '>', '<', '\'', '(', ')', 'CONTENT-TRANSFER-ENCODING');
- if(isset($_GET['formhash']) && $_GET['formhash'] !== formhash()) {
- system_error('request_tainting');
- }
- if($_SERVER['REQUEST_METHOD'] == 'GET' ) {
- $temp = $_SERVER['REQUEST_URI'];
- } elseif(empty ($_GET['formhash'])) {
- $temp = $_SERVER['REQUEST_URI'].file_get_contents('php://input');
- } else {
- $temp = '';
- }
- if(!empty($temp)) {
- $temp = strtoupper(urldecode(urldecode($temp)));
- foreach ($check as $str) {
- if(strpos($temp, $str) !== false) {
- system_error('request_tainting');
- }
- }
- }
- return true;
- }
复制代码 对比发现,新版代码的问题在 $temp = $_SERVER['REQUEST_URI'].file_get_contents('php://input'); ,如果是Ucenter下发的通知
$temp拿到的数据是 get的数据和post的数据
因为ucenter 发的post数据是xml格式, 所以下面的检测是肯定会走到 system_error('request_tainting');的
- foreach ($check as $str) {
- if(strpos($temp, $str) !== false) {
- system_error('request_tainting');
- }
复制代码 因为$check包含了 '<' '>' 这些符号
- static $check = array('"', '>', '<', '\'', '(', ')', 'CONTENT-TRANSFER-ENCODING');
复制代码
|