Closed Bug 1891234 (CVE-2024-5692) Opened 1 year ago Closed 1 year ago

Using ASCII code 0 can bypass the file download restriction on url/loca/lnk [Windows 10]

Categories

(Firefox :: File Handling, defect, P1)

Firefox 126
Desktop
Windows 10
defect

Tracking

()

RESOLVED FIXED
128 Branch
Tracking Status
firefox-esr115 127+ fixed
firefox126 --- wontfix
firefox127 + fixed
firefox128 + fixed

People

(Reporter: Laraweron, Assigned: enndeakin)

References

Details

(Keywords: csectype-spoof, reporter-external, sec-moderate, Whiteboard: [reporter-external] [client-bounty-form] [verif?][adv-main127+][adv-esr115.12+])

Attachments

(6 files)

Attached file poc.html

I discovered an incorrect symbol override of the character when placed in the file extension name. When the "Always ask for file save" flag is enabled, it is possible to save prohibited extensions that will not be converted to .download.
It is not possible to run such a file from the browser, but if the user executes the file from the folder, it could be dangerous.

An example of a file name looks like this: example.url. You can change it to any type of extension by adding just the character.
This works only for Windows.
I see that I cannot correctly transmit this character through the panel, decrypt BASE64 to understand which character is being discussed.

Flags: sec-bounty?
Status: NEW → UNCONFIRMED
Component: Security → File Handling
Ever confirmed: false
OS: Unspecified → Windows 10
Hardware: Unspecified → Desktop
Version: unspecified → Firefox 126
See Also: → CVE-2023-29542
Attached file local file.html

Using a phishing attack, it is also possible to read local files.

Hey Neil, could you take a look? I'm surprised that the null byte would be able to bypass any of the constraints added here.

Flags: needinfo?(enndeakin)

The filename in the testcase is \u0001, there is no null character that I can see.

A null character gets turned into an underscore so the filename becomes example._url
The \u0001 character will get converted into space so the filename becomes example. url with a space prefix.

My version of Windows 11 does not treat either case as a shortcut/link file. Is this different for earlier versions of Windows?

We could change the substitution to use a underscore for both I suppose if the space is causing an issue.

Flags: needinfo?(enndeakin)

