Vulnerabilities

What Is Cross-Site Request Forgery (CSRF)?

An attack where a malicious website tricks a user's browser into performing an unwanted action on a site where the user is authenticated. The browser automatically sends cookies with the request, so the target site processes it as a legitimate action from the user.

In Laravel Applications

Laravel includes built-in CSRF protection via the VerifyCsrfToken middleware. Every form must include the @csrf Blade directive, and AJAX requests must send the X-CSRF-TOKEN header. The protection works by generating a unique token per session and validating it on every POST, PUT, PATCH, and DELETE request.

Example

Without @csrf, an attacker could create a form on their site that submits a POST request to your Laravel app's /account/delete endpoint. If a logged-in user visits the attacker's page, their account would be deleted without their knowledge.

Related Terms

Related Articles

Monitor Your Laravel Application's Security

StackShield continuously checks your Laravel application from the outside, catching security issues before attackers find them.

Start Free Trial