Closed Bug 2054692 Opened 4 months ago Closed 4 months ago

Missing parent-side validation in WindowGlobalParent::RecvReloadWithHttpsOnlyException lets a compromised content process disable HTTPS-Only/HTTPS-First for the top-level site and force a system-principal http reload

Categories

(Core :: DOM: Content Processes, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 2014104

People

(Reporter: bugmon, Unassigned)

Details

(5 keywords)

Attachments

(5 files)

The PWindowGlobal::ReloadWithHttpsOnlyException IPC message is intended to be sent only by the trusted about:httpsonlyerror error page when the user clicks the top-level-only 'Continue to HTTP Site' button. However, every protection in that flow — the [Func="Document::CallerIsTrustedAboutHttpsOnlyError"] WebIDL gate, the top-level-only button, and the clickjacking delay in toolkit/components/httpsonlyerror/content/errorpage.js — is enforced exclusively inside the (attacker-controllable) content process. The parent-side handler WindowGlobalParent::RecvReloadWithHttpsOnlyException (dom/ipc/WindowGlobalParent.cpp:1665) accepts the message from ANY WindowGlobal actor with no validation: it does not check that the sender is the top window global, that the sending document is the trusted error page, that user activation occurred, or that HTTPS-Only/HTTPS-First mode is even active for that load.

On receipt, the handler unconditionally mints the session-scoped 'https-only-load-insecure' permission (LOAD_INSECURE_ALLOW_SESSION) for the principal of the TOP-LEVEL site of the sender's browsing context tree and force-reloads the top browsing context over plain http using the SYSTEM triggering principal (LOAD_NORMAL_REPLACE). Consequently, a compromised content process that hosts only a cross-origin subframe (e.g. an ad iframe, which under Fission runs in a different process than the victim top document) can, with a single IPC message, disable HTTPS-Only enforcement for the victim's top-level site for the entire session and downgrade the currently-viewed page to plain http. Because nsHTTPSOnlyUtils::TestIfPrincipalIsExempt honors LOAD_INSECURE_ALLOW_SESSION for both HTTPS-Only and HTTPS-First upgrade modes, the primitive also neutralizes default-on HTTPS-First upgrades. This was verified end-to-end: on a fresh unpatched-parent ASAN build, a cross-origin iframe running in a separate content process (simulated compromised process via a minimal child-side-only pref hook) sent the message, the parent minted the exemption and force-reloaded the victim top-level page, and a fetch to an HTTPS-Only-protected host that was blocked before the attack succeeded over plain http afterwards ('Not upgrading insecure request ... because it is exempt').

Build Info

Affected Code

File: dom/ipc/WindowGlobalParent.cpp, line 1665-1739

mozilla::ipc::IPCResult WindowGlobalParent::RecvReloadWithHttpsOnlyException() {
  nsresult rv;
  // No check that `this` is the top WindowGlobal of the BC tree.
  // No check that the sending document is about:httpsonlyerror.
  // No user-activation check. No check HTTPS-Only/First is enabled.
  nsCOMPtr<nsIURI> currentURI = BrowsingContext()->Top()->GetCurrentURI();
  ...
  nsCOMPtr<nsIURI> newURI;
  (void)NS_MutateURI(innerURI).SetScheme("http"_ns).Finalize(
      getter_AddRefs(newURI));
  ...
  nsCOMPtr<nsIPrincipal> principal =
      BasePrincipal::CreateContentPrincipal(newURI, originAttributes);

  rv = permMgr->AddFromPrincipal(
      principal, "https-only-load-insecure"_ns,
      nsIHttpsOnlyModePermission::LOAD_INSECURE_ALLOW_SESSION,
      nsIPermissionManager::EXPIRE_SESSION, 0);   // <-- exemption minted for the TOP-LEVEL site on behalf of ANY frame's actor
  ...
  RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(insecureURI);
  loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal()); // <-- system triggering principal
  loadState->SetLoadType(LOAD_NORMAL_REPLACE);
  ...
  RefPtr<CanonicalBrowsingContext> topBC = BrowsingContext()->Top();
  topBC->LoadURI(loadState, /* setNavigating */ true);   // <-- forced top-level http reload

  return IPC_OK();
}

File: dom/webidl/Document.webidl, line 336-337

// The ONLY gate on the message-sending API is evaluated inside the
// (attacker-controlled) content process:
[Func="Document::CallerIsTrustedAboutHttpsOnlyError"]
undefined reloadWithHttpsOnlyException();

File: dom/base/Document.cpp, line 1552-1556

