Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable CSRF Token in Laravel and why we have to disable it?

Tags:

laravel

I want to see how I can disable CSRF token in Laravel and where I have to disable it. Is this good to disable it or not?

like image 916
Bhupinder Singh Avatar asked Jun 14 '16 08:06

Bhupinder Singh


People also ask

Why should we disable CSRF?

It is an attack that forces an end user to execute unwanted actions on a web application in which they are currently authenticated. CSRF attacks specifically target state-changing requests, not theft of data, since the attacker has no way to see the response to the forged request.

How do I disable CSRF protection in laravel?

Laravel Disable CSRF Token Protection To disable CSRF protection on all routes. So navigate to app\Http\Middleware and open VerifyCsrfToken. php file. Then update the routes, which you want to disable CSRF protection.

Why CSRF token is used in laravel?

Laravel automatically generates a CSRF "token" for each active user session managed by the application. This token is used to verify that the authenticated user is the person actually making the requests to the application.

What is CSRF token and why it is required?

A CSRF token is a secure random token (e.g., synchronizer token or challenge token) that is used to prevent CSRF attacks. The token needs to be unique per user session and should be of large random value to make it difficult to guess. A CSRF secure application assigns a unique CSRF token for every user session.


1 Answers

You can Disable CSRF on few routes by editing.

App\Http\Middleware\VerifyCsrfToken  

and add your own routes name in protected

$except = [] array. 

It does not seems to be good practice as by doing this we are removing security feature of Laravel.

like image 68
Gaurav Avatar answered Sep 30 '22 01:09

Gaurav