Skip to content
XSS Write-up Intermediate

How I bypass CSP sandbox and find Stored XSS

An SVG file upload filter could be bypassed by using upper-case tag names and leading whitespace, allowing a stored SVG containing a script and a javascript link. The site's CSP sandbox was then avoided by supplying a Content-Type of image/png,image/svg+xml, which the server did not treat as needing the CSP header, so the script executed on the victim domain.

l4zyhacker Follow

Published on l4zyhacker.medium.com

Free: https://l4zyhacker.medium.com/how-i-bypass-csp-sandbox-and-find-stored-xss-322ad1f82d82

L4zyhacker, on l4zyhacker.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

Likely the server decided whether to attach the CSP header based on the request's Content-Type, and a combined value like image/png,image/svg+xml was not recognised as needing the header, while the browser still rendered the SVG.

Impact

An attacker could store a script that runs in a victim's browser on the site's domain, though the report notes the submission was closed as a duplicate.

What the attacker needed

Ability to upload an SVG file; victim views the uploaded file

How it was found

  1. Upload an SVG file whose tags use mixed case and which begins with whitespace to get past the upload filter.
  2. Observe that the response for a safe Content-Type such as image/png carries no CSP header.
  3. Send the upload with a Content-Type of image/png,image/svg+xml and confirm the CSP header is absent.
  4. Load the uploaded file and see the script execute on the victim domain.

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 picture files, and it tried to block dangerous ones with a filter and a security header called CSP that stops scripts from running. The author found that slightly changing the file's declared type made the server skip that header, so a script hidden in the uploaded picture ran in a visitor's browser. This kind of stored script attack is called stored cross-site scripting (XSS).

What is XSS?

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

More by l4zyhacker

View all

1 more disclosed report, best first.

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.