Frontend (FRE6)
Olga exploits malicious JavaScript to steal authentication tokens and hijack user sessions, gaining access to accounts without credentials
This card covers active session hijacking through JavaScript-based token theft during a live session. See FRE3 for residual tokens left accessible after logout, and FRE9 for forging or predicting tokens without needing to steal them from a live session.
Scenario: Olga's Token Theft and Session Hijacking
Olga uses malicious JavaScript running in the victim's browser to steal authentication tokens and then uses them to take over the user's session, gaining full access to the account without knowing the user's password. This occurs because:
- Tokens accessible to JavaScript: Authentication tokens ā session cookies without the
HttpOnlyflag, JWTs stored inlocalStorage, or access tokens held in JavaScript variables ā can be read by any script executing in the page's origin. - Execution vector available: Olga can run JavaScript in the victim's browser through a cross-site scripting vulnerability, a compromised third-party script, or a malicious browser extension.
Example
A project management application stores its JWT access token in localStorage after login. Olga discovers a stored XSS vulnerability in the comments section of a shared project. She posts a comment containing a script that reads localStorage.getItem('token') and sends the value to a server she controls. When a project administrator views the comments page, the script executes silently in their browser, exfiltrating their JWT. Olga imports the token into her own browser using a developer console and makes authenticated API calls as the administrator ā resetting passwords, exporting data, and inviting her own accounts as collaborators.
Threat Modeling
STRIDE
The scenario maps directly to STRIDE: Spoofing.
Olga presents a stolen token to the backend and is indistinguishable from the legitimate user. She does not break the authentication mechanism itself ā she steals a valid credential and reuses it from a different context.
What can go wrong?
Session hijacking gives an attacker complete control over the victim's account for as long as the token remains valid. All actions taken through the hijacked session are attributed to the victim in audit logs, complicating incident response. Depending on the application, this can lead to data exfiltration, financial fraud, account takeover, or lateral movement to other systems the victim has access to.
For more things that can go wrong, see the OWASP Top 10, OWASP Top 10 Client-Side Security Risks, and CAPECs IDs in the mapping section below and correlate these with the IDs on the OWASP Top 10, OWASP Top 10 Client-Side Security Risks, and CAPECs documentation.
What are we going to do about it?
Protect authentication tokens from JavaScript access and limit the window of opportunity for stolen tokens to be reused.
- Set the
HttpOnlyflag on session cookies so that JavaScript cannot read them; use cookies for authentication tokens rather thanlocalStoragewherever possible. - Set the
Secureflag on authentication cookies so they are only transmitted over HTTPS, and apply theSameSite=StrictorSameSite=Laxattribute to reduce cross-site request risks. - Keep token lifetimes short and implement refresh token rotation, so a stolen access token expires quickly.
- Eliminate XSS vulnerabilities that would give an attacker a JavaScript execution vector ā address the root cause, not only the token storage mechanism.
For detailed advice on how to mitigate threats related to the card, see the OWASP ASVS IDs in the table below and correlate these with the IDs in the OWASP Application Security Verification Standard documentation.
Mappings
STRIDE: Spoofing
OWASP TOP-10 CLIENT SIDE: 7
OWASP TOP-10: A07:2025
ASVS: 8.2
CAPEC: CAPEC-180
CWE: CWE-284
MITRE ATTACK: T1552.001
Attacks
No attacks registered!