Closed Bug 2034938 Opened 7 months ago Closed 2 months ago

MV3 static content script executes on top-level about:blank with no granted host permissions

Categories

(WebExtensions :: General, defect)

defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: 0809android, Unassigned)

Details

(Keywords: reporter-external, Whiteboard: [client-bounty-form][deduped][nosec])

Attachments

(8 files)

Bugzilla Client Bounty Report

Title

MV3 static content script executes on top-level about:blank with no granted host permissions

Product / Component

Firefox :: WebExtensions: General

Summary

I found a Manifest V3 host-permission/origin-controls bypass for the top-level opaque about:blank special case.

The PoC extension uses:

  • manifest_version: 3
  • no host_permissions
  • a static content script with matches: ["*://*/*"]
  • match_about_blank: true
  • no activeTab permission

The PoC installs the extension as a normal non-temporary extension with Firefox MV3 origin controls enabled and extensions.originControls.grantByDefault=false. It verifies that ExtensionPermissions.get(addonId) returns empty origins and permissions, then opens a top-level about:blank document.

Even in that state, the static content script runs in the top-level about:blank page and sends browser.runtime.sendMessage() to the extension background script.

Security Impact

This weakens the MV3 host-permission/origin-controls boundary for top-level opaque about:blank.

The current PoC does not demonstrate full arbitrary-origin content-script injection into https:// pages and does not claim UXSS. The demonstrated boundary violation is narrower:

  • Firefox reports no granted host origins for the extension.
  • The extension does not have activeTab.
  • A static content script that should depend on an effective host grant still executes in a top-level opaque about:blank document.
  • The script can access and modify that document and communicate with the extension background script.
  • The same PoC does not execute on a normal local HTTP document when no host grant is present, which narrows the issue to the top-level opaque about:blank special case.

This matters because MV3 origin controls are supposed to let users revoke host access and because Firefox already fixed the general class “MV3 content scripts require granted host permissions” in Bug 1745819.

Suggested rating: sec-moderate candidate, potentially higher if Mozilla identifies sensitive top-level about:blank creator/opener cases that expose privileged or user-sensitive document state.

Reproduced On

  • Local mozilla-central source build
  • Revision: 5836a062726f715fda621338a17b51aff30d0a8c
  • Firefox/Nightly version: 142.0a1
  • Build ID: 20260425003130
  • Platform: macOS
  • Install mode: non-temporary extension install (temporaryInstall: false)

The same PoC shape was also previously reproduced on installed Firefox/Nightly builds, but the attached evidence is from the local source build above.

Steps To Reproduce

From a mozilla-central checkout:

./mach python security-pocs/mv3_about_blank_ungranted_host_permissions.py \
  --firefox obj-loadinfo-debug/dist/NightlyDebug.app/Contents/MacOS/firefox

The script:

  1. creates a temporary Firefox profile
  2. builds an MV3 extension XPI
  3. installs it as a normal non-temporary extension
  4. explicitly sets extensions.originControls.grantByDefault=false
  5. confirms that ExtensionPermissions.get(addonId) returns empty origins and permissions
  6. records WebExtensionPolicy.getByID(addonId) diagnostics, including allowedOrigins and canAccessURI(target)
  7. opens top-level about:blank
  8. checks whether the content script modified the DOM and whether the background script received its message

Expected Result

With no granted host permissions and no activeTab grant, the static MV3 content script should not run on top-level about:blank.

Actual Result

The static content script runs and reaches the background script.

Key evidence from one successful run. The attached PoC prints this JSON-shaped result when it reproduces the issue:

{
  "browserVersion": "142.0a1",
  "moz:buildID": "20260425003130",
  "temporaryInstall": false,
  "hostPermissionsBeforeRemoval": {
    "data_collection": [],
    "origins": [],
    "permissions": []
  },
  "hostPermissionsGranted": {
    "data_collection": [],
    "origins": [],
    "permissions": []
  },
  "policyAllowedOrigins": {
    "matchesAllWebUrls": false,
    "patterns": [
      "moz-extension://d7ac7424-cf5a-4b9f-a689-7ef0f8ca0a1e/*"
    ]
  },
  "policyDiagnostics": {
    "extension": {
      "grantedHostPermissions": false,
      "isPrivileged": false,
      "manifestVersion": 3,
      "originControls": true,
      "temporarilyInstalled": false
    },
    "policy": {
      "allowedOriginsMatchesAll": false,
      "canAccessTarget": false
    },
    "prefGrantByDefault": false
  },
  "contentScriptExecuted": true,
  "messageObserved": true,
  "contentDomMarker": "{\"href\":\"about:blank\",\"origin\":\"null\",\"readyState\":\"loading\",\"topLevel\":true,\"timestamp\":1777049411944}"
}

