Skip to content
XSS Write-up Beginner

XSS vulnerability caused by modifying the Content-Type

A file upload feature accepted an uploaded file whose Content-Type was changed from an image type to text/html, and the uploaded file was then served back in a way that let it render as HTML. An attacker could upload a file containing script and have it execute in a victim's browser when the returned path is visited.

xiaodongsec Follow

Published on medium.com

today I bring another article about an XSS vulnerability I discovered, equally straightforward.

Mu1berry, 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

Likely the server trusted the client-supplied Content-Type when storing and later serving the uploaded file, instead of deciding the type itself and forcing a safe one.

Impact

An uploaded file could be served as HTML, so script inside it could run in a victim's browser if they open the returned link, giving cross-site scripting.

What the attacker needed

Ability to upload a file; victim opens the returned link

The fix

The server should determine the file type itself and serve uploads with a safe Content-Type, such as a download-only type, rather than trusting the client's value.

How it was found

  1. Try changing the file extension and fuzzing the upload form, which did not bypass the checks.
  2. Change the request's Content-Type from an image type to text/html.
  3. Upload the file and note the returned path on a domain ending in 'local'.
  4. Replace 'local' with 'com' in the returned address to reach it.

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 you upload a file, your browser also tells the server what kind of file it is, using a label called Content-Type. This site trusted that label, so by claiming an uploaded file was a web page instead of a picture, the author got the site to hand the file back as a web page. That means any script inside the file runs in the browser of whoever opens the link.

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 xiaodongsec

View all

11 more disclosed reports, 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.