Skip to content
File upload Write-up Intermediate

How Browser’s Save As Feature might lead to Code Execution (CVE-2022–45415)

The browser's Save Page As feature generated the saved file name from the page's title tag without properly restricting the file extension, allowing an attacker to host a page whose title ends in .hta. When a victim saved the page and opened the resulting file, the HTML content executed as a Windows script, leading to code execution.

Jayateertha Guruprasad Follow

Published on infosecwriteups.com

Few days ago, while I was exploring browser based bugs, I read a article over internet explaining about a path traversal vulnerability in Safari browser using Save Page As Feature. The file name was generated from content of <title></title> tag.

Jayateertha Guruprasad, on infosecwriteups.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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Mozilla Firefox's Save Page As feature lets a user store the current page on disk. Firefox derives the saved filename from the content of the page's <title></title> tag. That derived name includes the extension, so the title controls not only the base name but also the suffix the saved file receives.

The researcher, Jayateertha Guruprasad, was looking at browser-based bugs and had read an article describing a path traversal vulnerability in Safari that abused this same feature: because the filename came from the title tag, a title containing ../ characters could make the file land outside the default Downloads directory. That article is the starting point, not the target here.

Setup

The work is entirely client-side and needs no accounts or special tooling. The preconditions are:

  1. A browser with a Save Page As feature that builds the filename from the title tag.
  2. A page the victim can be persuaded to open and save, hosted anywhere the researcher controls.
  3. For the final impact, a Windows host where the saved file is later opened.

The researcher tested the path traversal behaviour across the major browsers. All of them, Firefox included, were safe: they sanitised the input or checked the canonical path, so ../ in the title could not escape the download directory. Firefox still generated the filename from the title tag, but the traversal was blocked.

Finding it

The observation that drove the rest of the work was that sanitisation only removes the dangerous path characters. The title still determines the extension of the saved file. In the researcher's words, the question became whether the feature could be exploited without path traversal, given that input sanitisation was in place.

To confirm the extension control, a page was hosted with this content:

HTML
<html><head><title>malicious.exe</title></head><body>This is a html file</body></html>

Opening the hosted page and using Save Page As produced a file named malicious.exe, even though the original file was index.html and its content was HTML. The title tag alone decided the name and the extension.

That alone is not code execution. A .exe, .bat or .ps1 file containing HTML cannot be run: the researcher also tried embedding binary or executable content inside an HTML file with a malicious filename in the title, and it still would not execute because the file is not a valid executable. The filename was controlled, but the content could only be HTML.

The next question was therefore whether any extension accepts HTML content and still executes code. The answer used here is Microsoft Hyper Text Application, the .hta extension, which can contain classic HTML together with VBScript or JScript. When an .hta file is opened, its content is parsed and executed by mshta.exe. The researcher notes this is not a new technique and is widely used by APT groups, citing the MITRE reference for T1218/005.

Exploitation

Step 1: Build the page

A proof of concept was prepared as an HTML file named index.html whose title carries the .hta extension, so that saving the page produces mal.hta. The source is published on Pastebin and a live hosted preview is provided; the report does not reproduce the file's body inline.

Step 2: Save the page in Firefox

With the page open in Mozilla Firefox, the user invokes Save Page As. Because the filename is generated from the title tag, the saved file is written with the .hta extension rather than .html.

Step 3: Open the saved file

When the saved mal.hta is opened, mshta.exe parses and executes its contents, giving code execution on the victim's machine. The researcher recorded a video of the proof of concept in Firefox.

Root cause

The filename for a saved page is derived from attacker-controlled page content, the title tag, and the extension is taken from that same string. The defence that existed, sanitisation of the title and a canonical path check, was aimed at path traversal: it stops ../ from moving the file out of the download directory. It does not constrain which extension the saved file receives. The browser therefore hands the user a file whose type is chosen by the page author.

Impact

The result is code execution on a victim's Windows machine, but only under specific conditions: the victim must open the attacker's page in Firefox, choose Save Page As, and then open the saved .hta file. The researcher describes the outcome as the victim getting pwned. The report does not describe any automatic execution, any bypass of a warning prompt, or any way to trigger the save without user action.

