T09 · Insecure Skill Coding Practices
- Location
references/examples.md:259- Finding
Sensitive Authentication State Persisted in Browser Local Storage
- Content
View full analysis
Vulnerability Details
File Location:
references/examples.md, lines 259–260 and 292–298
Vulnerability Type: Client-side storage of potentially sensitive authentication data
Risk Level: MediumVulnerable Code
typescript // Persist to localStorage localStorage.setItem('user', JSON.stringify(user))typescript persist: { enabled: true, strategies: [ { key: 'user', storage: localStorage, paths: ['currentUser'] } ] }Technical Analysis
The example stores the complete user object returned by the login API in
localStorage. It also configures Pinia to persistcurrentUserto the same script-readable storage. This creates redundant persistence and does not restrict the stored object to an explicit set of non-sensitive fields.Data in
localStorageis accessible to all JavaScript executing under the same origin. If the login response includes session tokens, authorization attributes, personal information, or other sensitive values, a cross-site scripting vulnerability or compromised same-origin dependency could retrieve them. Unlike anHttpOnlycookie,localStorageprovides no mechanism that prevents JavaScript from reading stored session material.Attack Path
- An application developer adopts the documented Pinia login pattern.
- The application receives a user object from
api.login(credentials). - The full response is serialized into
localStorage; Pinia persistence also storescurrentUser. - An attacker obtains same-origin JavaScript execution through an XSS vulnerability or compromised frontend dependency.
- The malicious script reads the persisted
userdata fromlocalStorage. - If the object contains session credentials, tokens, or sensitive profile data, the attacker exfiltrates and abuses that information.
Exploitation depends on same-origin script execution and on sensitive information being present ...[truncated 544 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not persist the complete login response or authentication tokens in
localStorage. - Store session identifiers in server-managed cookies configured with
HttpOnly,Secure, and an appropriateSameSitepolicy. - Keep only the minimum non-sensitive UI state in browser storage.
- Define an explicit allowlist of persistable fields rather than serializing the full
Userobject. - Remove the duplicate explicit
localStorage.setItemoperation if a persistence plugin remains necessary. - Ensure logout invalidates the server-side session in addition to clearing client state.
- Apply a restrictive Content Security Policy, contextual output encoding, dependency controls, and other XSS defenses to reduce exposure to same-origin malicious scripts.
- Review existing stored records and rotate session material if tokens were previously persisted.
- Do not persist the complete login response or authentication tokens in