The PoC output also includes the extension result tabs opened by the background script after receiving the content-script message.

Root Cause Analysis

The relevant C++ matching path appears to be MozDocumentMatcher::Matches in toolkit/components/extensions/WebExtensionPolicy.cpp.

For a top-level opaque about:blank, the matcher has a special case that can return true when:

  • match_about_blank is set
  • activeTab is present, or
  • the script match pattern covers all web URLs and there are no include globs

The important distinction is that this special case is not equivalent to the normal MatchesURI() path. Normal MV3 content-script matching goes through the permission-aware URI check:

if (mCheckPermissions && !aIgnorePermissions &&
    !mExtension->CanAccessURI(aURL, false, false, true)) {
  return false;
}

In the reproduced state, ExtensionPermissions.get(addonId) is empty and WebExtensionPolicy.allowedOrigins only contains the extension's own moz-extension://.../* origin. The PoC also records policy.canAccessURI(about:blank) == false.

Despite that, MozDocumentMatcher::Matches() returns true for top-level opaque about:blank before reaching MatchesURI():

if (mMatchAboutBlank && aDoc.IsTopLevelOpaqueAboutBlank()) {
  if (mHasActiveTabPermission) {
    return true;
  }
  if (mMatches->MatchesAllWebUrls() && mIncludeGlobs.IsNull()) {
    return true;
  }
}

So the suspected root cause is:

  1. MV3 static content-script match patterns are broad enough for mMatches->MatchesAllWebUrls() to be true.
  2. The user/effective granted host permission state can still be empty.
  3. The top-level opaque about:blank special case accepts the requested match pattern itself, before the permission-aware MatchesURI() path.
  4. The content script executes despite no granted host permissions, no activeTab, and policy.canAccessURI(target) == false.

Relevant Code

  • toolkit/components/extensions/WebExtensionPolicy.cpp
    • MozDocumentMatcher::Matches
    • top-level opaque about:blank special case
    • MozDocumentMatcher::MatchesURI
  • toolkit/components/extensions/Extension.sys.mjs
    • MV3 origin-controls startup/install handling
    • manifest content-script origins added to extension permission state/policy state
  • toolkit/components/extensions/ExtensionPermissions.sys.mjs
    • persisted/effective extension permission storage queried by the PoC
  • toolkit/components/extensions/test/mochitest/test_ext_contentscript_about_blank.html
    • existing top-level about:blank content-script coverage

Related Bugs Checked

Public Bugzilla searches found related issues, but I did not find a public duplicate for this exact condition.

  • Bug 1745819: “Require granted host permission for content scripts in mv3”. This fixed the general requirement that MV3 content scripts need granted host permissions.
  • Bug 1745818: “Treat host permissions as optional in MV3 manifest”. This established the MV3 optional-host-permission model.
  • Bug 1889402: “Grant origin permissions during install for mv3”. This changed install-time granting behavior, while still documenting that authors must handle revoked host permissions.
  • Bug 1272890: “Support match_about_blank in content scripts”. This is the older feature support for match_about_blank.
  • Bug 1901894: “Unexpected content script execution in initial about:blank in parent process when extensions.webextensions.remote=false”. This is close because it also involved top-level opaque about:blank, but it fixed injection into initial/background-browser about:blank while preserving the original top-level about:blank support. This report is specifically about MV3 origin-controls/host-grant enforcement for that preserved special case.
  • Bug 1766752: documents that static content script execution in MV3 requires approved manifest permissions; this report shows the top-level opaque about:blank branch still bypasses that check.

The attached PoC is different because it explicitly verifies that the effective extension permission store is empty before opening top-level about:blank, while the content script still executes.

Suggested Fix Direction

