Skip to content

Add proposal for topFrameMatches and excludeTopFrameMatches #802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

polywock
Copy link

Related issue: #763

API proposal to allow content script registration (both static and dynamic) to be restricted based on the origin of the top-level frame.
@polywock
Copy link
Author

polywock commented Mar 30, 2025

If linking my GitHub to the W3 account is enough, the ipr issue should be resolved.

malloy20001
malloy20001 previously approved these changes Apr 21, 2025
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, I have a request to specify the meaning of "origin" more precisely.

* And if `topFrameMatches` was specified, the origin of the top-level frame's URL matches at least one pattern in `topFrameMatches`.
* And if `excludeTopFrameMatches` was specified, the origin of the top-level frame's URL does *not* match any validated pattern in `excludeTopFrameMatches`.

**Origin Definition:** The origin consists of the scheme, host, and port (e.g., `https://www.example.com:443`). Match patterns are compared against this origin. The path component of the top-level URL is ignored during matching, as enforced by the validation rule disallowing specific paths in the patterns.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this seems precise, it is leaving room for interpretation. I think that it would make most sense to use the origin following the interpretation of match_origin_as_fallback: true as specified at https://w3c.github.io/webextensions/specification/index.html#determine-the-url-for-matching-a-document . That part of the spec draft was added in #542
My motivation for this interpretation is to make sure that about:blank, blob: etc can be matched (which would naturally happen if you look at the document's origin) AND also that http(s) documents would be matched even if Content-Security-Policy: sandbox were to be used, which would give it an opaque origin.

And also to specify what should happen if an origin cannot be determined, so that we don't have issues like https://bugzilla.mozilla.org/show_bug.cgi?id=1798225 ([DNR] Matching of missing initiators and/or with an opaque origin)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering potential support for <extension_urls>, we should specify how browsers should handle match patterns they do not understand. Whether or not excludeTopFrameMatches should become a no-op or simply prevent the content script from running.

Copy link
Author

@polywock polywock May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rob--W Updated the proposal to use the W3C spec for origin matching and to clarify behavior for unknown origin. Let me know if it didn't hit the mark.

@carlosjeurissen It's a cop out, but I've added -> "The browser must validate all patterns provided in topFrameMatches and excludeTopFrameMatches as it would validate patterns provided by matches and excludeMatches" as a base validation step for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants