Content-Disposition filename truncation leads to Reflected File Download
Firefox truncates the filename in a Content-Disposition header at a NULL character, keeping only the part before it. An attacker could use this to make a downloaded file appear with a dangerous extension such as .cmd, bypassing server-side extension checks and enabling reflected file download.
Originally disclosed on Mozilla
- Fixed in 7 months
- Paid in 7 months
- Disclosed after 7 months
User-Agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
When handling filename directive in the Content-Disposition header, the filename would be truncated if the token contains a NULL character and only the first part is kept: `filename.exe<NULL>.txt` -> `filename.exe`
This behavior makes Firefox users vulnerable to reflected file download (RFD). For instance, CVE-2022-36359[1] in Django that has been patched[2] is still exploitable on Firefox because the filename truncation provides a trivial way to manipulate and bypass extension checking/appending on the server side. These RFD vulnerabilities such as CVE-2022-36359, CVE-2015-5211[3] and CVE-2020-5398[4] in Spring Frameworks are all rated as High or Important in severity by the project maintainers.
More about RFD: https://securitylab.github.com/research/rfd-spring-mvc-CVE-2020-5398/
I know the vulnerability exists partly because Django allows invalid characters (RFC 2616 I suppose) in the filename. That said, this can only be addressed reliably from the client side. I believe it would be reasonable to stop accepting responses with invalid headers.
'''
from django.shortcuts import render
from django.http import FileResponse
def index(request):
filename = request.GET.get('filename') + ".pdf"
print(filename)
return FileResponse(open("/test.txt", 'rb'), as_attachment=True, filename=filename)
'''
Given `request.GET.get('filename') = file.cmd%00`, Firefox would download the file `file.cmd` instead of `file.cmd.pdf` while Chromium and Safari threw an error (ERR_INVALID_HTTP_RESPONSE) and refused to open the page in this case.
Response:
'''
HTTP/1.1 200 OK
Date: Thu, 11 Aug 2022 19:40:57 GMT
Server: WSGIServer/0.2 CPython/3.8.10
Content-Type: application/octet-stream
Content-Length: 3213
Content-Disposition: attachment; filename="file.cmd<NULL>.pdf"
'''
[1] https://www.djangoproject.com/weblog/2022/aug/03/security-releases/
[2] https://github.com/django/django/commit/bd062445cffd3f6cc6dcd20d13e2abed818fa173
[3] https://tanzu.vmware.com/security/cve-2015-5211
[4] https://tanzu.vmware.com/security/cve-2020-5398
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely Firefox does not reject or sanitise NULL characters in the Content-Disposition filename, so it truncates the value at the NULL and uses only the prefix.
Impact
Firefox users could be tricked into downloading and running a file with a dangerous extension, while Chromium and Safari refused the response.
What the attacker needed
Firefox as the browser; victim clicks a crafted link; server reflects the filename
The fix
Firefox should reject responses whose headers contain invalid characters such as NULL rather than truncating the filename.
How it was found
- Send a request whose filename parameter ends with a NULL character followed by a safe extension.
- The server appends its own extension and returns a Content-Disposition header containing the NULL.
- Firefox truncates the filename at the NULL and saves the file with the attacker-chosen extension.
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 report has not been written yet. The Original tab links to the source.
When a website sends a file to your browser, it includes a suggested filename in a header. Firefox stops reading that name at a special invisible character called NULL, so a name ending in .pdf can be cut down to end in .cmd instead. That means a file the server thought was safe could be saved with a dangerous extension, and opening it could run code on the user's machine.
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.