Session tokens in secure HTTP-only cookies, SameSite=Strict
Why it matters
Session tokens stored in localStorage or accessible JavaScript variables are exfiltrable by any XSS payload on any page of the application. A single reflected or stored XSS vulnerability anywhere on the domain becomes a full session hijack with no additional effort. CWE-614 (Sensitive Cookie Without 'Secure' Attribute) and CWE-1004 (Sensitive Cookie Without 'HttpOnly' Flag) define these as distinct failures. OWASP A07 and PCI-DSS Req 6.4.1 mandate that session tokens be inaccessible to client-side scripts. In a financial application, exfiltrating a session token from localStorage via document.cookie or XSS requires zero CSRF bypass — the token is already JavaScript-readable and portable.
Severity rationale
High because a session token in localStorage or a cookie missing HttpOnly is a single XSS vulnerability away from full account compromise — the attacker does not need to break HTTPS or defeat SameSite protections to extract and replay it.
Remediation
Configure session cookies with all three required attributes in src/lib/session.ts or the session middleware initialization:
session({
cookie: {
httpOnly: true, // inaccessible to document.cookie and XSS
secure: true, // HTTPS transport only
sameSite: 'Strict', // no cross-origin send (CSRF protection)
maxAge: 15 * 60 * 1000
}
})
Audit all calls to localStorage.setItem and sessionStorage.setItem in the codebase — no session token, auth token, or user identity value should appear as a storage key. Tokens are set exclusively by the server via Set-Cookie response headers; the client-side JavaScript never handles them.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Session Security Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-614 — Sensitive Cookie in HTTPS Session Without 'Secure' Attribute
- cwe · CWE-1004 — Sensitive Cookie Without 'HttpOnly' Flag
- owasp:2021 · A07
- pci-dss:4.0 · Req 6.4.1 — Session management controls for public-facing web applications
Taxons
History
- 2026-04-18·v1.0.0·Initial import from finserv-session-security·automated