Nonce Upon a Time: A Small Misconfiguration to Account Takeover
The application used a static nonce in its Content Security Policy, which allowed an existing stored XSS to execute inline scripts. The attacker used this to read a valid CSRF token from the victim's account page and submit an email change request, leading to account takeover.
medium.com
Published on medium.com
Today we are going to look into a misconfiguration in Content Security Policy (CSP), that completely bypassed the CSRF check and led to an account takeover.
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
Root cause
Likely the server generated a static nonce instead of a fresh random value for each response, weakening the CSP and enabling inline script execution.
Impact
An attacker could change the victim's email address, leading to account takeover.
What the attacker needed
Stored XSS vulnerability; victim visits the page with the XSS payload; static CSP nonce
The fix
The nonce should be generated randomly for each response to prevent reuse.
How it was found
- The attacker identifies a stored XSS vulnerability that cannot be exploited with a simple script tag due to CSP.
- The attacker notices the CSP nonce is static across responses.
- The attacker crafts an XSS payload using the static nonce to execute JavaScript in the victim's browser.
- The injected script fetches the account page to extract the CSRF token.
- The script sends a POST request to change the victim's email address using the extracted token.
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 nonce is a random value that a website includes in its security policy to allow only specific scripts to run. If the same nonce is reused, an attacker who can inject a script can also use that nonce to make the script run. Here, the attacker combined that with a cross-site request forgery (CSRF) token, which is a secret code that proves a request comes from the real user, to change the victim's email address and take over the account.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.