Skip to content
XSS Write-up Beginner

Stored XSS via Unsanitized SVG File Upload

The application allowed authenticated users to upload SVG files without sanitising their content, so an attacker could embed JavaScript that runs in other users' browsers. The author then used a remote script loader to steal cookies, which could lead to account takeover.

medium.com

Published on medium.com

In the last write-up, I mentioned that I had shifted my focus to hunt for external programs for this period, and I have started on a program, let’s call it “pharaoh.com”.

youssef awad, on medium.com

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

The upload feature accepted SVG files and served them without sanitising embedded scripts or event handlers.

Impact

Attackers could execute arbitrary JavaScript in users' browsers, leading to session theft, impersonation, phishing, or UI manipulation; the author demonstrated cookie theft, which is a major step toward account takeover.

What the attacker needed

Authenticated user account; ability to upload a store logo

The fix

Uploaded SVG files should be sanitised to remove scripts and event attributes, uploads should be restricted to safe image types where possible, and files should be served from a separate domain with a strict Content Security Policy.

How it was found

  1. Open the Products tab and find the store logo upload feature.
  2. Upload a test file to check how the server handles uploads.
  3. Change the file extension to SVG and the content type to text/javascript, and include a script in the SVG.
  4. The server responds with 201 Created, confirming the upload.
  5. Upload an SVG that loads a remote script to steal cookies.

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.

An SVG is an image format that can also contain code, including JavaScript. If a site lets you upload an SVG and then shows it to other people without cleaning it, that code runs in their browsers. This is called stored cross-site scripting (XSS), and it lets an attacker act as the victim, for example by stealing their session cookie.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.