Token Leakage in JSON Response Breaking httpOnly Protection
The login endpoint returned the access and refresh tokens in the JSON response body even though they were also set as httpOnly cookies. An attacker who can run JavaScript in the victim's browser, for example through an XSS flaw, could read those tokens and use them to hijack the session.
medium.com
Published on medium.com
While analyzing a Node.js authentication flow, I came across an interesting issue in the login endpoint.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
If an attacker can exploit even a simple XSS vulnerability, they could extract the tokens and potentially hijack the session or take over the account.
What the attacker needed
A valid account; an XSS or script injection on the site
The fix
The tokens should be removed from the JSON response so they are only delivered through httpOnly cookies; the text shows this change and states the tokens are then no longer accessible from client-side JavaScript.
How it was found
- Submit email and password to the login endpoint.
- Observe that the response sets httpOnly cookies for the tokens.
- Observe that the same tokens also appear in the JSON response body.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A cookie marked httpOnly cannot be read by JavaScript running on the page, which helps stop stolen sessions if a script injection bug exists. Here the server also put the same login tokens into the normal response data, which JavaScript can read. So the httpOnly protection was undone by a simple mistake in what the server sent back.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.