2

当我在 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 ....

因此,当我要创建或编辑时,然后在个人资料图像部分上传文件,然后从模块页面返回主页面。

并尝试从中保存它会给出错误:

遇到错误

您请求的操作是不允许的。

由于 csrf 令牌在资产上传器的 iframe 中发生了更改,并且主要从 csrf 没有得到更新。

这个问题的任何解决方案?

4

1 回答 1

0

我已经实施了一个我不能拒绝它的解决方案。它仍有改进的余地。我使用控制器来获取 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 上发生更新时才可以将其单元格化,则需要对其进行优化)

/fuel/modules/fuel/assets/js/jquery/plugins/jqModal.js

改变

$.fn.jqm隐藏

功能如下。

$.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); 

        }

    });};
于 2019-10-09T11:15:07.007 回答