The top-level opaque about:blank special case should require one of:

  • a valid activeTab grant, or
  • an effective MV3 granted-origin decision equivalent to the normal content-script host-permission check, or
  • an explicit helper that answers “does this extension currently have granted all-web-url access?” without conflating requested/static content-script patterns with granted origins.

Regression coverage should install an MV3 extension with:

  • content_scripts.matches: ["*://*/*"]
  • match_about_blank: true
  • no activeTab
  • no effective granted host permissions

Then it should open top-level about:blank and assert that the content script does not run.

Attachments

  • mv3_about_blank_ungranted_host_permissions.py: standalone local PoC. It generates the MV3 test extension, runs Firefox with a temporary profile, verifies the effective permission state, opens the target document, and prints the reproduction result as JSON.

Disclosure

I have not publicly disclosed this issue. I am submitting it privately for Mozilla Client Bug Bounty consideration.

Flags: sec-bounty?

Attaching a proposed mozilla-central patch with a matcher fix and two regression tests.

The patch does three things:

  1. delays the top-level opaque about:blank early return until after the usual permission checks,
  2. requires effective all-web-url access for the broad MV3 about:blank case when there is no activeTab grant,
  3. adds regression coverage at both the mochitest and xpcshell matcher levels.

I am attaching it separately as mozilla-central-fix-and-regression-tests.diff.

Short triage note: the fastest reproducer is the attached Python PoC plus result.json. It verifies that the extension has no granted origins, opens top-level about:blank, and still observes content-script execution and browser.runtime.sendMessage(). The negative local HTTP control stays non-executing under the same no-grant state. The patch attachment is a draft fix direction, not a tested landed changeset.

Adding a follow-up evidence package for the top-level data: variant. This appears to be the same opaque-document root cause as this bug, with duplicate risk around Bug 1902635, so I am attaching it here rather than filing separately.

Component: Security → Untriaged
Product: Firefox → WebExtensions

In short, this is intentional (but not explicitly documented).

For clarity, this bug report is about content script in documents matching the following very narrow definition:

  • is top level
  • is about:blank (or data: until bug 1902635 is closed).
  • has an opaque origin (i.e. not about:blank opened by a regular web page)

These documents have no special privileges or capabilities. The ability for extensions to inject there is intentional, and relevant bugs are here:

  • bug 1272890 describing scenario that is intended to be supported (executeScript working in a newly created blank tab)
  • bug 1310331 implements the first sign of the logic that allows injection in opaque about:blank documents (source diff).
  • ( bug 1317697: refactor without behavioral change, moved logic elsewhere (source diff)
  • bug 1368102 moved the logic to C++ (source diff)
  • bug 1853409 added more conditions before accepting about:blank matches for functional (non-security) reasons (source diff)

While it seems strange for extensions to be permitted injection without any host permissions, it is necessary to support that if we want to maintain support for executeScript in newly created tabs (as described by bug 1272890). These newly created tabs have an opaque origin.

In theory, we could narrow the definition further, to exclude null principals that have a precursor. That would exclude about:blank popups created by sandboxed web pages. I didn't see a point to implement that edge case in bug 1853409, and still do not see that now.

If anything, perhaps we could add a unit test that verifies that the scenario written here continues to work as intended.

Component: Untriaged → General

(In reply to Rob Wu [:robwu] from comment #10)

In short, this is intentional (but not explicitly documented).

Thanks for the detailed explanation.

Should this be resolved INVALID?

Flags: needinfo?(rob)

(In reply to :Gijs (he/him) from comment #11)

(In reply to Rob Wu [:robwu] from comment #10)

In short, this is intentional (but not explicitly documented).

Thanks for the detailed explanation.

Should this be resolved INVALID?

I think so, yes. I asked another team member to confirm before we close (and open up?) this report.

Flags: needinfo?(rob) → needinfo?(tomica)
Whiteboard: [client-bounty-form] → [client-bounty-form][deduped]
Whiteboard: [client-bounty-form][deduped] → [client-bounty-form][deduped][nosec]
Flags: sec-bounty? → sec-bounty-
Status: UNCONFIRMED → RESOLVED
Closed: 2 months ago
Resolution: --- → INVALID
Group: firefox-core-security
Flags: needinfo?(tomica)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: