简体   繁体   English

如何仅在 PHP CodeIgniter 中的特定 url/页面上使用 CSRF

[英]How to use CSRF only on a specifc url/page in PHP CodeIgniter

Hi I am trying to use CodeIngiter's CSRF mechanism.嗨,我正在尝试使用 CodeIngiter 的 CSRF 机制。 But the thing is that I do not want to use it for every url/page.但问题是我不想为每个 url/页面使用它。 I only want to use it for a specific url/page.我只想将它用于特定的 url/页面。

I have the following code.我有以下代码。 I want the CSRF check only on site_url('login') and site_url('signup')我只希望对site_url('login')site_url('signup')进行 CSRF 检查

But the CSRF happens on every page.但是 CSRF 发生在每一页上。 How can I make the CSRF to ignore other URLs and only focus on the 2 I've specified above ?如何让 CSRF 忽略其他 URL 而只关注我上面指定的 2 个?

$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_checker';
$config['csrf_cookie_name'] = 'csrf_checker';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array('home', 'about', 'licenses');

Selected URIs can be whitelisted from csrf protection (for example API endpoints expecting externally POSTed content).选定的 URI 可以从 csrf 保护中列入白名单(例如,需要外部发布内容的 API 端点)。 You can add these URIs by editing the 'csrf_exclude_uris' config parameter:您可以通过编辑“csrf_exclude_uris”配置参数来添加这些 URI:

$config['csrf_exclude_uris'] = array('api/person/add');

Regular expressions are also supported (case-insensitive):还支持正则表达式(不区分大小写):

$config['csrf_exclude_uris'] = array(
        'api/record/[0-9]+',
        'api/title/[a-z]+'
);

ref : https://www.codeigniter.com/user_guide/libraries/security.html?highlight=csrf#cross-site-request-forgery-csrf参考: https : //www.codeigniter.com/user_guide/libraries/security.html? highlight = csrf#cross-site-request-forgery- csrf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM