CodeIgniter use CSRF protection only in some pages

esrpim picture esrpim · Aug 22, 2013 · Viewed 14.1k times · Source

What I want to do is to protect some sensitive forms from CSRF attack in codeigniter but not all pages.

To protect from CSRF if I set it in config.php it applies for all pages. is there any way to do that only for some pages by setting in controller?

$config['csrf_protection'] = TRUE;

Answer

Bira picture Bira · Feb 13, 2015

Now the CI3 have this feature, we can exclude the URIs in the config http://www.codeigniter.com/userguide3/libraries/security.html?highlight=csrf#cross-site-request-forgery-csrf

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


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