chrome-extensions-samples icon indicating copy to clipboard operation
chrome-extensions-samples copied to clipboard

Trouble upgrading Content-Security-Policy from third party from Manifest v2 to Manifest v3

Open hyfydistro opened this issue 2 years ago • 3 comments

I'm unclear how to resolve my invalid CSP. I'm unable to find an example in the Migrating to Manifest v3 Google Chrome extension (https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy).

Could you provide an example in here for it?

Here is what I have:

Manifest v2

  "content_security_policy": "script-src 'self' 'unsafe-eval' https://cdn.firebase.com https://apis.google.com https://www.gstatic.com; object-src 'self'"

In Manifest v3 they have properties to give value to, but I don't see an example for outside sites.

How do I configure this for Google Chrome extension Manifest v3?

hyfydistro avatar Jun 16 '22 16:06 hyfydistro

What exactly are you trying to achieve?

guest271314 avatar Jun 19 '22 17:06 guest271314

Create a sandbox page that will be available and reachable to other parts of your code with some tweaking and message passing.

Set CORS for Sandbox to include 'unsafe-eval'

for the script src of your extension_pages 'unsafe-eval' will never allow you to load the extension.

Ambushfall avatar Aug 20 '22 14:08 Ambushfall

There are few explanations and examples of sandbox and it is difficult to understand.

warmhug avatar Sep 08 '22 09:09 warmhug

The extension_pages property sets the CSP for the extension's pages to allow scripts from the extension itself ('self') and from external domains like https://cdn.firebase.com, https://apis.google.com, and https://www.gstatic.com. It also allows objects to be loaded only from the extension itself ('self'). Note that you should adjust the script-src and object-src directives to match your specific needs and security requirements.

Also, note that the sandbox property is set to allow scripts and same-origin content. This can help mitigate the risk of vulnerabilities in your code by isolating it from other content on the page.

"content_security_policy": { "extension_pages": "script-src 'self' 'unsafe-eval' https://cdn.firebase.com https://apis.google.com https://www.gstatic.com; object-src 'self'", "sandbox": "allow-scripts allow-same-origin" }

M-SAI-SOORYA avatar Mar 24 '23 17:03 M-SAI-SOORYA