Sensitive data not persisted in browser storage unencrypted
Why it matters
CMMC 2.0 MP.L1-3.8.3 (NIST 800-171r2 3.8.3) covers controlled access to sensitive data. Storing authentication tokens or JWT strings in localStorage or sessionStorage makes them accessible to any JavaScript executing on the page — including injected third-party scripts and XSS payloads. Unlike HttpOnly cookies, browser storage offers no protection against script-based exfiltration. CWE-922 (Insecure Storage of Sensitive Information) and OWASP A02 (Cryptographic Failures) both apply. A token stored in localStorage that encodes user role and email exposes the user's identity and access level to any script that runs in the same origin.
Severity rationale
Medium because exploiting browser storage requires XSS or a malicious script on the same origin, but when that occurs, all stored tokens are immediately readable with no additional access barrier.
Remediation
Deliver authentication tokens as HttpOnly cookies set by the server — client code never touches the token value. For UI state that requires user info (display name, role label), fetch it from a dedicated endpoint rather than caching sensitive data in browser storage:
// DO NOT do this:
// localStorage.setItem('auth_token', response.token)
// Instead: server sets the cookie on login response
// Set-Cookie: session=<token>; HttpOnly; Secure; SameSite=Lax
// For UI-only user info:
const [user, setUser] = useState<User | null>(null)
useEffect(() => {
fetch('/api/auth/me').then(r => r.ok ? r.json() : null).then(setUser)
}, [])
Audit all localStorage.setItem and sessionStorage.setItem calls in the codebase — non-sensitive UI preferences (theme, sidebar state) are acceptable; anything that identifies the user, their role, or their access credentials is not. Cross-reference with the authentication-verify check to confirm the session cookie flags are correctly set.
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 CMMC Level 1 Readiness Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cmmc:2.0 · MP.L1-3.8.3 — Media Sanitization (derived — browser storage)
- cwe · CWE-922 — Insecure Storage of Sensitive Information
- owasp:2021 · A02 — Cryptographic Failures
- nist:rev2 · SP-800-171 3.8.3 — Sanitize or destroy system media before disposal or reuse
Taxons
History
- 2026-04-18·v1.0.0·Initial import from gov-cmmc-level-1·automated