As part of our efforts to make add-ons safer for users, and to support evolving manifest v3 features, we are making changes to apply the Content Security Policy (CSP) to content scripts used in extensions. These changes will make it easier to enforce our long-standing policy of disallowing execution of remote code.
When this feature is completed and enabled, remotely hosted code will not run, and attempts to run them will result in a network error. We have taken our time implementing this change to decrease the likelihood of breaking extensions and to maintain compatibility. Programmatically limiting the execution of remotely hosted code is an important aspect of manifest v3, and we feel it is a good time to move forward with these changes now.
We have landed a new content script CSP, the first part of these changes, behind preferences in Firefox 72. We’d love for developers to test it out to see how their extensions will be affected.
Using a test profile in Firefox Beta or Nightly, please change the following preferences in
false to enable policy enforcement
This will apply the default CSP to the content scripts of all installed extensions in the profile.
Then, update your extension’s manifest to change your content_security_policy. With the new content script CSP, content_scripts works the same as extension_pages. This means that the original CSP value moves under the
extension_pages key and the new
content_scripts key will control content scripts.
Your CSP will change from something that looks like:
content_security_policy: "script-src 'self'; object-src 'none'"
To something that looks like:
extension_pages: "script-src 'self'; object-src 'none'",
content_scripts: "script-src 'self'; object-src 'none'"
Next, load your extension in
about:debugging. The default CSP now applied to your content scripts will prevent the loading of remote resources, much like what happens when you try to insert an image into a website over http, possibly causing your extension to fail. Similar to the old content_security_policy (as documented on MDN), you may make changes using the content_scripts key.
Please do not loosen the CSP to allow remote code, as we are working on upcoming changes to disallow remote scripts.
As a note, we don’t currently support any other keys in the
content_security_policy object. We plan to be as compatible as possible with Chrome in this area will support the same key name they use for content_scripts in the future.
Please tell us about your testing experience on our community forums. If you think you’ve found a bug, please let us know on Bugzilla.
More changes to the CSP for extensions are expected to land behind preferences in the upcoming weeks. We will publish testing instructions once those updates are ready. The full set of changes should be finished and enabled by default in 2020, meaning that you will be able to use the new format without toggling any preferences in Firefox.
Even after the new CSP is turned on by default, extensions using manifest v2 will be able to continue using the string form of the CSP. The object format will only be required for extensions that use manifest v3 (which is not yet supported in Firefox).
There will be a transition period when Firefox supports both manifest v2 and manifest v3 so that developers have time to update their extensions. Stay tuned for updates about timing!
The post Test the new Content Security Policy for Content Scripts appeared first on Mozilla Add-ons Blog.