(In reply to Neil Deakin from comment #3)

The filename in the testcase is \u0001, there is no null character that I can see.

A null character gets turned into an underscore so the filename becomes example._url
The \u0001 character will get converted into space so the filename becomes example. url with a space prefix.

My version of Windows 11 does not treat either case as a shortcut/link file. Is this different for earlier versions of Windows?

We could change the substitution to use a underscore for both I suppose if the space is causing an issue.

It appears that this works only for Windows 10 and only for Save As. I have looked at Google Chrome changing to underscore, and I think it would be wise to do the same.

Attached image file.jpg

Note that the file format transformation duplicates the file extension, and if we replace it with an underscore, we will no longer have this bug?

I checked and other characters, adding a character at the beginning of the file extension allows bypassing the filter. We can add space characters or ">", ":"
Based on this, it would be reasonable to limit the addition of characters at the beginning of the file extension.
Examples:
". :url"
". url"
".>url"

The primary issue here is that while we replace the invalid characters with spaces, at https://searchfox.org/mozilla-central/rev/fe2743c6c5c708061c7f6504b26958fcc815bb4a/widget/windows/nsFilePicker.cpp#1021 we strip out the whitespace, leaving a default extension with the same characters without the spaces. The Windows filepicker then does its own filename modification to match the extension filter.

We could change the substitution to use a underscore for both I suppose if the space is causing an issue.

Yeah, space is a bad substitution character—for anything, really—in the file extension part.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Using ASCII code 0 can bypass the file upload restriction on url/loca/lnk → Using ASCII code 0 can bypass the file upload restriction on url/loca/lnk [Windows 10]

(In reply to Neil Deakin from comment #7)

The primary issue here is that while we replace the invalid characters with spaces, at https://searchfox.org/mozilla-central/rev/fe2743c6c5c708061c7f6504b26958fcc815bb4a/widget/windows/nsFilePicker.cpp#1021 we strip out the whitespace, leaving a default extension with the same characters without the spaces. The Windows filepicker then does its own filename modification to match the extension filter.

Alas, we can't just drop the StripWhitespace call -- there are spaces in the input, both from the Web and internally. While I would like to move to something more like what the Gtk file-picker does and actually parse the input string instead of "sanitizing" it — preferably in cross-platform code, at that —

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

Yeah, space is a bad substitution character—for anything, really—in the file extension part.

— +1. This happens well before the platform-specific file-picker gets its hands on the filename and/or filter-set, and is presumably a cross-platform issue.

Neil, are you able to pick this up?

Flags: needinfo?(enndeakin)

I think what can happen here is to generally replace all invalid characters with underscores instead of spaces (Chrome seems to have this behaviour), and remove any whitespace from the extension.

Assignee: nobody → enndeakin
Status: NEW → ASSIGNED
Flags: needinfo?(enndeakin)

The severity field is not set for this bug.
:Gijs, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(gijskruitbosch+bugs)
Severity: -- → S2
Flags: needinfo?(gijskruitbosch+bugs)
Priority: -- → P1
Pushed by neil@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4b7fe66103e5 additional filename filter checks, r=Gijs,extension-reviewers,robwu

Backed out for assertion failures:
https://hg.mozilla.org/integration/autoland/rev/c70f720dd79a60e2604dcb63fec8d4a53f0ebb96

Push with failures
Failure log

ASSERTION: Illegal file characters have changed!: '!strcmp(QuotaManager::kReplaceChars, FILE_ILLEGAL_CHARACTERS FILE_PATH_SEPARATOR)', file /builds/worker/checkouts/gecko/dom/quota/SanitizationUtils.cpp:20) at /builds/worker/checkouts/gecko/xpcom/base/nsDebugImpl.cpp:512

The R(C) and Wr4 tasks are also assertion failures from this commit.

Flags: needinfo?(enndeakin)
Flags: needinfo?(enndeakin)
Group: firefox-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → 128 Branch

The patch landed in nightly and beta is affected.
:enndeakin, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox127 to wontfix.

For more information, please visit BugBot documentation.

Flags: needinfo?(enndeakin)
Blocks: 1837514
Flags: sec-bounty? → sec-bounty+

Comment on attachment 9398698 [details]
Bug 1891234, additional filename filter checks, r=gijs

Beta/Release Uplift Approval Request

  • User impact if declined: Improves the filename sanitization when saving files, otherwise a filename given by a page can be used to create a file that is saved an internet shortcut to a local file.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Improves filename sanitization using underscores instead of whitespace in a way similar to the way other browsers do.
  • String changes made/needed: None
  • Is Android affected?: Yes
Flags: needinfo?(enndeakin)
Attachment #9398698 - Flags: approval-mozilla-beta?
Attachment #9403357 - Flags: approval-mozilla-esr115?

esr115 Uplift Approval Request

  • User impact if declined: Improves the filename sanitization when saving files, otherwise a filename given by a page can be used to create a file that is saved an internet shortcut to a local file.
  • Code covered by automated testing: yes
  • Fix verified in Nightly: no
  • Needs manual QE test: no
  • Steps to reproduce for manual QE testing: n/a
  • Risk associated with taking this patch: Low
  • Explanation of risk level: Improves filename sanitization using underscores instead of whitespace in a way similar to the way other browsers do.
  • String changes made/needed: None
  • Is Android affected?: yes

Comment on attachment 9398698 [details]
Bug 1891234, additional filename filter checks, r=gijs

Approved for 127 beta 6, thanks.

See Also: → 1897051
Attachment #9398698 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
QA Whiteboard: [post-critsmash-triage]
Flags: qe-verify-
Attachment #9403357 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+

Neil, on esr115 the uplift is causing some failures:
https://treeherder.mozilla.org/logviewer?job_id=460383707&repo=mozilla-esr115&lineNumber=14423

Could you have a look please? Thanks

Flags: needinfo?(enndeakin)
Regressions: 1898498
Whiteboard: [reporter-external] [client-bounty-form] [verif?] → [reporter-external] [client-bounty-form] [verif?][adv-main127+]
Whiteboard: [reporter-external] [client-bounty-form] [verif?][adv-main127+] → [reporter-external] [client-bounty-form] [verif?][adv-main127+][adv-esr115.12+]
Alias: CVE-2024-5692
Summary: Using ASCII code 0 can bypass the file upload restriction on url/loca/lnk [Windows 10] → Using ASCII code 0 can bypass the file download restriction on url/loca/lnk [Windows 10]
Regressions: 1903780
Regressions: 1907931
Flags: needinfo?(enndeakin)
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: