Escalating impact: Full Account Takeover via Stored XSS
A Next.js image optimisation route served user-uploaded SVG files, so an SVG containing a script executed as stored XSS when rendered. Because the app kept JWT tokens in local storage, the script could read them and send them to an attacker, allowing full account takeover.
Published on rajukani100.medium.com
I was hunting on a EdTech platform. While digging, i get to know that web app is made using nextJs.
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 image optimisation endpoint served uploaded SVG files with a content type that made the browser execute embedded scripts, instead of forcing a safe image type or blocking SVG.
Impact
If a victim opened the crafted link, their JWT token could be sent to the attacker, allowing the attacker to take over the victim's account; the HttpOnly cookie setting did not help because the token was in local storage.
What the attacker needed
A user account; profile image upload feature; victim opens the crafted link
The fix
Sensitive tokens should not be stored in local storage, and uploaded SVG files should not be served in a way that lets embedded scripts run.
How it was found
- Upload an SVG file containing a script as the profile picture
- Take the URL returned for the uploaded file
- Load that URL through the Next.js image route
- The script runs and reads the user store from local storage
- The script sends the stolen data to an attacker-controlled server
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 website let people upload a profile picture, and it accepted a picture format called SVG that can contain code. When someone viewed that picture through the site's image link, the code ran in their browser. The site also kept the user's login token in a place that page code can read, so the code could copy it and send it to the attacker, who could then 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.