Welcome Guest, Not a member yet? Register   Sign In
Add CSRF error 'the action you have requested is not allowed'
#1

(This post was last modified: 11-22-2020, 02:50 PM by rilekt12.)

I added csrf field to my form like that:
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" />
And I send request using POST method.
When I submit my form, I've got error 'the action you have requested is not allowed'. How to repair it?
My App.php:
[...]
    public $sessionDriver            = 'CodeIgniter\Session\Handlers\FileHandler';
    public $sessionCookieName        = 'my_session';
    public $sessionExpiration        = 7200;
    public $sessionSavePath          = WRITEPATH . 'session';
    public $sessionMatchIP           = false;
    public $sessionTimeToUpdate      = 300;
    public $sessionRegenerateDestroy = false;


    public $cookiePrefix   = '';
    public $cookieDomain   = 'http://localhost:8080';
    public $cookiePath     = '/';
    public $cookieSecure   = false;
    public $cookieHTTPOnly = false;


    public $CSRFTokenName  = 'csrf';
    public $CSRFHeaderName = 'X-CSRF-TOKEN';
    public $CSRFCookieName = 'csrf';
    public $CSRFExpire     = 700;
    public $CSRFRegenerate = false;
    public $CSRFRedirect   = true;

[..]

Thanks for any help  Sad
Reply
#2

(This post was last modified: 11-25-2020, 12:10 PM by captain-sensible.)

did you enable in Filters.php ?

public $globals = [
'before' => [
//'honeypot'
'csrf'
]
];


I can confirm your approach must be Ok since i'm using exacly the same approach in my forms eg

Code:
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" />
Reply




Theme © iAndrew 2016 - Forum software by © MyBB