Mozilla was already aware of a related issue without a security impact: Jefferson Scher had earlier reported that Save Page As creates an erroneous file extension if the page title ends with a TLD. It was the valid proof of concept and the demonstrated security impact that moved this report forward. Mozilla fixed it quickly and released the fix, credited the researcher in advisory CVE-2022-45415, and paid a bounty, shown in the report as $xxxx.

Me enjoying the bounty after the hunt ! From the original on infosecwriteups.com

Me enjoying the bounty after the hunt !

Fix

Mozilla fixed the issue and shipped the fix in a release. The report does not describe the code change itself. The general lesson is that a filename derived from page content should not let the page choose the extension, or at least should not let it choose an extension that the operating system treats as executable.

Report timeline

  1. Reported: 4 October 2022
  2. Fixed: 20 October 2022
  3. Bounty awarded: 26 October 2022

Variants to test

  1. Other browsers' Save Page As. Host a page whose title ends in an executable or script extension and save it. A positive result is a saved file carrying that extension while the content is still HTML.
  2. Other title-derived names. Look for any feature that derives a filename, a MIME type or a handler from page content (print to file, export, share, offline save). A positive result is a file or type chosen by the page rather than by the user.
  3. Extensions that execute HTML-like content. Beyond .hta, check which extensions on the target platform are executed by a handler that tolerates HTML or script, and whether the browser will produce them from a title.
  4. Sanitisation boundaries. Where traversal is blocked, test whether the sanitiser strips path characters but leaves the extension intact, and whether unusual characters in the title survive into the saved name.
  5. TLD-style titles. Reproduce the earlier class of bug by ending the title with a TLD and observing the generated extension, to see whether the same filename logic is still in play.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

A security researcher found a way to make Mozilla Firefox save a web page as a file that Windows would later run as a program. The trick did not need any special tools or accounts. It relied on a small feature almost everyone has used: Save Page As, the menu option that stores a copy of the page you are looking at on your computer.

When you save a page, Firefox builds the filename from the page's title, the text that appears in the browser tab. That name includes the part after the dot, the extension, which tells the operating system what kind of file it is: .html for a web page, .exe for a Windows program, and so on. Because the page author controls the title, the page author also controls the extension of the saved file.

The researcher worked out that a page could carry a title ending in .hta, an extension Windows treats as a runnable program. When a visitor saved that page and then opened the saved file, Windows ran the page's contents as code. Mozilla fixed the problem, published it as CVE-2022-45415, credited the researcher and paid a bounty.

This article walks through the same story from the beginning, explaining each idea as it comes up.

Some background first

What a browser does when it saves a page

A web page is not a single file. It is usually an HTML document plus images, stylesheets and scripts. When you choose Save Page As, the browser writes a copy of all of that to your disk, normally in your Downloads folder. To do that it needs a filename.

A header is a small line of information the server sends alongside the page, a bit like the label on a parcel telling the post office what is inside and how to handle it. Firefox takes the text inside the page's <title></title> tag and uses it as the filename.

That fallback is the heart of this story. The title tag is written by whoever made the page. So whoever made the page gets to influence the name of the file that lands on your computer, including the extension at the end.

What path traversal is

A path is the address of a file on a disk, something like C:\Users\you\Downloads\page.html. The two dots .. mean "the folder above this one". If a program lets you put .. into a filename, you can sometimes make it write outside the folder it intended, for example into a system folder. That class of bug is called path traversal: you traverse, or walk, out of the place you were supposed to stay in.

An everyday comparison: imagine a hotel clerk who files your paperwork in the drawer marked with your room number. If you can write "room 12, then go up two floors" on the form, the clerk may file it somewhere you were never meant to reach. Path traversal is that, for files.

The article that started it

The researcher, Jayateertha Guruprasad, was exploring browser bugs and read an article about a path traversal vulnerability in the Safari browser that abused this same Save Page As feature. In Safari, the filename came from the title tag, so a title containing ../ characters could make the saved file land in a directory other than the intended or default Downloads folder. That article was the starting point, not the target.

Checking the other browsers

The researcher wanted to see whether the same path traversal worked in the other major browsers. It did not. All of them, Firefox included, were safe: they cleaned up the input, or sanitised it, and checked the final, canonical path, so ../ in the title could not escape the download folder.

Sanitising means removing or neutralising characters that could be misused, the way a form that asks for a name might strip out slashes so you cannot type a folder path. A canonical path check means the browser works out the real, final location of the file and confirms it is still inside the folder it is allowed to use.

Firefox still built the filename from the title tag. It just blocked the traversal. That left an open question, which the researcher put like this: given that input sanitisation is in place, is it possible to exploit this scenario without path traversal?

Finding the real issue

The key observation was that sanitisation only removes the dangerous path characters. The title still decides the extension of the saved file. The researcher still had control over the suffix, even without being able to move the file anywhere.

To confirm that, a page was hosted with this content:

HTML
<html><head><title>malicious.exe</title></head><body>This is a html file</body></html>

Line by line, in plain words:

  • <html> opens the document, telling the browser that what follows is a web page.
  • <head> opens the section that holds information about the page rather than visible content.
  • <title>malicious.exe</title> sets the page title to the text malicious.exe. This is the text that appears in the browser tab, and, crucially, the text Firefox will use as the filename when saving.
  • <body>This is a html file</body> is the visible part: the page simply shows the sentence "This is a html file".
  • </html> closes the document.

Opening that hosted page and using Save Page As produced a file named malicious.exe, even though the original file was index.html and its content was ordinary HTML. The title tag alone decided both the name and the extension. The researcher notes that you might not reproduce this now, because it is already fixed in Firefox.

That on its own is not code execution. A .exe, .bat or .ps1 file containing HTML cannot be run. The researcher also tried putting binary or executable content inside an HTML file with a malicious filename in the title, and it still would not execute, because the file is not a valid executable. The filename was under control, but the content could only be HTML.

So the next question was whether any extension accepts HTML content and still executes code.

The extension that runs HTML

The answer used here is Microsoft Hyper Text Application, the .hta extension. An .hta file can contain classic HTML together with VBScript or JScript, which are scripting languages Windows understands. When an .hta file is opened, its content is parsed and executed by a Windows program called mshta.exe.

An everyday comparison: most file types are like a sealed envelope that only one kind of reader is allowed to open. An .hta file is an envelope that the operating system hands straight to a reader which will follow any instructions written inside, including instructions to run programs. That is why the extension matters so much.

The researcher notes this is not a new technique and is widely used by APT groups, citing the MITRE reference for T1218/005. APT stands for advanced persistent threat, a term for well-resourced attackers who operate quietly over long periods.

Exploitation, step by step

Step 1: Build the page

A proof of concept was prepared as an HTML file named index.html whose title carries the .hta extension, so that saving the page produces mal.hta. The source is published on Pastebin and a live hosted preview is provided; the report does not reproduce the file's body inline.

A proof of concept, or POC, is a small demonstration that proves a bug is real and shows its effect, without needing to be a finished attack.

Step 2: Save the page in Firefox

With the page open in Mozilla Firefox, the user invokes Save Page As. Because the filename is generated from the title tag, the saved file is written with the .hta extension rather than .html.

Step 3: Open the saved file

When the saved mal.hta is opened, mshta.exe parses and executes its contents, giving code execution on the victim's machine. The researcher recorded a video of the proof of concept in Firefox.

Code execution means that instructions written by someone else end up running on your computer, with your permissions. It is the difference between someone sending you a letter and someone being able to use your kitchen.

Why it worked

The filename for a saved page is derived from attacker-controlled page content, the title tag, and the extension is taken from that same string. The defence that existed, sanitisation of the title and a canonical path check, was aimed at path traversal: it stops ../ from moving the file out of the download folder. It does not constrain which extension the saved file receives. The browser therefore hands the user a file whose type is chosen by the page author.

In other words, the guard was watching the door for people trying to walk into other rooms, and never noticed that the visitor had brought their own key to the front door.

What the impact was, and what it was not

The result is code execution on a victim's Windows machine, but only under specific conditions: the victim must open the attacker's page in Firefox, choose Save Page As, and then open the saved .hta file. The researcher describes the outcome as the victim getting pwned, slang for being fully compromised. The report does not describe any automatic execution, any bypass of a warning prompt, or any way to trigger the save without user action.

