Discuz!系統的_xss_check()函數原本的意義是為了論壇安全,防止XSS攻擊,一般網站使用是不會出現什么問題的,但是有些網站要接入第三方接口,當第三方接口向本站post數據的時候就會報"您當前的訪問請求當中含有非法字符,已經被系統拒絕",本文介紹一種簡單的修改方法避免此錯誤。
解決方案如下:
\source\class\discuz的discuz_application.php
查找
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; }
替換為:
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; }