Repository navigation
Specify the activeTab permission. - #1152
kiaraarose wants to merge 3 commits into
Conversation
Define the `activeTab` permission and describe how this permission is granted from an invocation of the extension by the user. Open questions about inconsistencies are tagged with issue notes, and include links to relevant issues where these inconsistencies have been discussed.
|
@kiaraarose Thanks for putting this together! Would it make sense to join this concept of access to the tab together with Ideally we would consolidate and unify the different concepts of host access as much as possible. For example, in Chrome |
I created a separate issue for specing |
| An <dfn>invocation</dfn> of an extension is one of the following user interactions, each of which identifies a [=tab=], called the <dfn for="invocation">target tab</dfn>. No other user interaction is an invocation. | ||
|
|
||
| * Clicking the extension's action, a button that the user agent shows for the extension, such as a toolbar button. The target tab is the [=selected tab=] of the browser window in which the user activates the action. | ||
| * Choosing a menu item that the extension created with the `menus` or `contextMenus` API, in a menu that the user agent shows for a tab, for a [=document in a tab=], or for the extension's action. The target tab is that tab, the tab of that document, or, for a menu shown for the action, the [=selected tab=] of the browser window that contains the action. |
There was a problem hiding this comment.
What about clicking a context menu item in a subframe of a tab?
There was a problem hiding this comment.
Subframes seem to have two coherent options, and Safari behaves like the second one.
Path A: show the item and grant the top-level origin. Chromium and Firefox do this today. The target tab is the tab that contains the subframe, and the grant is for the top-level document origin. It keeps the grant model of one tab and one origin. For a cross-origin subframe it means:
- The extension gets access the user did not point at (the host page), and no access to what the user did point at (the frame).
frameUrlandframeIdare in the click info, but the extension cannot inject into that frame. - An extension that has only
activeTabsees a menu item for an action it cannot perform on that frame.
Path B: show the item only when the grant would cover the frame. Safari hides the item in a subframe unless the extension already has access to the frame URL. The argument for this:
- An item that appears implies the extension can act, so the click does what the menu suggests.
- A click aimed at one origin content does not hand the extension access to a different origin.
- Extension authors can rely on "the item appeared, so I have access".
Safari’s rule today is blunter than that principle, since it also hides the item for a same-origin subframe where the grant would work. A refinement would show the item when the frame is same-origin with the grant origin and hide it otherwise.
The specification could document Path A with an Issue for the cross-origin case, or take Path B with that refinement. Path B looks preferable to me because an invocation then always gives the extension something to act on, but it would be new behavior for the engines that show the item now.
There was a problem hiding this comment.
I'm interested in exploring cross-origin subframe access, but that should be a separate issue, not here.
Here is a relevant feature request in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1838753
There was a problem hiding this comment.
I went with Path A since this matches two browser vendors. i filled #1195 to address whether or not the grant should cover a subframe if the invocation happened in that frame
|
|
||
| 1. Let |tab| be the [=invocation/target tab=]. | ||
| 1. Let |origin| be the [=Document/origin=] of |tab|'s [=navigable/active document=]. | ||
| 1. If |origin| is an [=opaque origin=], return. |
There was a problem hiding this comment.
I don't think Chrome does this. Looking at our code, it seems we don't grant the origin permission, but do grant tab permission (so an extension could still see data like tab.url, tab.faviconUrl, etc)
There was a problem hiding this comment.
Could we use the "Determine the URL for matching a document" algorithm with match_origin_as_fallback=true here, to make sure that something like scripting.executeScript works once the user performs an action that grants activeTab?
Currently rendered spec: https://w3c.github.io/webextensions/specification/#determine-the-url-for-matching-a-document
Source: https://github.com/w3c/webextensions/blob/99c5b2b4cc1c57b089c061254195aff8f96c5032/specification/index.bs#L367C51-L397
|
Scheduled for discussion at TPAC on Monday, October 26. See https://github.com/w3c/webextensions/wiki/2026-TPAC-Coordination#-spec-progress-. |
|
FYI: I chatted with @zombie (and @patrickkettner ) about activeTab in Firefox, and we are willing to align with the behaviors that Chrome and Safari have; that an activeTab grant takes the shape of granting origin access across APIs, instead of only activeTab. There are some subtle differences between Chrome and Safari, so before filing the bug I'd like to get clarity on what we want to align on. EDIT: Filed bug at https://bugzilla.mozilla.org/show_bug.cgi?id=2086712 |
oliverdunk
left a comment
There was a problem hiding this comment.
Thanks Kiara! The general behaviors described here seem correct, just left a few nits on our approach to the specification language.
|
|
||
| While an extension has an [=activeTab grant=] for a [=tab=], the user agent treats the extension as having a host permission for the [=activeTab grant/origin of the grant=] for the following purposes: | ||
|
|
||
| * Injecting scripts and style sheets into any [=document in a tab|document=] in the granted tab whose origin is [=same origin=] with the [=activeTab grant/origin of the grant=], and removing the style sheets that the extension inserted, using the `scripting` API. |
There was a problem hiding this comment.
Similar to the feedback on other parts, this feels quite verbose and like it might be unrealistic to do for every part of the specification that grants some kind of host permissions. Does it make sense to drop this list?
There was a problem hiding this comment.
I would lean towards keeping a list here, but a shorter one could work. Unlike a regular host permission, activeTab is defined by what the grant covers: reading the tab URL and title, injecting scripts, capturing the tab, and so on. That list tells an implementer what the grant has to cover, and the browser differences in the Issue notes hang off those items. It also should not set a precedent for every permission, because most permissions apply to a whole API and do not need a list of purposes. If length is the concern, dropping the "such as" examples after each item and keeping only the purposes might be enough.
There was a problem hiding this comment.
i agree that listing examples are helpful, as leaving them out can easily lead to browser inconsistencies across our implementations, which is why i added them. although, each browser might have their own opinions as to what a user interaction is. for example, Chrome doesn't grant the activeTab when a user opens the sidebar, whereas Safari (behind a feature flag, not including user interactions within the sidebar) and Firefox do. this is a question i'm planning on raising in a separate discussion in the soon to come sidebar proposal, but it highlights an example of where browser vendors may disagree.
given that we've chose to align on the described behavior in this list, i think it would helpful to keep, but i can add a sentence stating that this is not an exhaustive list, if that easies your concerns @oliverdunk
Rob--W
left a comment
There was a problem hiding this comment.
I reviewed the draft together with @kiaraarose and she took notes for the start of the document. Near the end of the draft PR I started adding comments/suggestions on the PR itself, which are included in this round of review.
|
|
||
| 1. Let |tab| be the [=invocation/target tab=]. | ||
| 1. Let |origin| be the [=Document/origin=] of |tab|'s [=navigable/active document=]. | ||
| 1. If |origin| is an [=opaque origin=], return. |
There was a problem hiding this comment.
Could we use the "Determine the URL for matching a document" algorithm with match_origin_as_fallback=true here, to make sure that something like scripting.executeScript works once the user performs an action that grants activeTab?
Currently rendered spec: https://w3c.github.io/webextensions/specification/#determine-the-url-for-matching-a-document
Source: https://github.com/w3c/webextensions/blob/99c5b2b4cc1c57b089c061254195aff8f96c5032/specification/index.bs#L367C51-L397
|
|
||
| Issue: User agents differ on whether a grant lets the extension make requests to the [=activeTab grant/origin of the grant=] from its privileged extension contexts. This specification allows it. See the discussion of [PR 799](https://github.com/w3c/webextensions/pull/799). | ||
|
|
||
| A grant does not add to the permissions that the user agent has granted to the extension. For example, `permissions.contains()` does not report the grant, and the `cookies` API does not treat the extension as having a host permission for the [=activeTab grant/origin of the grant=]. |
There was a problem hiding this comment.
This remark about cookies API not having access is surprising to me. While true for Firefox right now, it is mostly due to Firefox's activeTab being tied to scripting.
As I understand Safari/Chrome's model, granting activeTab is equivalent to getting host permissions for the match pattern derived from the tab's URL. With that in mind, I would expect the cookies API to also have access. Two additional arguments: content scripts can read cookies, and webRequest/DNR can also read/modify cookies, with the granted access.
There was a problem hiding this comment.
In Safari the grant is tab-scoped. webRequest and declarativeNetRequest checks carry the tab, so the grant applies to them. cookies checks the URL without a tab, so the grant gives no access there. The sentence matches what Safari does today.
|
|
||
| The user agent removes an extension's [=activeTab grant=] for a [=tab=] when any of the following occurs: | ||
|
|
||
| * The tab's [=navigable/active document=] becomes a document whose [=Document/origin=] is not [=same origin=] with the [=activeTab grant/origin of the grant=]. |
There was a problem hiding this comment.
Should we compare document origins, or the origin that we identified before? See my comment in the thread about opaque origin for context, at https://github.com/w3c/webextensions/pull/1152/changes#r4377190005
An example with different outcomes depending on the interpretation is when a (CSP) sandboxed example.com navigates to unsandboxed example.com (or the converse).
There was a problem hiding this comment.
Safari does not sandbox documents, so that example does not apply there. Safari derives a match pattern from the tab URL (http and https together, exact host, any port, any path) and ends the grant when the tab navigates to a URL that does not match. That is looser than same origin: a navigation from http to https on the same host, or to a different port, keeps the grant. It is worth deciding which of the two behaviors the specification should describe.
There was a problem hiding this comment.
Safari does not sandbox documents, so that example does not apply there.
I'm not sure if we are referring to the same concept. For clarity, I am referring to a document whose CSP is derived from a HTTP header Content-Security-Policy: sandbox allow-scripts allow-top-navigation (or perhaps<iframe sandbox that created a popup). That document would have an opaque origin due to the absence of allow-same-origin`. If navigated to a different page at the same domain that (for example) lacks a CSP header, then the new document would not be an opaque origin. Therefore the old and new documents would be considered cross-origin. Even if it was the same URL, a document with an opaque origin is cross-origin relative to any other document.
In that example, the origin component of the tab's URL as displayed in the address bar are identical though.
And if you avoid the document's origin and want to focus on the tab's URL, then what is the outcome for blob:-URLs? I guess that you would consider them different, despite their origin (precursor in case of opaque origins) being identical.
Safari derives a match pattern from the tab URL (http and https together, exact host, any port, any path) and ends the grant when the tab navigates to a URL that does not match. That is looser than same origin:
In some sense this is stricter than same-origin: same-origin checks ignore the path. If you consider a navigation to same domain but different paths as ending the grant, that is stricter than a same-origin check.
And in non-sandboxed about:blank, the tab's URL would not reflect its origin. So as currently written, the grant would also end when you navigate from or to a same-origin about:blank doc.
There was a problem hiding this comment.
The specification now compares origins: a grant ends when the tab navigates to a document whose origin, resolved through determine the URL for matching a document, is not same origin with the grant's origin. A change of scheme or port therefore ends the grant, and a change of path does not. I filed https://bugs.webkit.org/show_bug.cgi?id=331525 to change Safari's behavior of keeping the grant when the scheme or port changes.
|
FYI: I created a bug tracking the implementation in Firefox at https://bugzilla.mozilla.org/show_bug.cgi?id=2086712. |
Derive the grant origin from the URL for matching a document, so a tab with an opaque origin still receives a grant for its tab properties, and compare the same origin when a grant ends. State that a grant follows the top-level document. Define "has a permission" once under `permissions`, shorten the access list, and use the `Issue(N)` shortcut for issue links.
Treat the invocation list as not exhaustive, state that a menu item chosen in a subframe targets the containing tab, and link the question of subframe access to issue 1195.
26ac97c to
1ca3093
Compare
Define the
activeTabpermission and describe how this permission is granted from an invocation ofthe extension by the user. Open questions about inconsistencies are tagged with issue notes, and
include links to relevant issues where these inconsistencies have been discussed.
Preview | Diff