Skip to content
File upload Write-up Beginner

Spoofing file extensions on HackerOne

HackerOne's file upload determined content type from file content rather than extension, and the download response lacked a filename in Content-Disposition, so browsers saved files with incorrect extensions. An attacker could upload a batch file or HTML file that appears as an image or text file, and if a user ignores the extension and opens it, malicious code could execute.

Anurag Jain Follow

Published on cooltrickshome.blogspot.com

While testing HackerOne, I observed an issue with the file upload functionality. It seems that on File upload, the uploader uses the content within the file for determining the content type of file instead of filetype .

Anurag Jain (@csanuragjain), on cooltrickshome.blogspot.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 set the Content-Type based on file content and omitted the filename in Content-Disposition, so browsers saved files with extensions derived from content type rather than the original extension.

Impact

An attacker could trick a user into downloading a file that appears to be an image or text file but is actually a batch script or HTML file; if the user ignores the file extension and opens it, malicious code could execute. The report notes that changed extensions would be visible at download time, and HackerOne closed the report as informative.

What the attacker needed

Victim clicks a link; victim ignores file extension; attacker can post a comment

How it was found

  1. Open any HackerOne report.
  2. Upload a batch file (batch.cmd) in a comment and post it.
  3. Open the uploaded file from the comment; an image is shown with no warning.
  4. Download the file; it is saved with an image extension.
  5. If the user ignores the extension and opens the file, the batch file executes.
  6. Similarly, upload a text file (myFile.txt) containing HTML; it is saved as an HTML file and scripts execute if opened.

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 to a website, the site decides what type of file it is. This site looked at the file's contents instead of its name, and when you downloaded it, the browser guessed the file type from the contents too. So a file that looks like an image might actually be a program or a web page, and opening it could run harmful code.

What is File upload?

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.

More from HackerOne

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.