Closed Bug 2066030 Opened 2 months ago Closed 2 months ago

DOM: Content Processes: subframe can downgrade top-level page from HTTPS to HTTP via RecvReloadWithHttpsOnlyException

Categories

(Core :: DOM: Security, defect)

Firefox 156
defect

Tracking

()

RESOLVED DUPLICATE of bug 2014104

People

(Reporter: longkd719, Unassigned)

Details

Attachments

(1 file)

Attached file repro.py —

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:

  1. Reading the top-level page's URI
  2. Creating a session-scoped HTTPS-Only exception for that domain
  3. 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:

  1. User visits https://bank.com which embeds an iframe (ad, analytics, third-party widget).
  2. Compromised iframe content process calls SendReloadWithHttpsOnlyException().
  3. Handler reads BrowsingContext()->Top()->GetCurrentURI() = https://bank.com/login.
  4. Creates http://bank.com/login URI and adds https-only-load-insecure ALLOW_SESSION permission.
  5. Reloads the top-level page over HTTP using SystemPrincipal as triggering principal.
  6. Top-level page now loads over HTTP. Session cookies sent in cleartext. The session-scoped permission means bank.com stays 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.

Group: core-security
Status: UNCONFIRMED → RESOLVED
Closed: 2 months ago
Component: DOM: Content Processes → DOM: Security
Duplicate of bug: 2014104
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: