php – Codeigniter CSRF保护VS标签
发布时间:2020-12-13 16:56:45 所属栏目:PHP教程 来源:网络整理
导读:在新的CodeIgniter v3中,CSRF令牌仅有效一次.因此,我在处理多个标签时遇到了一些问题: 使用Form1打开一个选项卡 使用Form2打开一个选项卡 使用表单1提交选项卡 使用表格2提交标签 步骤4将导致CSRF错误.显然这不太理想……怎么解决这个问题呢? 解决方法 背
在新的CodeIgniter v3中,CSRF令牌仅有效一次.因此,我在处理多个标签时遇到了一些问题:
>使用Form1打开一个选项卡 步骤4将导致CSRF错误.显然这不太理想……怎么解决这个问题呢? 解决方法
背景
每次表单提交时都无需重新生成CSRF令牌.安全性很小 – 如果攻击者可以从您的页面中检索令牌,那么他们已经赢了.这将使您的站点无错误地运行交叉表. 有关安全方面的一些背景信息,请参阅此页面:Why [you shouldn’t] refresh CSRF token per form request?. CodeIgniter v3 v3使用名为 CodeIgniter v2 CodeIgniter使用的代码在本文中讨论:CSRF Protection in CodeIgniter 2.0: A closer look.相关代码如下: function csrf_verify() { // If no POST data exists we will set the CSRF cookie if (count($_POST) == 0) { return $this>csrf_set_cookie(); } // Do the tokens exist in both the _POST and _COOKIE arrays? if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_cookie_name]) ) { $this->csrf_show_error(); } // Do the tokens match? if ( $_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_cookie_name] ) { $this->csrf_show_error(); } // We kill this since we're done and we don't // want to polute the _POST array unset($_POST[$this->csrf_token_name]); // Re-generate CSRF Token and Cookie unset($_COOKIE[$this->csrf_cookie_name]); $this->_csrf_set_hash(); $this->csrf_set_cookie(); log_message('debug',"CSRF token verified "); } 只需从函数中删除以下代码: // Re-generate CSRF Token and Cookie unset($_COOKIE[$this->csrf_cookie_name]); $this->_csrf_set_hash(); $this->csrf_set_cookie(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |