You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We mentioned and considered this issue again in discussion #945.
I'm a bit unsure and don't fully remember why we previously thought bypassing CSP was impossible.
I guess the main reason was that we cannot use tab.executeScript() to inject scripts at an accurate earlier time and dose not supports injection into the page scope, and we didn’t pay enough attention to the new MV3 API scripting.executeScript() (also available with MV2 in Safari)?
Anyway, I mentioned other day that actually we could combine the two, although it might add a bit of async latency, but bypassing CSP seems possible. Specifically we can ensure timing through content scripts and inject actual user script through scripting.executeScript().
I did a simple test and in a page with the script-src 'none' policy, injecting an inline script will get the error:
Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.
Note
It should be noted that there is no distinction between page context and content script context here, cause inline scripts are always appended to the DOM.
Then in the same page, executing from the background page, it succeeds:
Note that in Safari the injectImmediately parameter is always true.
"Scripts are always injected immediately."
So we just need to wrap and implement the @run-at logic additionally.
And since scripting.executeScript() does not modify the DOM, this has some additional benefits.
So there doesn't seem to be a significant impediment other than the impact on @run-at document-start of possible additional delays due to asynchronous messaging and execution.
Finally, from what I remember reading, the MV3 userScripts API should also support bypassing CSP.
We have had some
CSPrelated issues like:CSPissues) #106We mentioned and considered this issue again in discussion #945.
I'm a bit unsure and don't fully remember why we previously thought bypassing
CSPwas impossible.I guess the main reason was that we cannot use
tab.executeScript()to inject scripts at an accurate earlier time and dose not supports injection into the page scope, and we didn’t pay enough attention to the new MV3 APIscripting.executeScript()(also available with MV2 in Safari)?Anyway, I mentioned other day that actually we could combine the two, although it might add a bit of async latency, but bypassing
CSPseems possible. Specifically we can ensure timing through content scripts and inject actual user script throughscripting.executeScript().I did a simple test and in a page with the
script-src 'none'policy, injecting an inline script will get the error:Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.Note
It should be noted that there is no distinction between page context and content script context here, cause inline scripts are always appended to the DOM.
Then in the same page, executing from the background page, it succeeds:
Note
Note that in Safari the
injectImmediatelyparameter is alwaystrue."Scripts are always injected immediately."
So we just need to wrap and implement the
@run-atlogic additionally.And since
scripting.executeScript()does not modify the DOM, this has some additional benefits.So there doesn't seem to be a significant impediment other than the impact on
@run-at document-startof possible additional delays due to asynchronous messaging and execution.Finally, from what I remember reading, the MV3
userScriptsAPI should also support bypassingCSP.