我正在使用codeigniter-paypal-ipn,并且启用了csrf_protection。这似乎阻止了从Paypal到我的IPN控制器的访问。如果我禁用csrf_protection,它工作得很好,在启用csrf_protection的情况下,paypal IPN服务抛出500内部服务器错误。
有没有办法在不禁用csrf_protection的情况下解决这个问题?如果没有,我是否可以仅禁用该控制器的csrf_protection?
谢谢。
发布于 2011-10-03 04:06:29
亚历克斯,codeigniter-paypal-ipn的创建者。目前,我还不知道有什么方法可以让IPN post与csrf_protection一起工作。如果你看看另一种语言/框架是如何做到这一点的,例如django-paypal IPN -他们添加了一个CSRF exemption to the specific IPN controller。
正如imm所说,在合并带有this pull request的版本之前,这种类型的细粒度控制不会在CodeIgniter中可用(如果您不能等待,请尝试下面caseyamcl的方法,因为它不涉及攻击CI核心...)
我已经更新了我的项目的README,以使CSRF的情况更清晰。
发布于 2011-10-10 02:17:18
我知道这个问题已经得到了回答,但我是以类似的方式完成的,而不是破解CI核心。我在应用程序/config/config.php文件中添加了以下内容:
$config['csrf_ignore'] = array('api');该数组可以包含您喜欢的任何路径。上面的示例将适用于任何以“api”开头的路径。
然后,我添加了以下文件:application/core/MY_Input.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Input extends CI_Input
{
function _sanitize_globals()
{
$ignore_csrf = config_item('csrf_ignore');
if (is_array($ignore_csrf) && count($ignore_csrf))
{
global $URI;
$haystack = $URI->uri_string();
foreach($ignore_csrf as $needle)
{
if (strlen($haystack) >= strlen($needle) && substr($haystack, 0, strlen($needle)) == $needle)
{
$this->_enable_csrf = FALSE;
break;
}
}
}
parent::_sanitize_globals();
}
}
/* EOF: MY_Input */发布于 2011-10-03 03:40:46
有人在http://ellislab.com/forums/viewthread/200625/上问了类似的问题,在下一个版本中将提供禁用单个控制器的csrf。
https://stackoverflow.com/questions/7628353
复制相似问题