Cross-site request forgery (CSRF) forces an authenticated user to perform unintended state-changing actions in a web application. This rule detects when CSRF protection is explicitly disabled or missing from an application.
When CSRF protection is disabled or bypassed, an attacker can trick a logged-in user into submitting requests the application treats as authenticated. The rule flags configurations that disable framework CSRF middleware, exempt specific routes or views, or leave unsafe HTTP methods unprotected.
An attacker can change passwords, transfer funds, modify data, or perform other privileged operations using the victim’s session.
Successful CSRF attacks can lead to full account takeover when combined with sensitive actions such as email or credential changes.
Do not add routes to the $except list on VerifyCsrfToken unless CSRF protection is replaced by an equivalent control.
Disabling or bypassing CSRF protection allows an authenticated user’s browser to execute state-changing requests the user did not intend.
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
protected $except = [
'api/*'
]; // Noncompliant: disable CSRF protection for a list of routes
}
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
protected $except = [];
}
Remember to add @csrf blade directive to the relevant forms when removing an element from $except. Otherwise the form submission will stop working.
Keep CSRF protection enabled on Symfony forms (it is enabled by default).
Disabling or bypassing CSRF protection allows an authenticated user’s browser to execute state-changing requests the user did not intend.
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class Controller extends AbstractController {
public function action() {
$this->createForm('', null, [
'csrf_protection' => false, // Noncompliant: disable CSRF protection for a single form
]);
}
}
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class Controller extends AbstractController {
public function action() {
$this->createForm('', null, []);
}
}