Codeigniter:Paypal IPN 和 csrf_protection

2024-01-12

我正在与Codeigniter-paypal-ipn https://github.com/orderly/codeigniter-paypal-ipn并启用 csrf_protection。 这似乎阻止了从 Paypal 到我的 IPN 控制器的访问。如果我禁用 csrf_protection 它工作得很好,启用 csrf_protection 后,paypal IPN 服务会抛出 500 内部服务器错误。

有没有办法在不禁用 csrf_protection 的情况下解决这个问题? 如果没有,我可以禁用该控制器的 csrf_protection 吗?

Thanks.


我知道问题已经得到解答,但我以类似的方式做到了这一点,而没有破解 CI 核心。我将以下内容添加到我的 application/config/config.php 文件中:

$config['csrf_ignore'] = array('api');

该数组可以包含您喜欢的任何路径。上面的示例将适用于以“api”开头的任何路径。

然后,我添加了以下文件:应用程序/核心/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 */
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Codeigniter:Paypal IPN 和 csrf_protection 的相关文章

随机推荐