Fragment navigation may change document URI scheme from https to http
Categories
(Core :: DOM: Security, defect, P2)
Tracking
()
People
(Reporter: aiunusov, Assigned: tschuster)
References
(Blocks 1 open bug)
Details
(Keywords: sec-other, Whiteboard: [domsecurity-active][post-critsmash-triage][adv-main114-])
Attachments
(1 file)
Reproduction steps:
- dom.security.https_first = true
- page already loaded using https
- during fragment navigation, so navigation within the page itself, changes its url to http (https://searchfox.org/mozilla-central/rev/a3c18883ef9875ba4bb0cc2e7d6ba5a198aaf9bd/dom/security/test/https-first/test_fragment.html#29)
this makes "secure" pages look like they aren't secure
Updated•3 years ago
|
Comment 1•3 years ago
|
||
This looks fun, but not like a security issue as per our client severity ratings.
Am I wrong or are you overly cautious?
Updated•3 years ago
|
Comment 2•3 years ago
|
||
Yeah, possibly not a security bug, but blocks a security bug.
| Reporter | ||
Comment 3•3 years ago
|
||
found this bug during working on Bug 1783504, where we stumbled upon that case:
RecvUpdateDocumentURI:
aURI='http://example.com/tests/dom/security/test/https-first/file_fragment.html#foo',
principal URI='https://example.com/tests/dom/security/test/https-first/file_fragment.html'
Comment 4•3 years ago
•
|
||
I couldn't reproduce the issue in the "wild".
But reproduced it with the linked test file.
I think the problem occurs in the fragment test because of that line.
AFAIK fragmentation navigations don't lead to page (re-)loads. That is probably the bug here since http:// is the hardcoded scheme of the button location.
As the author of that test case I am sorry for bad practice (that is a copy paste of my first test I wrote for firefox :D ), unsure if that is not a very unlikely case for the "wild".
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 5•3 years ago
•
|
||
I think it could be patched by implementing in the URI check for fragment navigations a URI modifier like: https://searchfox.org/mozilla-central/source/dom/security/nsHTTPSOnlyUtils.cpp#751,779-795.
Something that looks like:
// If we entered here the current scheme is https (upgraded by
// HTTPS-Only/-First mode) and the navigation is a fragment
// navigation. For that reason we should navigate from https to
// https.
nsCOMPtr<nsIURI> newHTTPSFragNavURI;
// Port should be set to the port value of the source (URI's port that we are navigating from)
rv = NS_MutateURI(oldHTTPFragNavURI)
.SetScheme("https"_ns)
.SetPort(port)
.Finalize(newHTTPSSchemeURI);
NS_ENSURE_SUCCESS(rv, false);
aLoadState->SetURI(newHTTPSFragNavURI);
I already tested it and it seems to work.
@smaug: I would like to add something similar to the code snippet from above as an helper function to nsHTTPSOnlyUtils.cpp and call it in nsDocShell.cpp. What are you thinking about that?
Comment 6•3 years ago
|
||
I was thinking something like that needs to happen. We have to change the scheme in the to-be-loaded url.
If it is nsDocShell::IsSameDocumentNavigation which ends up modifying the URL, better to add some good comment to the .h explaining the behavior.
Test will need to ensure document.documentURI and location.href are updated properly. And I guess it would be good to test that also the URI sent to the parent process is correct https://searchfox.org/mozilla-central/rev/17aeb39742eba71e0936ae44a51a54197100166d/dom/chrome-webidl/WindowGlobalActors.webidl#96
Comment 7•3 years ago
|
||
Updated•3 years ago
|
Comment 8•3 years ago
|
||
Fragment navigation may change document URI scheme from https to http r=smaug
https://hg.mozilla.org/integration/autoland/rev/30d7636620f835c7aa3d3fc07508fbd8d72de8b0
https://hg.mozilla.org/mozilla-central/rev/30d7636620f8
Updated•3 years ago
|
Updated•3 years ago
|
Comment 9•3 years ago
|
||
Backed out as requested by smaug
Backout link: https://hg.mozilla.org/integration/autoland/rev/4f2f6e92ee47a3e61122563a4e0eee07bb759d08
Comment 10•3 years ago
|
||
Backout merged to central: https://hg.mozilla.org/mozilla-central/rev/4f2f6e92ee47
Updated•3 years ago
|
Comment 11•3 years ago
|
||
There's a r+ patch which didn't land and no activity in this bug for 2 weeks.
:lyavor, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit auto_nag documentation.
Comment 12•3 years ago
|
||
Tomer, I guess we need to figure out how to avoid that sync IPC. Someone more familiar with http->https setup might have suggestions.
Comment 13•3 years ago
|
||
Okay, thank you!
I will try to find someone or do you have someone in mind?
Comment 14•3 years ago
|
||
Do I correctly understand that calling NS_GetSecureUpgradedURI() from DocShell is causing synchronous IPC to the network process?
I wonder how we usually deal with utility functions that should be available cross process. This one in particular does not seem very process-specific to me..
Comment 15•3 years ago
|
||
No, I think smaug meant this part in the patch:
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
cc->SendIsSecureURI(currentURI, attrsForHSTS, &isStsHost);
Which is needed to check if the request has a HSTS header.
| Assignee | ||
Updated•3 years ago
|
Comment 16•3 years ago
|
||
Fragment navigation may change document URI scheme from https to http r=ckerschb
https://hg.mozilla.org/integration/autoland/rev/bb1f3463f21d75a3d72dfe29b791935f28e289a3
https://hg.mozilla.org/mozilla-central/rev/bb1f3463f21d
Updated•3 years ago
|
Comment 17•3 years ago
|
||
The patch landed in nightly and beta is affected.
:tschuster, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta approval.Also, don't forget to request an uplift for the patches in the regression caused by this fix.
- If no, please set
status-firefox112towontfix.
For more information, please visit auto_nag documentation.
| Assignee | ||
Updated•3 years ago
|
| Assignee | ||
Comment 18•3 years ago
|
||
Let's backout.
| Assignee | ||
Comment 19•3 years ago
|
||
I am not sure what to do here. Seems like just modifying the URL is not the way to go.
| Assignee | ||
Updated•3 years ago
|
Comment 20•3 years ago
|
||
Backed out for causing Bug 1823765 a=backout
https://hg.mozilla.org/mozilla-central/rev/b917c4511ec4
Comment 21•3 years ago
|
||
The error here is caused by the load validation which we do on nsDocShellLoadState to ensure that the content process does not tamper with the URI being loaded. You're re-writing the LoadState's URI within the content process in your case, so if the navigation ends up actually creating a real DocumentChannel (as it does in bug 1823765), it'll send the new URI to the parent process, which will be different than the original one.
Perhaps instead of changing the URI in the current place, where other decisions might make it not actually be a same-document navigation, record that the URI needs to have it's scheme changed in the SameDocumentNavigationState object. You can then do the change to the URI before it is used in HandleSameDocumentNavigation (https://searchfox.org/mozilla-central/rev/dd2fe65d792943365a03fa996cdf9766829575b6/docshell/base/nsDocShell.cpp#8865), which will ensure that it's not going to be used to create a channel (which should be done with the original URI anyway so that necko can upgrade it).
Adding a flag like mShouldSecureUpgradeURI to SameDocumentNavigationState, and changing all calls to aLoadState->URI() to instead happen on a local copy of the URI which is upgraded if mShouldSecureUpgradeURI is set.
| Assignee | ||
Comment 22•3 years ago
|
||
Thank you Nika! I am investigating this new approach you suggested.
| Assignee | ||
Comment 23•3 years ago
|
||
That seems to work fine, but do you have an idea what condition would reproduce the crashes? Something involving redirect GetPendingRedirectedChannel ?
Updated•3 years ago
|
Updated•3 years ago
|
| Assignee | ||
Comment 24•3 years ago
|
||
Fragment navigation may change document URI scheme from https to http. r=ckerschb,nika,smaug
https://hg.mozilla.org/integration/autoland/rev/d841063b73d7d850d864f72123420931c602b9ee
https://hg.mozilla.org/mozilla-central/rev/d841063b73d7d850d864f72123420931c602b9ee
| Assignee | ||
Updated•3 years ago
|
Updated•3 years ago
|
Comment 25•3 years ago
|
||
Looks like the crashes have stayed away this time. Is this something we were thinking about backporting or can it ride the trains?
| Assignee | ||
Comment 26•3 years ago
|
||
I think this can ride the trains. However as I understand it, this patch is required for bug 1783504, so we might uplift both of them if that get finished soon.
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•2 years ago
|
Description
•