Stored XSS via Image Upload and MIME-Type Confusion
The image upload feature accepted a file with a .gif extension whose Content-Type was changed to text/html and whose content contained an HTML/JavaScript payload. When the uploaded file was opened via its public URL, the browser rendered it as HTML and executed the script, giving stored XSS.
medium.com
Published on medium.com
During testing, I discovered a vulnerability that allows Stored Cross-Site Scripting (XSS) through an image upload functionality.
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 trusted the file extension and the client-supplied Content-Type instead of validating the actual file content, and then served the file in a way the browser rendered as HTML.
Impact
This could allow stored XSS, and depending on protections, session hijacking, malicious redirection and data exfiltration.
What the attacker needed
Ability to upload a profile picture; ability to intercept and modify the upload request
The fix
The upload should validate the real file content rather than the extension or client-supplied MIME type, and serve uploaded files with a safe content type and disposition so browsers do not render them as HTML.
How it was found
- Upload a profile picture using the image upload feature.
- Use a file with a .gif extension.
- Intercept the upload request and change the Content-Type header from image/jpeg to text/html.
- Put an HTML/JavaScript payload inside the file content.
- Complete the upload.
- Open the uploaded file via its public URL.
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 profile pictures. The upload check only looked at the file name ending and the declared file type, not what was actually inside the file. By renaming the declared type to a web page type and putting a small script inside, the file was shown as a web page, so the script ran in the browser of anyone who opened it.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.