Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF Token mismatch #7

Open
Linkto91 opened this issue Jul 21, 2020 · 1 comment
Open

CSRF Token mismatch #7

Linkto91 opened this issue Jul 21, 2020 · 1 comment

Comments

@Linkto91
Copy link

Hi,

Firstly, thanks for your work !

I installed your plugin, I am working with CakePHP 3.7.

The problem is that I can't acceed to my page to add an user for example.
The error message is :

CSRF token mismatch. Cake\Http\Exception\InvalidCsrfTokenException
Documentation API

If you want to customize this error message, create src/Template/Error/error400.ctp
toggle vendor stack frames

    ⟩ Cake\Http\Middleware\CsrfProtectionMiddleware->_validateToken CORE/src/Http/Middleware/CsrfProtectionMiddleware.php, line 120

I understand that the problem is about the CSRF, I tried to resolved with a lot of solution but nothing to do, I don't understand why.

I tried to change the route, to remove :
// $routes->applyMiddleware('csrf');

All solutions to disable the CSRF on this page what I found on internet (Google) don't work.

When I access to the page for the view without send POST, the page works.

Thank you by advance.

@Linkto91
Copy link
Author

I found the problem, the routes page was in the cache and doesn't actualize.

I removed it from the cache and I modified it like this :

if (substr($_SERVER['REQUEST_URI'], 0, 5) != '/api/') {
        $routes->applyMiddleware('csrf');
    }

Without this line :
// $routes->connect('/api/add', ['controller' => 'Api', 'action' => 'add', 'isRest' => true]);

The API already working, it's not forced to have it ?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant