Closed Bug 2037801 Opened 6 months ago Closed 6 months ago

Path traversal in custom profile ZIP extraction allows arbitrary file writes

Categories

(Testing :: geckodriver, defect, P2)

defect
Points:
2

Tracking

(firefox-esr115 wontfix, firefox-esr140 wontfix, firefox151 wontfix, firefox152 wontfix, firefox153 fixed)

RESOLVED FIXED
153 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 --- wontfix
firefox151 --- wontfix
firefox152 --- wontfix
firefox153 --- fixed

People

(Reporter: whimboo, Assigned: whimboo)

References

Details

(Keywords: csectype-priv-escalation, sec-moderate, Whiteboard: [webdriver:m20][adv-main153+r])

Attachments

(2 external files, 1 obsolete file)

unzip_buffer() in testing/geckodriver/src/capabilities.rs:800-850 uses file.name() from the zip crate to construct extraction paths, but name() returns the raw, unsanitized entry name from the ZIP archive. An attacker who controls WebDriver session capabilities can craft a ZIP with entries containing ../ sequences (e.g. ../../../tmp/malicious) and supply it as the base64-encoded moz:firefoxOptions.profile value. When geckodriver extracts the profile, files are written outside the temporary profile directory to arbitrary locations on the filesystem.

The vulnerable code path is:

  load_profile() [capabilities.rs:548]
    → base64-decode moz:firefoxOptions.profile
    → unzip_buffer(profile_zip, temp_dir) [capabilities.rs:560]
      → file.name()           // raw unsanitized ZIP entry name [line 813]
      → Path::new(name)       // preserves ../ components [line 815]
      → dest_dir.join(rel_path)  // traversal escapes dest_dir [line 816]
      → fs::create_dir_all()  // creates parent directories outside profile [line 828]
      → fs::File::create()    // writes file outside profile [line 841]

The zip crate already provides enclosed_name() specifically for this purpose. It validates that resolved paths stay within the extraction directory by rejecting absolute paths, null bytes, and ../ sequences that would escape the base directory. It returns None for unsafe entries.

As such we should replace file.name() with file.enclosed_name() and skip entries that return None:

  let enclosed = file.enclosed_name();
  let Some(rel_path) = enclosed else {
      warn!("Skipping potentially unsafe ZIP entry: {}", file.name());
      continue;
  };
  let dest_path = dest_dir.join(rel_path);

Additional concerns with the current extraction:

  • Absolute paths in ZIP entries (e.g. /etc/foo) cause Path::join() to discard the base directory entirely, writing directly to the absolute location.
  • No check for symlink entries in the ZIP (external_attr with Unix symlink flag 0xA000), which could be combined with traversal.
  • No total decompressed size limit, making ZIP bomb attacks possible.
Severity: -- → S3
Points: --- → 2
Priority: -- → P2
Whiteboard: [webdriver:m20]
Blocks: 1938333
Attached file (secure) —

Use enclosed_name() instead of name() when resolving ZIP entry paths in
unzip_buffer(). This rejects entries containing ../ sequences that would
escape the destination directory, preventing arbitrary file writes when
a malicious profile ZIP is supplied via moz:firefoxOptions.profile.

DO NOT LAND TOGETHER WITH THE PATCH

Assignee: nobody → hskupin
Status: NEW → ASSIGNED
Attached file (secure) (obsolete) —
Attachment #9587561 - Attachment is obsolete: true

I'm going to land the patch on its own and will follow-up with landing the tests once GitHub download numbers show that most systems running the upcoming 0.37.0 release of geckodriver.

Flags: needinfo?(hskupin)
Pushed by hskupin@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2fec8aad5a69 https://hg.mozilla.org/integration/autoland/rev/57fed9c0b831 [geckodriver] Error and cleanup on invalid files in the profile. r=geckodriver-reviewers,jgraham
Status: ASSIGNED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 153 Branch

Hi Dan. Do we have guidelines for when to land patches that add tests for fixed security bugs in external applications such as geckodriver?

Our last release was on June 3rd, and we are planning another release soon. Given that, I’m wondering whether we can already land the tests for this bug, or if we should wait longer.

Unfortunately, I cannot provide historical download data for the last month. All geckodriver binaries are served through the GitHub release page, and GitHub statistics only expose aggregate download counts.

Flags: needinfo?(hskupin) → needinfo?(dveditz)

We don't have anything for external apps specifically, but they all assume that there was some sort of associated security advisory that let people know they have to update. A month after the release would normally be fine, but if there wasn't an advisory (for anything) in that release that would drive updates then maybe it's not.

I'm not sure I realized geckodriver had separate binary releases. As this bug is currently marked our advisory scripts would see this as a bug that needed a Firefox CVE/advisory for Firefox 153 which is currently scheduled for July 21. But it looks like bugs like this should get advisories on a different cycle and possibly published as GitHub advisories rather than Firefox ones. I'm guessing this is the bug referred to by

  • Invalid files encountered when extracting a custom profile now raise an error.

... and in the future something like that could be moved from the "Changed" section to the "Fixed" section and include the CVE. In fact, we could just call that the advisory and not have to publish a whole GitHub or Firefox advisory page just to repeat it.

Flags: needinfo?(dveditz)

(In reply to Daniel Veditz [:dveditz] from comment #8)

... and in the future something like that could be moved from the "Changed" section to the "Fixed" section and include the CVE. In fact, we could just call that the advisory and not have to publish a whole GitHub or Firefox advisory page just to repeat it.

If we do it independently from Firefox who is in charge of creating such a CVE? I assume it would still have to be an external entry that we then have to reference in our release notes. It would also mean that we need it before the geckodriver release so that we can correctly update the release notes. Should we do something like that in the future? If yes, maybe a separate bug might be good to discuss all the details and the required steps in case of another security bug is found?

For the last release I can still change it from Changed to Fixed, but not sure if adding a CVE now still makes sense? Maybe we wait another month then to land the tests.

Flags: needinfo?(dveditz)
Flags: needinfo?(dveditz)
Whiteboard: [webdriver:m20] → [webdriver:m20][adv-main153+r]
Group: core-security-release
Attachment #9585612 - Attachment description: (secure) → Bug 2037801 - [geckodriver] Update tests for unzipping zip archives.
Pushed by hskupin@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/72099406ea07 https://hg.mozilla.org/integration/autoland/rev/96b6350ba523 [geckodriver] Update tests for unzipping zip archives. r=geckodriver-reviewers,jgraham
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: