我正在尝试在网站背面设置CMS,但每当发布数据<a href=...时,帖子数据都会被废弃.
我有$config['global_xss_filtering'] = TRUE;配置
我的问题是有一种方法可以禁用一个项目的xss过滤吗?
例如
$this->input->post('content', true); - 打开它,但如何关闭它?
感谢大家.
PVS
tre*_*ace 27
如果要更改方法的默认行为post(),可以扩展核心输入库,或者如果你是懒惰的,只需将输入库的第278行(或左右)更改为:
/**
* Fetch an item from the POST array
*
* @access public
* @param string
* @param bool
* @return string
*/
function post($index = '', $xss_clean = TRUE)
{
return $this->_fetch_from_array($_POST, $index, $xss_clean);
}
Run Code Online (Sandbox Code Playgroud)
这里唯一的区别是我已经将$ xss_clean变量改为TRUE而不是FALSE.现在您可以关闭全局XSS过滤,它将自动过滤输入,除非您在调用Input库的post()方法时指定false作为第二个参数.只有一种方法是get()方法,您可以以相同的方式更改它.
但是,如果我是你,我只是扩展原生库,因为你更新CodeIgniter时很可能会忘记这个,然后你会突然想知道为什么你会受到XSS攻击.这看起来像这样:
class MY_Input extends CI_Input {
function My_Input()
{
parent::CI_Input();
}
function post($index = '', $xss_clean = TRUE)
{
return parent::post($index, $xss_clean);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在此处了解有关扩展库的更多信息
http://codeigniter.com/user_guide/general/creating_libraries.html
如果您希望xss_clean仅在某些情况下保持全局启用和覆盖,则可以扩展输入库以保留克隆状态,$_POST以便在询问时提供原始数据:
<?php if (!defined('BASEPATH')) exit('No direct access allowed.');
class MY_Input extends CI_Input {
public function __construct() {
$this->_POST_RAW = $_POST; //clone raw post data
parent::__construct();
}
public function post($index = null, $xss_clean = TRUE) {
if(!$xss_clean){ //if asked for raw post data -eg. post('key', false)-, return raw data. Use with caution.
return $this->_POST_RAW[$index];
}
return parent::post($index, $xss_clean);
}
}
?>
Run Code Online (Sandbox Code Playgroud)
这样,$this->input->post('mydata', FALSE)即使xss_clean全局启用,您也可以使用它来检索未经过清理的原始发布数据.
| 归档时间: |
|
| 查看次数: |
15913 次 |
| 最近记录: |