void Document::ReloadWithHttpsOnlyException() {
  if (WindowGlobalChild* wgc = GetWindowGlobalChild()) {
    wgc->SendReloadWithHttpsOnlyException();  // any compromised child can send this directly on any of its PWindowGlobal actors
  }
}

File: netwerk/protocol/http/nsHTTPSOnlyUtils.cpp, line 691-712

bool nsHTTPSOnlyUtils::TestIfPrincipalIsExempt(nsIPrincipal* aPrincipal,
                                               UpgradeMode aUpgradeMode) {
  ...
  rv = sPermMgr->TestExactPermissionFromPrincipal(
      aPrincipal, "https-only-load-insecure"_ns, &perm);
  ...
  return perm == nsIHttpsOnlyModePermission::LOAD_INSECURE_ALLOW ||
         perm == nsIHttpsOnlyModePermission::LOAD_INSECURE_ALLOW_SESSION || // <-- minted value exempts BOTH HTTPS-Only and default-on HTTPS-First
         (checkForHTTPSFirst &&
          perm == nsIHttpsOnlyModePermission::HTTPSFIRST_LOAD_INSECURE_ALLOW);
}

The parent-side IPC handler trusts the sender completely. It derives everything from the top of the sender's browsing context tree, mints the HTTPS-Only exemption permission, and issues a system-principal top-level load — with no check that the sending WindowGlobal is the top window, that it is the trusted about:httpsonlyerror page, or that any user interaction occurred. All of those checks exist only in content-process code (the WebIDL Func gate and errorpage.js), which a compromised content process bypasses trivially.

Exploit Chain

  1. Attacker compromises a content process via a renderer bug (e.g. the process hosting a cross-origin ad iframe embedded in a victim HTTPS-Only-protected page; under Fission this is a different process than the victim top document).
  2. From the compromised process, the attacker sends PWindowGlobal::ReloadWithHttpsOnlyException on any of its WindowGlobal actors (equivalent to calling WindowGlobalChild::SendReloadWithHttpsOnlyException; the only guard is the child-side WebIDL Func check, which the attacker controls).
  3. The pristine parent-side handler WindowGlobalParent::RecvReloadWithHttpsOnlyException accepts the message without any sender validation, resolves the TOP-LEVEL browsing context of the tab, and rewrites its current URI to scheme http.
  4. The parent mints the session-scoped 'https-only-load-insecure' permission (LOAD_INSECURE_ALLOW_SESSION) for the top-level site's principal via PermissionManager::AddFromPrincipal.
  5. The parent force-reloads the top browsing context over plain http with the SYSTEM triggering principal (LOAD_NORMAL_REPLACE), replacing the victim's page with its http version without any user interaction.
  6. All subsequent loads for that site during the session are exempt from HTTPS-Only and HTTPS-First upgrades (nsHTTPSOnlyUtils::TestIfPrincipalIsExempt), giving an on-path network attacker a session-wide TLS-downgrade / content-injection primitive against the victim's currently-viewed top-level site.

IPC Path

  • PWindowGlobal
    • Protocol: PWindowGlobal
    • Parent process: Main
    • Child process: Content
    • Message flow: Content (compromised cross-origin iframe process) -> Main: ReloadWithHttpsOnlyException()

