Quick answer
Manifest V3 extension pages and workers run under an extension Content Security Policy. The default script-src allows packaged scripts from self, blocks inline JavaScript and string evaluation, and does not enable WebAssembly. The allowed minimum can include wasm-unsafe-eval for packaged WebAssembly, but it cannot be relaxed to allow unsafe-eval or arbitrary remote script hosts. Keep default and minimum policy separate when diagnosing a dependency.
CSP is one boundary, not a complete security review. A policy can block an inline handler while unsafe HTML still changes the interface or steals user input through allowed behavior. Render untrusted text as text, validate messages, and review the packaged dependency tree. Store remote-code rules also apply independently of whether a particular runtime path appears to pass CSP.
Practical implementation steps
Identify the blocked context
Read the violation's resource, directive, and execution surface. A popup, extension tab, worker, isolated content script, and page-main-world script do not all share the same policy context. Fix the affected surface rather than adding a broad manifest rule by trial and error. Inspect the popup console or worker inspector appropriate to the failure, and reproduce it from the packaged build.
Move executable code into packaged files
Replace inline event attributes with listeners in local JavaScript files. Use a production bundle that does not depend on eval-based development tooling. If an SDK imports a script from a CDN at runtime, bundle a compatible implementation or replace that dependency. Do not disable protections simply to make a starter's development mode run inside an extension.
Constrain network access separately
Host permissions and connect-src answer different questions. A custom connect-src or default-src can block a request even when host access is granted. If you restrict connections, list the implemented service origins and test the failure state when one is unavailable. Keep the list based on actual traffic; a remote-data endpoint must not become an executable-code source.
Review sandbox boundaries explicitly
Sandbox pages have a separate policy and no direct extension API access. They may help isolate a narrowly justified evaluation need, but add a message boundary and store-policy considerations. A sandbox is not permission to download arbitrary logic into a privileged extension. Validate input and output across that boundary, and prefer a dependency that works under the normal extension policy when possible.
Implementation example
This policy retains local scripts, disables plugin objects, and restricts connections to one illustrative API. Use it only when those constraints match the application. It does not grant host access and deliberately omits WebAssembly because the example has no WASM feature.
{
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'none'; connect-src 'self' https://api.example.com;"
},
"host_permissions": ["https://api.example.com/*"]
}
Add this fragment to a valid Manifest V3 manifest. Then test both the expected request and an unexpected destination from the extension context. Inspect built HTML for local script references and verify that dev-only bundles are absent. These are validation instructions, not claims that this policy was exercised in a portfolio extension.
Tradeoffs and alternatives
An explicit connection allowlist reduces accidental destinations but requires maintenance when a service changes. The default policy is simpler but does not express that application-specific network boundary. Adding packaged WASM may be justified for a real feature; adding its CSP allowance preemptively is unnecessary. Record why each customization exists so a future maintainer can evaluate changes.
Common mistakes
- Confusing the default policy with the minimum allowed policy.
- Adding unsafe-eval to fix a development bundle.
- Assuming host permission overrides connect-src.
- Treating CSP as sanitization for arbitrary HTML.
- Using a sandbox to bypass remote-code review.
Production checklist
- Each violation is traced to its actual context and directive.
- Scripts are packaged and production bundles avoid eval.
- Network permissions and CSP agree.
- Untrusted rendering and messages have separate validation.
- Sandbox input and output are bounded if used.
- Final ZIP and dependency code have been inspected.
FAQ
Can I allow a trusted CDN?
Not as an arbitrary script source for normal Manifest V3 extension pages. Package the executable dependency and review its generated output. A familiar provider does not waive the code model.
Does CSP prevent every XSS problem?
No. Keep safe rendering and validation as primary boundaries. CSP limits permitted execution and resources; it does not establish that received HTML or messages are trustworthy.
Conclusion
Diagnose the blocked operation before changing policy. Prefer packaged code compatible with the default script restrictions, then add only the resource rules required by the shipped feature. Verify CSP and store policy together, because satisfying one does not prove the other.
Primary sources
Related guides and examples
Need this implemented in a real product?
Browser tools with a clear purpose, focused permissions, and a maintainable Manifest V3 architecture.