CSRF protection in Laravel

By | April 2, 2017

CSRF-TOKEN
CSRF is an attack using unauthorized command done on behalf of an authorized user.
Including csrf token in a form its in a hidden format,so that middleware can validate the request.
Laravel automatically generates the csrf token for each active session.This token is used to verify each
authenticated user is making the request

Method for generting csrf token

we can use the below code also to generate csrf token

Middleware folder contains file called verifycsrftoken.php. Functions inside this file will verify the token in the input request with value in session.

For a particualr reason if you want to avoid csrf protection you can exclude using the verifycsrftoken.php file

X-CSRF-TOKEN
In addition to check the csrf token in the post parameter.verifycsrftoken will verify the
token in the request header

if we store the the token in meta tag, like..

this verification from request header not from the form post method.In the case of ajax application
jquery will instruct the function to add csrftoken.

X-XSRF-TOKEN
x-xsrf-token is generated and save as a cookie in each response generated by the laravel.this value we can use in the request header.

So in csrf token stored in request header and hidden field in the form.