Closed Bug 1433890 Opened 8 years ago Closed 1 year ago

WebExtension directory listing shows local file:-URL

Categories

(WebExtensions :: General, defect, P3)

60 Branch
defect

Tracking

(firefox-esr115 wontfix, firefox-esr140146+ verified, firefox144 wontfix, firefox145 wontfix, firefox146+ verified)

VERIFIED FIXED
146 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 146+ verified
firefox144 --- wontfix
firefox145 --- wontfix
firefox146 + verified

People

(Reporter: qab, Assigned: valentin)

Details

(Keywords: csectype-disclosure, sec-low, Whiteboard: [adv-main146-][adv-esr140.6-])

Attachments

(1 file, 4 external files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 Steps to reproduce: This does not work on temporary extensions. I have NoScript installed and will use it as an example. Going to 'moz-extension://0cab90f5-29bf-4c63-8caa-0f71b91517f4/' will result in a file list, and on the top is 'jar:file:///C:/Users/Abdulrahman/AppData/Roaming/Mozilla/Firefox/Profiles/1eevha2t.default-{salt}/extensions/%7B73a6fe31-595d-460b-a920-fcc0f8843232%7D.xpi!/' Actual results: this information could be used to get two things: 1. OS username 2. Salted profile directory Since webextensions have access to their own moz-extension URLS then this info can be read easily and then used with another exploit Basically this is somewhat of a SOP bypass because 'moz-extension://{ID}/' points to a 'jar:file:' yet 'moz-extensions://{ID}/some-page.html' can link to and has full access to 'moz-extension://{ID}/' Expected results: I think visiting the root directory of installed extensions should return an error instead.
Group: toolkit-core-security
Component: Untriaged → WebExtensions: Untriaged
Product: Firefox → Toolkit
Ignore the 'somehwat of an SOP bypass' it definitely isn't since all files technically point to some jar:file: location. Though there is still a sensitive information disclosure here.
Confirmed. This is a privacy info leak, and it'd be nice to prevent it. In order to leak this information you've installed a web extension that can follow what you're doing on the web and potentially gather even more information so it's hard to rate it very high. NB: a simplistic approach like blocking loads of the extension's root is not enough. We have to prevent loading anything that returns a directory listing because they all will contain the full profile directory path. For example if you have Stylish installed you can load moz-extension://{ID}/images/ and learn the same. From a nerd/developer/learning perspective it'd be nice to allow loads of the same if the user enters them manually into a URL bar, but we probably just have to block them outright. If we can distinguish between the real referrer and an overridden referrer maybe we could use a blank referrer as the clue, but keep in mind an evil extension could use referrerpolicy=no-referrer to suppress the referrer.
Group: firefox-core-security
Status: UNCONFIRMED → NEW
Ever confirmed: true
I think we can probably just fix the directory listing converter to use the right final channel URI
(In reply to Daniel Veditz [:dveditz] from comment #2) > Confirmed. This is a privacy info leak, and it'd be nice to prevent it. In > order to leak this information you've installed a web extension that can > follow what you're doing on the web and potentially gather even more > information so it's hard to rate it very high. I only used NoScript because that's all I had installed from web at the time. This can be done with an extension that has no extra privileges (no 'permissions' set in manifest.json) all you need is to open a malicious html file within moz-extensions: and you can iframe a directory and read from it. For example, take this addon ( https://addons.mozilla.org/en-US/firefox/addon/enhancer-for-youtube/ ), it only asks for permission for youtube.com and some other website. (no mention of '<all_urls>', 'activeTab' or 'tabs'). As soon as you install it, it will take you to its moz-extension page. Within this page, insert an iframe pointing to root directory, then attempt to access this iframe and you will notice you can read everything.
Attached file Minimized testcase β€”
The full effect can only happen if extension installed from web (specifically getting the OS username and profile directory) But if installed from XPI (temporarily) will give you the general idea of it.
Priority: -- → P3
Product: Toolkit → WebExtensions
Group: toolkit-core-security → firefox-core-security
Severity: normal → S3

re-triaged, leaving at same prio/sev

I can only reproduce with non-default prefs. However, I think that this is more a coincidence than an intentional fix, because there is a way to reproduce it anyway. Before closing this bug, we need a unit test at least.


I can only reproduce this if I set extensions.webextensions.protocol.remote to false or extensions.webextensions.remote to false (and restart the browser). I wondered why this is the case, so I visited a moz-extension://.../ URL with some logging

MOZ_LOG=ExtProtocol:5,nsJarProtocol:5,URILoader:5,DocumentChannel:5 ./mach run --temp-profile --setpref=extensions.webextensions.protocol.remote=false (and without the pref).

Both runs have in common that the channe's type is set to "application/http-index-format" (via nsJARChannel::GetContentTypeGuess), e.g.

[Parent 87791: Main Thread]: D/URILoader [0x17865bb80] nsDocumentOpenInfo::OnStartRequest
[Parent 87791: Main Thread]: D/URILoader [0x17865bb80] nsDocumentOpenInfo::DispatchContent for type ''
[Parent 87791: Main Thread]: D/URILoader   Got type from channel: 'application/http-index-format'
[Parent 87791: Main Thread]: D/URILoader   forceExternalHandling: no
[Parent 87791: Main Thread]: D/URILoader   IsSandboxed: no
[Parent 87791: Main Thread]: D/URILoader   IsContentPDF: no
[Parent 87791: Main Thread]: D/URILoader   Success!  Our default listener likes this type
[Parent 87791: Main Thread]: D/URILoader   After dispatch, m_targetStreamListener: 0x17c0f4538, rv: 0x00000000
[Parent 87791: Main Thread]: V/DocumentChannel DocumentLoadListener OnStartRequest [this=30f4d0100]
[Parent 87791: Main Thread]: V/DocumentChannel DocumentLoadListener::TriggerRedirectToRealChannel [this=30f4d0100] aDestinationBrowsingContext=11 aDestinationProcess=-1
[Parent 87791: Main Thread]: V/DocumentChannel DocumentLoadListener RedirectToRealChannel [this=30f4d0100] aRedirectFlags=4, aLoadFlags=3d0004

However, by default (when extensions or the protocol run in-process), the log deviates in nsDocumentOpenInfo::DispatchContent:

[Child 87854: Main Thread]: D/URILoader [0x103898040] nsDocumentOpenInfo::OnStartRequest
[Child 87854: Main Thread]: D/URILoader [0x103898040] nsDocumentOpenInfo::DispatchContent for type ''
[Child 87854: Main Thread]: D/URILoader   Got type from channel: 'application/x-unknown-content-type'

In contrast, when extensions.webextensions.protocol.remote is set to false, the type is preserved (and the index is rendered, as reported here)

[Child 87796: Main Thread]: D/URILoader [0x10a32ee60] nsDocumentOpenInfo::OnStartRequest
[Child 87796: Main Thread]: D/URILoader [0x10a32ee60] nsDocumentOpenInfo::DispatchContent for type ''
[Child 87796: Main Thread]: D/URILoader   Got type from channel: 'application/http-index-format'

I think that this is happening because DocumentLoadListener::SerializeRedirectData does not copy the channel's contentType.

Valentin, what is the intended behavior for contentType here?

Component: Untriaged → General
Flags: needinfo?(valentin.gosu)
Summary: Installed WebExtension root directory contains sensitive information → WebExtensio directory listing shows local file:-URL
Summary: WebExtensio directory listing shows local file:-URL → WebExtension directory listing shows local file:-URL

I think in this case the difference I'm seeing is that in the content process nsDocumentOpenInfo::OnStartRequest gets called with a mozilla::net::SimpleChannelChild when the pref is true, and mozilla::net::FileChannelChild/nsJARChannel when it's false.

And I assume SimpleChannelChild returns application/x-unknown-content-type because it hasn't been set to something else.

I think that this is happening because DocumentLoadListener::SerializeRedirectData does not copy the channel's contentType.

The contentType does get copied via mozilla::net::DocumentLoadListener::SerializeRedirectData > mozilla::net::HttpBaseChannel::CloneReplacementChannelConfig, but that only happens for nsHttpChannel

Note that nsURILoader::OpenURI does know it's opening a moz-extension URI, so we could just add a check to handle application/http-index-format as application/x-unknown-content-type when the URI had a moz-extension scheme?

Maybe Nika has an idea for a more fool-proof fix here.

Flags: needinfo?(valentin.gosu) → needinfo?(nika)

(In reply to Valentin Gosu [:valentin] (he/him) from comment #8)

I think in this case the difference I'm seeing is that in the content process nsDocumentOpenInfo::OnStartRequest gets called with a mozilla::net::SimpleChannelChild when the pref is true, and mozilla::net::FileChannelChild/nsJARChannel when it's false.

This does align with my memory of how the extension channel works under the hood. IIRC currently in the parent process, the channel redirects to an in-process JAR channel, while within a content process, the channel creates the JAR channel behind the scenes and forwards the status notifications to a nsSimpleChannel's listeners.

I was a touch surprised that the URL being loaded ends up showing the bare jar: URI within the header, as we also redirect to a jar URI under the hood for resource:// URIs, but the header in those listings shows the expected URI there (e.g. if you type resource://gre/ it'll show a directory listing starting with "Index of resource://gre/"). Looking at the stream converter which performs the conversion, it appears this is happening because of https://searchfox.org/firefox-main/rev/054e2b072785984455b3b59acad9444ba1eeffb4/netwerk/streamconv/converters/nsIndexedToHTML.cpp#137-142, which explicitly makes resource:// URIs show the original URI instead of the resolved URI. If we add a && !uri->SchemeIs("moz-extension") we could also get the proper moz-extension: path shown when the stream converter displays the HTML listing, which I believe would fix the original concern of leaking the raw JAR URI into the DOM:

   // We use the original URI for the title and parent link when it's a
-  // resource:// url, instead of the jar:file:// url it resolves to.
+  // resource:// or moz-extension:// url, instead of the jar:file:// url it resolves to.
-  if (!uri->SchemeIs("resource")) {
+  if (!uri->SchemeIs("resource") && !uri->SchemeIs("moz-extension")) {
     rv = channel->GetURI(getter_AddRefs(uri));
     if (NS_FAILED(rv)) return rv;
   }

As a side note: I'm not sure why we don't always use GetOriginalURI (perhaps we should be using NS_GetFinalChannelURI?) instead of GetURI here. We added the exception for resource:// in bug 1366180, but the use of GetURI instead of GetOriginalURI dates back to the code being added in 2001 (https://github.com/mozilla-firefox/firefox/commit/4a5272f5d6f22613a23630ebd85d998d41ef8848). GetOriginalURI did exist back then, but perhaps it was overlooked? I think we could perhaps always use GetOriginalURI/NS_GetFinalChannelURI here which could simplify things even more.

If we then also updated the webextension remoted channel implementation to preserve the content type, we could actually continue to support these prettified HTML rendered responses (which might be nice for webextension developer experience?), but perhaps that's not something we want to do (the HTML prettifier was deprecated for non-local sources in bug 1824325).

If we decided that extension loads should never display directory listings (either the pretty format or the raw text format we currently see), it would require deeper changes to how we load moz-extension:// URIs as currently those listings are directly served by file: (1) and jar: (1, 2) channels, which we redirect the extension channels to.

Flags: needinfo?(nika)

Another thing to potentially note here is the origin access issue. This is a "pretty" rendering of the listing being fetched but is being displayed with the principal of the resource being fetched (unlike how we display e.g. PDFs with PDF.js or JSON with the JSON viewer). This would be a much more substantial change (and perhaps not worth it), but we could perhaps theoretically change the HTML directory index renderer to force a unique principal which could also hide the contents from a snooping extension.

If we add a && !uri->SchemeIs("moz-extension") we could also get the proper moz-extension: path shown when the stream converter displays the HTML listing, which I believe would fix the original concern of leaking the raw JAR URI into the DOM:

Thanks, Nika! That's a great suggestion that ought to close this issue, and we can decide whether we want to support the nice dir listing for web-extensions in a follow-up.

but perhaps that's not something we want to do (the HTML prettifier was deprecated for non-local sources in bug 1824325).

I would consider web-extensions to be local sources. 🀷

Attached file (secure) β€”
Assignee: nobody → valentin.gosu
Status: NEW → ASSIGNED
Attached file (secure) β€”
Pushed by valentin.gosu@gmail.com: https://github.com/mozilla-firefox/firefox/commit/ce12fe1250a1 https://hg.mozilla.org/integration/autoland/rev/be77c18f9c7b Do not use the webext channel's real URL in nsIndexedToHTML r=robwu,necko-reviewers,sunil https://github.com/mozilla-firefox/firefox/commit/15d2393fd4d8 https://hg.mozilla.org/integration/autoland/rev/e11a7c2c4ab1 Test that webextension dir listing does not contain file or jar URLs r=robwu
Group: firefox-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 146 Branch
QA Whiteboard: [sec] [qa-triage-done-c147/b146]

Please nominate this for ESR140 approval.

Flags: needinfo?(valentin.gosu)
Flags: needinfo?(valentin.gosu)
Attached file (secure) β€”
Attachment #9527705 - Flags: approval-mozilla-esr140?

firefox-esr140 Uplift Approval Request

  • User impact if declined: Possible leak of OS username & salted profile directory when the extensions.webextensions.protocol.remote or extensions.webextensions.remote prefs are set to false.
  • Code covered by automated testing: yes
  • Fix verified in Nightly: yes
  • Needs manual QE test: yes
  • Steps to reproduce for manual QE testing: Set either of these prefs to false and load the root of a webextension (eg. Load the uBlock origin extension settings - should be something like moz-extension://4704050a-ec6c-4767-b22d-f1935d6fd8d5/dashboard.html - and remove the dashboard.html from the path)
    Check if the directory listing shows the full path on disk (ie the OS username)
  • Risk associated with taking this patch: low
  • Explanation of risk level: Already verified on Nightly. Fix is a simple if check that we already applied to resource URLs
  • String changes made/needed: none
  • Is Android affected?: yes
Attachment #9527706 - Flags: approval-mozilla-esr140?
Flags: qe-verify+
Attached file (secure) β€”
Attachment #9527705 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
Attachment #9527706 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
QA Contact: acornestean

Verified as Fixed. Tested on the latest Nightly (147.0a1/20251119215322), Beta (146.0b5/20251119090309) and ESR 140 (140.6.0esr/20251119190205 from https://treeherder.mozilla.org/jobs?repo=mozilla-esr140&revision=019319154723d1588fec503294d02cadc29f3fe7) under Windows 11 and Ubuntu 24.10 as per the STR from Comment 18.

Also tested on the latest Release (145.0.1/20251118022223) which does not contain the fix, for comparison.

With the fix, the directory listing does not show the full path on disk. It only shows Index of moz-extension://d498bb87-147b-49f9-a4d4-397127c25626/

On Release, without the fix, the directory listing shows something along the lines of Index of jar:file:///C:/Users/<<username>>/AppData/Roaming/Mozilla/Firefox/Profiles/rzailey5.<<salt>>/extensions/uBlock0@raymondhill.net.xpi!/

Status: RESOLVED → VERIFIED
Flags: qe-verify+
Whiteboard: [adv-main146-]
Whiteboard: [adv-main146-] → [adv-main146-][adv-esr140.6-]
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: