Skip to content

Sensitive cookie with improper SameSite attribute

Description

The `sameSite` attribute is not configured to 'strict' or 'lax' in the session middleware settings, which provides protection against Cross Site Request Forgery attacks.

Examples

Insecure Code

javascript
const session = require('express-session');
const app = express();
app.use(session({ secret: 'secret' }));

Secure Code

javascript
const session = require('express-session');
const app = express();
app.use(session({ secret: 'secret', cookie: { sameSite: 'strict' } }));

Remediation

Configure the `sameSite` attribute to 'strict' or 'lax' when creating a session, for example: $SESSION({ cookie: { sameSite: 'strict' } })

Rule Details

FieldValue
IDCODE-0393
CategoryWeb
SeverityMEDIUM
CWECWE-1275
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
TagsCSRF, Session Management
OWASPA2:2017-Broken Authentication, A07:2021-Identification and Authentication Failures