TheNab
June 30, 2025, 12:54am
1
inline js script tag isn’t being loaded due to csp and idk how to fix it.
2 Likes
There’s some information in this post that may help: Mitigate XSS Attacks with Content Security Policy
CSP and third-party integrations
When using third-party services like Google Tag Manager, Google Analytics, or advertising services, you may need to adjust your CSP settings. In most cases with Discourse version 3.3.0.beta1 or later, external scripts should work without additional configuration due to the ‘strict-dynamic’ CSP implementation.
If you encounter issues, you may need to:
Identify the required script sources by monitoring your browser console
Add the necessary sources to the content_security_policy_script_src
setting
For complex integrations like ad services which load external resources, you might need to enable cross-domain rendering (Example PR from discourse-adplugin that does this).
Best practices
Start with CSP Report-Only mode to identify potential issues
Gradually tighten your CSP as you resolve legitimate violations
Regularly review your CSP settings and adjust as needed
Be cautious when adding permissive directives like 'unsafe-eval'
or 'wasm-unsafe-eval'
Keep your Discourse instance updated to benefit from the latest CSP improvements
1 Like
TheNab
June 30, 2025, 5:14pm
3
I’ve read through that and others but cannot piece together how to actually add the exception to the content_security_policy_script_src
1 Like
Do you see an error concerning the script in your browser console? something like this?
You’ll want to add that provided hash ('sha256-xxxxx'
) to the “content security policy script src” setting found in admin > all site settings
1 Like
The error I was getting had nonce-s0m3h4sh in Firefox browser I wasn’t getting the sha256-s0m3h4sh. But when I just now looked in chrome it was the sha256 one. I suppose that was causing most of my confusion
2 Likes
system
(system)
Closed
July 31, 2025, 3:58pm
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.