Mozilla was already aware of a related issue without a security impact: Jefferson Scher had earlier reported that Save Page As creates an erroneous file extension if the page title ends with a TLD. A TLD, or top-level domain, is the last part of a web address such as .com or .org. It was the valid proof of concept and the demonstrated security impact that moved this report forward. Mozilla fixed it quickly and released the fix, credited the researcher in advisory CVE-2022-45415, and paid a bounty, shown in the report as $xxxx.

A CVE is a public identifier for a known vulnerability, so that people can refer to the same bug unambiguously. A bounty is a payment a company makes to a researcher who reports a security problem responsibly.

Me enjoying the bounty after the hunt ! From the original on infosecwriteups.com

Me enjoying the bounty after the hunt !

The fix

Mozilla fixed the issue and shipped the fix in a release. The report does not describe the code change itself. The general lesson is that a filename derived from page content should not let the page choose the extension, or at least should not let it choose an extension that the operating system treats as executable.

Report timeline

  1. Reported: 4 October 2022
  2. Fixed: 20 October 2022
  3. Bounty awarded: 26 October 2022

Things worth testing yourself

  1. Other browsers' Save Page As. Host a page whose title ends in an executable or script extension and save it. A positive result is a saved file carrying that extension while the content is still HTML.
  2. Other title-derived names. Look for any feature that derives a filename, a MIME type or a handler from page content (print to file, export, share, offline save). A positive result is a file or type chosen by the page rather than by the user. A MIME type is a label such as text/html that says what kind of content something is.
  3. Extensions that execute HTML-like content. Beyond .hta, check which extensions on the target platform are executed by a handler that tolerates HTML or script, and whether the browser will produce them from a title.
  4. Sanitisation boundaries. Where traversal is blocked, test whether the sanitiser strips path characters but leaves the extension intact, and whether unusual characters in the title survive into the saved name.
  5. TLD-style titles. Reproduce the earlier class of bug by ending the title with a TLD and observing the generated extension, to see whether the same filename logic is still in play.

Glossary

  • APT (advanced persistent threat): a well-resourced attacker who operates quietly over a long period, often a group rather than one person.
  • Bounty: a payment a company makes to a researcher who reports a security problem responsibly.
  • Browser: the program you use to view web pages, such as Firefox, Safari or Chrome.
  • Canonical path: the real, final location of a file on disk, with all shortcuts and relative parts resolved.
  • Code execution: a situation where instructions written by someone else run on your computer with your permissions.
  • Content-Disposition header: a line the server sends to suggest a filename for a downloaded or saved file.
  • CVE: a public identifier for a known vulnerability, so people can refer to the same bug unambiguously.
  • Extension: the part of a filename after the dot, such as .html or .exe, which tells the operating system what kind of file it is.
  • Header: a small line of information a server sends alongside a page, describing how it should be handled.
  • HTML: the language web pages are written in, made of tags such as <title> and <body>.
  • .hta (Microsoft Hyper Text Application): a Windows file type that can contain HTML plus VBScript or JScript, and is executed by mshta.exe when opened.
  • HTTP: the protocol browsers and servers use to exchange pages and other content.
  • JScript / VBScript: scripting languages Windows can run, often embedded in .hta files.
  • MIME type: a label such as text/html that says what kind of content something is.
  • mshta.exe: the Windows program that parses and runs .hta files.
  • Path: the address of a file on a disk, such as C:\Users\you\Downloads\page.html.
  • Path traversal: a bug where .. in a filename lets a program write or read outside the folder it intended.
  • POC (proof of concept): a small demonstration that proves a bug is real and shows its effect.
  • Pwned: slang for being fully compromised, with an attacker able to run code on your machine.
  • Sanitisation: cleaning up input by removing or neutralising characters that could be misused.
  • Save Page As: the browser feature that stores a copy of the current page on your disk.
  • Title tag: the <title></title> element in a page, whose text appears in the browser tab and which Firefox uses as the filename when saving.
  • TLD (top-level domain): the last part of a web address, such as .com or .org.
  • Vulnerability: a weakness in software that someone can misuse to make it behave in ways its maker did not intend.

More by Jayateertha Guruprasad

View all

10 more disclosed reports, best first.

More from Mozilla (Firefox)

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.