fuel cms简单模块CSRF更新问题
fuel cms simple module CSRF update issue
当我在 Fuel 1.4 中启用 CSRF 保护时,我遇到了一个 csrf 令牌重置问题。
以免详细说明问题 :
我的 config.php 在应用程序配置中
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 's_csrf_tocken';
$config['csrf_cookie_name'] = 's_csrf_cookie';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
在具有以下字段的简单模块中
姓名,profile_image ....
所以每当我要创建或编辑然后在个人资料图片部分上传文件然后 return 从模块页面返回主页面。
并尝试保存它给出的错误:
An Error Was Encountered
The action you have requested is not allowed.
因为 csrf 令牌在资产上传器的 iframe 中发生了变化,而在 main 中来自 csrf 的令牌没有得到更新。
这个问题有什么解决办法吗?
我已经实施了一个解决方案,我不能说它非常合适。它仍有改进的余地。
我用一个控制器来获取 csrf
class Csrf_secure extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->library('user_agent');
}
function get_csrf()
{
$this->fuel->admin->check_login();
if(false)
{}
elseif(trim($this->agent->referrer()) =='' or $this->input->is_ajax_request()== false)
{show_404(); }
else {
echo json_encode(array(
'token'=>$this->security->get_csrf_token_name(),
'hash'=>$this->security->get_csrf_hash()
));
} }}
当模式 i 框架关闭时获取和更新函数
from(如果只有在 from 上发生更新时才能被删除,则需要优化)
/fuel/modules/fuel/assets/js/jquery/plugins/jqModal.js
改变
$.fn.jqmHide
功能如下.
$.fn.jqmHide=function(t){return this.each(function(){
$.jqm.close(this._jqm,t);
if(typeof window.parent != "undefined" ){
if(typeof window.parent.CallParent == "undefined" ){
window.parent.CallParent = function(context)
{
$.getJSON(jqx_config.basePath+"csrf_secure/get_csrf", function(result){
if(typeof result.token != "undefined"){
document.querySelectorAll('#'+result.token).forEach(function(rf){
rf.value=result.hash;
});
}
});
};
};
window.parent.CallParent(this._jqm,t);
}
});};
当我在 Fuel 1.4 中启用 CSRF 保护时,我遇到了一个 csrf 令牌重置问题。
以免详细说明问题 :
我的 config.php 在应用程序配置中
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 's_csrf_tocken';
$config['csrf_cookie_name'] = 's_csrf_cookie';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
在具有以下字段的简单模块中
姓名,profile_image ....
所以每当我要创建或编辑然后在个人资料图片部分上传文件然后 return 从模块页面返回主页面。
并尝试保存它给出的错误:
An Error Was Encountered
The action you have requested is not allowed.
因为 csrf 令牌在资产上传器的 iframe 中发生了变化,而在 main 中来自 csrf 的令牌没有得到更新。
这个问题有什么解决办法吗?
我已经实施了一个解决方案,我不能说它非常合适。它仍有改进的余地。 我用一个控制器来获取 csrf
class Csrf_secure extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->library('user_agent');
}
function get_csrf()
{
$this->fuel->admin->check_login();
if(false)
{}
elseif(trim($this->agent->referrer()) =='' or $this->input->is_ajax_request()== false)
{show_404(); }
else {
echo json_encode(array(
'token'=>$this->security->get_csrf_token_name(),
'hash'=>$this->security->get_csrf_hash()
));
} }}
当模式 i 框架关闭时获取和更新函数
from(如果只有在 from 上发生更新时才能被删除,则需要优化)
/fuel/modules/fuel/assets/js/jquery/plugins/jqModal.js
改变
$.fn.jqmHide
功能如下.
$.fn.jqmHide=function(t){return this.each(function(){
$.jqm.close(this._jqm,t);
if(typeof window.parent != "undefined" ){
if(typeof window.parent.CallParent == "undefined" ){
window.parent.CallParent = function(context)
{
$.getJSON(jqx_config.basePath+"csrf_secure/get_csrf", function(result){
if(typeof result.token != "undefined"){
document.querySelectorAll('#'+result.token).forEach(function(rf){
rf.value=result.hash;
});
}
});
};
};
window.parent.CallParent(this._jqm,t);
}
});};