Skip to content
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

Switch remaining CSP-vulnerable main world script injection to scripting API #3053

Open
ghostwords opened this issue Feb 6, 2025 · 1 comment
Labels
bug Chrome MV3 Manifest V3-specific issue

Comments

@ghostwords
Copy link
Member

ghostwords commented Feb 6, 2025

We already migrated most but not all uses of window.injectScript() to the scripting API:

Let's migrate the rest (search for injectScript in the MV3 branch).

The main problem with window.injectScript() is that it is subject to page CSPs. This means learning from canvas fingerprinting and local storage is broken on sites with restrictive CSPs (like this very site probably). We pollute the page dev tools console and/or the Errors button on chrome://extensions/ when this happens.

Related issues: #1793, #1865

@ghostwords ghostwords added Chrome MV3 Manifest V3-specific issue labels Feb 6, 2025
@ghostwords ghostwords changed the title Switch remaining CSP-vulnerable dynamic main world injection to scripting API Switch remaining CSP-vulnerable main world script injection to scripting API Feb 6, 2025
@ghostwords ghostwords added the bug label Feb 7, 2025
@ghostwords
Copy link
Member Author

ghostwords commented Feb 11, 2025

One issue is that the two remaining uses of injectScript() both pass a parameter to the main world script, so that the main world script can send messages back to the content script using CustomEvents with a prearranged, random ID, to make message interception a bit harder.

There's been lots of discussion of adding parameters (and secure communication) to registered main world scripts (for example, w3c/webextensions#284 (comment) and w3c/webextensions#536 (comment)) but so far nothing tangible came of it? There may also be workarounds worth investigating in w3c/webextensions#78 (comment).

Edit: There are now two relevant API proposals, dom.execute() (synchronous cross-world content script injection) and dom.createPort() (secure communication).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Chrome MV3 Manifest V3-specific issue
Projects
None yet
Development

No branches or pull requests

1 participant