️ Exploiting Stored XSS to Bypass CSRF Protection and Gain Admi
A web application stored user-supplied HTML without filtering, allowing persistent JavaScript execution. The attacker used this stored cross-site scripting to read a CSRF token from the page and submit a forged request that created a new administrator account.
In this article, I’m going to share a real-world exploitation chain — a scenario where I leveraged a simple Stored XSS vulnerability to bypass CSRF protection and ultimately created a new admin user without any authentication!
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 stored and rendered user-supplied HTML without validation or output encoding, and the CSRF token was readable from the page by same-origin scripts.
Impact
An attacker could create a new administrator account without authentication or user interaction, leading to full application compromise.
What the attacker needed
Ability to create posts; victim views the post
How it was found
- Create a post containing HTML that includes an image with an error handler and a script tag.
- Revisit the dashboard and observe the alert firing, confirming the payload is stored and executed.
- Use JavaScript to extract the CSRF token from the page's HTML using a regular expression.
- Send a POST request to the admin-creation endpoint with the extracted token and new admin credentials.
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.
Stored cross-site scripting (XSS) happens when a website saves text that includes code and later shows it to other people without cleaning it, so the code runs in their browsers. Here the saved code could read a secret anti-forgery token that the site uses to stop fake form submissions, then send a request that looked legitimate and created an admin account.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.