-
Notifications
You must be signed in to change notification settings - Fork 56
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
executeScript API may inject scripts in an unexpected target at runtime #8
Comments
Proposal from Google on documentIds: |
A few quick thoughts post-meeting on the Chrome proposal… I love the document ID concept as a solution for “time of use” problems. With the current APIs there are cases where these problems are unavoidable, and being able to target a specific document (and therefore a certain origin) is a really nice capability. I do have some backwards compatibility concerns when it comes to pre-rendering:
While I realise it isn’t part of the proposal, someone at WECG suggested making this opt-in, so I wanted to provide some thoughts on that too. Unfortunately, I think that could cause even worse backwards compatibility issues. Unless all of the events are queued up until the page becomes active (onDOMContentLoaded etc.) a new page is magically going to become frame 0 without any of the events extensions are built to expect. Finally, are there any plans to indicate to extensions when a pre-rendered frame becomes active? That’s important because an extension may want to (for example) update UI or clear data based on when the page the user is looking at changes. Appreciate all of the work here. It would be great to come to a consensus because Safari does similar pre-rendering and I expect other browsers may want to experiment in the future. |
I've left a few comments from the Firefox point of view in the doc, but the biggest issue seems to be that it's not obvious from the proposal that top frame in a pre-rendered tab would not have the value That would mean the value of the I expect a much more compatible change would be to keep it zero during pre-render, and let extensions distinguish if it's the currently "active" frame using |
This is largely solved in Chrome via document ID support. Adding "implemented:chrome". |
The
chrome.tabs.executeScript
API (and also Chrome's proposedchrome.scripting.executeScript
API) have an inherent design flaw (TOCTOU) that is not present with statically registered content scripts.The
executeScript
API looks like this:For script execution at runtime by the extension, the typical pattern is that an extension calls
executeScript
in response to an event related to a tab or frame (e.g. a navigation, network request or user interaction with an extension button). The problem with theexecuteScript
API is that it only takes atabId
andframeId
as an identifier. These IDs uniquely identify a frame (BrowsingContext), but not the document within the frame. Consequently, it's possible for a page to have been navigated and for the extension to inadvertently run a content script on an unexpected website.This issue is not present with
content_scripts
inmanifest.json
(or APIs that register scripts in a declarative way such asbrowser.contentScripts.register
), because the browser engine checks the URL right before injection.There are multiple ways to mitigate this issue with
executeScript
, e.g. any of the following:tabId + frameId + documentId
), and allow extensions to pass this toexecuteScript
(and potentially any API where this is relevant, beyond content scripts, e.g. extension messaging APIs).documentId
may not always be known when an extension uses this.history.pushState
).The text was updated successfully, but these errors were encountered: