Skip to content
XSS Write-up Intermediate

From Uploading a “PDF” To Owning The Admin Account

The upload feature accepted an HTML file disguised as a PDF because it trusted the filename extension and Content-Type header. An attacker could upload malicious HTML that, when opened by an admin, stole the admin's bearer token from localStorage and sent it to an attacker-controlled server, leading to admin account takeover.

medium.com

Published on medium.com

But deep inside this “Normal” feature… a silent attack chain is waiting to happen.

Rehan Ansari, 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 backend trusted the file extension and Content-Type header instead of validating the actual file content with magic bytes.

Impact

An attacker could steal an admin's bearer token and take over the admin account.

What the attacker needed

Upload feature accepting PDFs; admin reviews uploaded files; token stored in localStorage

The fix

The upload feature should validate file content using magic bytes, serve uploaded files as downloads with Content-Disposition: attachment, never render user-uploaded HTML, and implement a Content-Security-Policy.

How it was found

  1. Upload a legitimate PDF file.
  2. Intercept the upload request in Burp Suite.
  3. Change the filename from .pdf to .html and the Content-Type from application/pdf to text/html.
  4. Delete the PDF content and inject malicious HTML.
  5. Forward the request; the server accepts the file as HTML.
  6. The admin opens the uploaded file, the script runs, steals the token from localStorage, and sends it to the attacker.

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 files but only checked the file's name and the label it claimed to be, not what was actually inside. An attacker uploaded a web page disguised as a PDF; when an administrator opened it, the page ran code that copied the admin's login token and sent it to the attacker. With that token, the attacker could log in as the admin.

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.