WebExtension directory listing shows local file:-URL
Categories
(WebExtensions :: General, defect, P3)
Tracking
(firefox-esr115 wontfix, firefox-esr140146+ 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)
|
803 bytes,
application/zip
|
Details |
| Reporter | ||
Updated•8 years ago
|
| Reporter | ||
Comment 1•8 years ago
|
||
Comment 2•8 years ago
|
||
Comment 3•8 years ago
|
||
| Reporter | ||
Comment 4•8 years ago
|
||
| Reporter | ||
Comment 5•8 years ago
|
||
Updated•8 years ago
|
Updated•8 years ago
|
Updated•7 years ago
|
Updated•6 years ago
|
Comment 6•5 years ago
|
||
re-triaged, leaving at same prio/sev
Comment 7•1 year ago
|
||
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?
Updated•1 year ago
|
| Assignee | ||
Comment 8•1 year ago
|
||
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::SerializeRedirectDatadoes 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.
Comment 9•1 year ago
|
||
(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 usingNS_GetFinalChannelURI?) instead ofGetURIhere. We added the exception forresource://in bug 1366180, but the use ofGetURIinstead ofGetOriginalURIdates back to the code being added in 2001 (https://github.com/mozilla-firefox/firefox/commit/4a5272f5d6f22613a23630ebd85d998d41ef8848).GetOriginalURIdid exist back then, but perhaps it was overlooked? I think we could perhaps always useGetOriginalURI/NS_GetFinalChannelURIhere 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.
Comment 10•1 year ago
|
||
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.
| Assignee | ||
Comment 11•1 year ago
|
||
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. π€·
| Assignee | ||
Comment 12•1 year ago
|
||
Updated•1 year ago
|
| Assignee | ||
Comment 13•1 year ago
|
||
Comment 14•1 year ago
|
||
Comment 15•1 year ago
|
||
https://hg.mozilla.org/mozilla-central/rev/be77c18f9c7b
https://hg.mozilla.org/mozilla-central/rev/e11a7c2c4ab1
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 17•1 year ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D268356
Updated•1 year ago
|
Comment 18•1 year ago
|
||
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
| Assignee | ||
Comment 19•1 year ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D268357
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Comment 20•1 year ago
|
||
| uplift | ||
Updated•1 year ago
|
Comment 21•1 year ago
|
||
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!/
Updated•1 year ago
|
Updated•1 year ago
|
Updated•6 months ago
|
Description
•