DOM: Content Processes: subframe can downgrade top-level page from HTTPS to HTTP via RecvReloadWithHttpsOnlyException
Categories
(Core :: DOM: Security, defect)
Tracking
()
People
(Reporter: longkd719, Unassigned)
Details
Attachments
(1 file)
|
444 bytes,
text/x-python
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Steps to reproduce:
Audited WindowGlobalParent::RecvReloadWithHttpsOnlyException in dom/ipc/WindowGlobalParent.cpp:1739. This IPC handler is intended for the HTTPS-Only error page's "Continue to HTTP Site" button, which only appears in a top-level context. But any WindowGlobalChild can send PWindowGlobal::ReloadWithHttpsOnlyException (dom/ipc/PWindowGlobal.ipdl:235), including subframes.
The handler does not check whether the caller is the top-level WindowGlobal before:
- Reading the top-level page's URI
- Creating a session-scoped HTTPS-Only exception for that domain
- Reloading the top-level page over HTTP with SystemPrincipal
Code path:
// dom/ipc/WindowGlobalParent.cpp:1739
mozilla::ipc::IPCResult WindowGlobalParent::RecvReloadWithHttpsOnlyException() {
nsresult rv;
nsCOMPtr<nsIURI> currentURI = BrowsingContext()->Top()->GetCurrentURI();
// ^^ reads the TOP-LEVEL page's URI, not the caller's
// ... (scheme validation) ...
nsCOMPtr<nsIURI> newURI;
(void)NS_MutateURI(innerURI).SetScheme("http"_ns).Finalize(
getter_AddRefs(newURI));
OriginAttributes originAttributes =
TopWindowContext()->DocumentPrincipal()->OriginAttributesRef();
// ^^ no null check, no identity check — TopWindowContext() != this for subframes
// ... creates content principal from the http:// URI ...
rv = permMgr->AddFromPrincipal(
principal, "https-only-load-insecure"_ns,
nsIHttpsOnlyModePermission::LOAD_INSECURE_ALLOW_SESSION,
nsIPermissionManager::EXPIRE_SESSION, 0);
// ^^ session-scoped exception: domain loads over HTTP until browser closes
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(insecureURI);
loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
// ^^ SystemPrincipal-privileged reload
RefPtr<CanonicalBrowsingContext> topBC = BrowsingContext()->Top();
topBC->LoadURI(loadState, /* setNavigating */ true);
// ^^ navigates the top-level browsing context to the HTTP version
return IPC_OK();
}
Attack scenario:
- User visits
https://bank.comwhich embeds an iframe (ad, analytics, third-party widget). - Compromised iframe content process calls
SendReloadWithHttpsOnlyException(). - Handler reads
BrowsingContext()->Top()->GetCurrentURI()=https://bank.com/login. - Creates
http://bank.com/loginURI and addshttps-only-load-insecureALLOW_SESSION permission. - Reloads the top-level page over HTTP using SystemPrincipal as triggering principal.
- Top-level page now loads over HTTP. Session cookies sent in cleartext. The session-scoped permission means
bank.comstays on HTTP until the browser is closed.
Actual results:
The handler has no caller identity check. Any WindowGlobalChild — including one belonging to a subframe in a different content process — can invoke this message and force the top-level page to downgrade from HTTPS to HTTP. The HTTPS-Only exception persists for the entire browser session (EXPIRE_SESSION).
The downgrade is silent: no user interaction is required, no prompt is shown, and the reload appears as a normal page refresh. Combined with a network attacker position (e.g., on the same WiFi network), the HTTP reload exposes session cookies and page content to interception.
Expected results:
The handler should verify that the calling WindowGlobalParent is the top-level window context before proceeding. The same file already uses the TopWindowContext() == this assertion in other handlers — for example at line 2061:
// dom/ipc/WindowGlobalParent.cpp:2061
void WindowGlobalParent::AddSecurityState(uint32_t aStateFlags) {
MOZ_ASSERT(TopWindowContext() == this);
The fix:
// dom/ipc/WindowGlobalParent.cpp:1739
mozilla::ipc::IPCResult WindowGlobalParent::RecvReloadWithHttpsOnlyException() {
if (this != TopWindowContext()) {
return IPC_FAIL(this,
"HTTPS-only mode: only the top-level window can add exceptions");
}
// ... rest of the handler unchanged ...
}
Additionally, RecvGetStorageAccessPermission at line 1818 already follows the defensive pattern of null-checking TopWindowContext() and returning IPC_FAIL_NO_REASON:
// dom/ipc/WindowGlobalParent.cpp:1818
WindowGlobalParent* top = TopWindowContext();
if (!top) {
return IPC_FAIL_NO_REASON(this);
}
RecvReloadWithHttpsOnlyException dereferences TopWindowContext() at line 1768 without a null check — an inconsistency with the rest of the file.
Updated•2 months ago
|
Description
•