Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document CSP nonce requirements for Django Debug Toolbar compatibility #2058

Open
robhudson opened this issue Jan 16, 2025 · 2 comments
Open

Comments

@robhudson
Copy link
Contributor

In a comment it was pointed out that users with django-csp enabled may need some extra set up to allow the debug toolbar to function correctly. Since these users will get the nonce applied to the toolbar's <script> tags.

Perhaps some documentation along these lines should be included in the documentation...


Debug Toolbar and CSP Nonces

When using django-csp, the toolbar's inline <script> tags will include CSP nonces. To ensure the debug toolbar functions correctly during development, make sure the nonce is included in your script-src directive in the Content-Security-Policy header.

@Zerotask
Copy link
Contributor

Thank you for creating this issue.

You also have to adjust the style-src and add unsafe-inline.

With django-csp you have to ensure, that your settings look like this:

CSP_SCRIPT_SRC = ["'self'", "'unsafe-inline'"]
CSP_STYLE_SRC = ["'self'", "'unsafe-inline'"]

In our case, we didn't want to set unsafe-inline for script-src and style-src and therefore I was a bit confused that I had these issues after updating it since it was nowhere documented that you need to do that.

@tim-schilling
Copy link
Member

@robhudson is it possible for us to include example code for:

To ensure the debug toolbar functions correctly during development, make sure the nonce is included in your script-src directive in the Content-Security-Policy header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants