Stored XSS to Account Takeover (AWS Cognito)
A stored cross-site scripting vulnerability existed in error and notification messages that rendered user-controlled item titles as HTML. An attacker could inject a script that reads authentication tokens from local storage and sends them to an attacker-controlled server, leading to account takeover.
Hello again! Today, I want to discuss a recent finding from my penetration test.
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 application rendered user-controlled item titles as HTML in error and notification messages without proper sanitisation, and stored authentication tokens in browser local storage where JavaScript could access them.
Impact
An attacker could steal a victim's authentication tokens and take over their account, though the exploit required bypassing a WAF and the victim to click a crafted link.
What the attacker needed
Ability to set an item title; victim clicks a crafted link; WAF bypass required
The fix
The application should sanitise or escape user-controlled titles before rendering them in error and notification messages, and avoid storing authentication tokens in local storage.
How it was found
- Set an item title to a malicious HTML payload.
- Trigger an action such as deleting the item to cause an error or notification message.
- The message renders the title as HTML, executing the injected script.
- The script reads local storage and sends the data to an attacker server via an image request.
- The attacker uses the stolen idToken to obtain an X-Amz-Security-Token and authenticate as the victim.
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.
When a website shows user-supplied text as HTML instead of plain text, an attacker can insert a script that runs in the victim's browser. This is called cross-site scripting (XSS). Here, the script stole login tokens stored in the browser, letting the attacker log in as the victim.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.