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.
Disabling or bypassing CSRF protection allows an authenticated user’s browser to execute state-changing requests the user did not intend.
Express.js CSURF middleware protection is not found on an unsafe HTTP method like POST method:
let csrf = require('csurf');
let express = require('express');
let csrfProtection = csrf({ cookie: true });
let app = express();
// Noncompliant: this route is not protected by CSURF middleware (csrfProtection is not used)
app.post('/money_transfer', parseForm, function (req, res) {
res.send('Money transferred');
});
Protection provided by Express.js CSURF middleware is globally disabled on unsafe methods:
let csrf = require('csurf');
let express = require('express');
app.use(csrf({ cookie: true, ignoreMethods: ["POST", "GET"] })); // Noncompliant: POST is an unsafe method
Express.js CSURF middleware protection is used on unsafe methods:
let csrf = require('csurf');
let express = require('express');
let csrfProtection = csrf({ cookie: true });
let app = express();
app.post('/money_transfer', parseForm, csrfProtection, function (req, res) {
res.send('Money transferred')
});
Protection provided by Express.js CSURF middleware is enabled on unsafe methods:
let csrf = require('csurf');
let express = require('express');
app.use(csrf({ cookie: true, ignoreMethods: ["GET"] }));