Steps to Reproduce

  1. Start from a clean Firefox checkout (verify with git -C /firefox diff).
  2. Apply the provided child-side-only simulation patch: git apply simulate-compromised-child.patch (adds a pref-gated bypass of the child-evaluated WebIDL gate Document::CallerIsTrustedAboutHttpsOnlyError so an ordinary page can emit the same IPC a compromised content process would send directly; the parent side of the boundary under test is unmodified).
  3. Build with the ASAN fuzzing mozconfig via build_firefox (mozconfig.linux.asan.fuzzing).
  4. Run testcase.html through browser_evaluator with prefs: dom.security.https_only_mode=true, network.dns.localDomains="victim.example", test.simulate-compromised-child.https-only-exception=true, browser.dom.window.dump.enabled=true, network.proxy.type=0, browser.tabs.remote.useCrossOriginEmbedderPolicy=false (the last two neutralize harness artifacts: proxying and the grizzly server's unconditional COEP: require-corp header).
  5. Observe the log sequence: PRE-ATTACK probe of http://victim.example => BLOCKED-BY-HTTPS-ONLY(TypeError); the cross-origin iframe (http://127.0.0.1, separate content process) sends the IPC; the top-level page is force-reloaded (phase 2); 'HTTPS-Only Mode: Not upgrading insecure request ... because it is exempt'; POST-ATTACK probe => ALLOWED-OVER-HTTP(responseType=opaque); '[HOE] VULNERABILITY CONFIRMED'.
  6. Negative control: run the identical testcase and prefs on the unpatched build — the iframe's document.reloadWithHttpsOnlyException is undefined, no reload occurs, and HTTPS-Only remains enforced, proving the parent-side handler is reachable only via the (child-side-only) gate and that the prefs alone cause no effect.
  7. Restore the tree with git -C /firefox checkout ..

Security Impact

  • Severity: Moderate
  • Attacker capability: A compromised content process — including one that only hosts a cross-origin subframe of the victim tab — can, with a single unvalidated IPC message: (1) mint the session-scoped 'https-only-load-insecure' exemption for the victim's top-level site, disabling HTTPS-Only and HTTPS-First upgrade enforcement for that site for the whole session; and (2) force-reload the victim's top-level page over plain http with the system triggering principal and no user interaction. Combined with an on-path network attacker, this yields session-wide TLS downgrade and active content injection into the victim's currently-viewed top-level site, defeating the user-consent, top-level-only, and anti-clickjacking protections of the HTTPS-Only error page. The forced load URI is derived from the current top-level URI (scheme swapped to http), so it is not an arbitrary system-principal navigation primitive.
  • Preconditions: Attacker must first fully compromise a content process (renderer RCE) that hosts any frame of the target tab. Realizing the downgrade's full impact additionally requires an active network (MITM) position. HTTPS-Only mode (dom.security.https_only_mode) is non-default, but the minted permission also exempts default-on HTTPS-First upgrades.

ASAN Report

No memory-safety crash is claimed or expected — this is a logic/privilege-violation finding proven by observable effect. Verified evaluator log (fresh ASAN build, unmodified parent, child-side simulation patch only):

[Child 15262: Main Thread]: I/console log: "[HOE] top document loaded, phase=1, url=http://localhost:43897/testcase.html"
[Child 15262: Main Thread]: W/PageMessages [JavaScript Warning: "HTTPS-Only Mode: Upgrading insecure request \"http://victim.example:43897/testcase.html?probe=...\" to use \"https\"."]
[Child 15262: Main Thread]: I/console log: "[HOE] PRE-ATTACK probe of http://victim.example:43897 => BLOCKED-BY-HTTPS-ONLY(TypeError)"
[Child 15262: Main Thread]: I/console log: "[HOE] injecting cross-origin attacker iframe (http://127.0.0.1:43897)"
[Child 15305: Main Thread]: I/console log: "[HOE] evil iframe loaded, origin=http://127.0.0.1:43897, reloadWithHttpsOnlyException is function"
[Child 15305: Main Thread]: I/console log: "[HOE] evil iframe sending PWindowGlobal::ReloadWithHttpsOnlyException targeting top-level site of top origin (cross-origin from us)"
[Child 15262: Main Thread]: I/console log: "[HOE] top document loaded, phase=2, url=http://localhost:43897/testcase.html"
[Child 15262: Main Thread]: I/console log: "[HOE] TOP-LEVEL PAGE WAS FORCE-RELOADED by the iframe's IPC message (system-principal LoadURI issued by WindowGlobalParent::RecvReloadWithHttpsOnlyException)"
[Child 15262: Main Thread]: I/PageMessages [JavaScript Error: "HTTPS-Only Mode: Not upgrading insecure request \"http://victim.example:43897/testcase.html?probe=...\" because it is exempt."]
[Child 15262: Main Thread]: I/console log: "[HOE] POST-ATTACK probe of http://victim.example:43897 => ALLOWED-OVER-HTTP(responseType=opaque)"
[Child 15262: Main Thread]: I/console log: "[HOE] pre=BLOCKED-BY-HTTPS-ONLY(TypeError) post=ALLOWED-OVER-HTTP(responseType=opaque)"
[Child 15262: Main Thread]: I/console log: "[HOE] VULNERABILITY CONFIRMED: a cross-origin iframe's process minted the session-scoped 'https-only-load-insecure' permission for the top-level site and force-reloaded the top-level page over plain http. HTTPS-Only enforcement for this site is now disabled for the whole session."

Negative control on the pristine build (same prefs): "reloadWithHttpsOnlyException is undefined", "TypeError: document.reloadWithHttpsOnlyException is not a function", no forced reload, HTTPS-Only enforcement unchanged.
Attached file testcase.html —
Attached file prefs.json —
Attached file crash_stack.txt —
Attached file prefs.js —
Group: core-security → dom-core-security
Severity: -- → S3
Status: UNCONFIRMED → RESOLVED
Closed: 4 months ago
Duplicate of bug: 2014104
Resolution: --- → DUPLICATE
Group: dom-core-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: