Skip to content

Conversation

@ahumeau
Copy link
Contributor

@ahumeau ahumeau commented Nov 27, 2025

Description

Django 6.0 added built-in support for Content Security Policies.
Part of this support is associating a randomly generated nonce to each request that can then be
attached to <script> and <style> tags.

If users of django-debug-toolbar want to have a nonce-based CSP, they need django-debug-toolbar to add the nonce to the <script> and <style> tags that it generates.

django-debug-toolbar already does that for CSP nonces generated by the django-csp third-party lib but the nonces generated by django-csp and Django are accessed differently.

This PR adds support for the CSP nonces generated by the built-in Django implementation.

Django 6.0 added built-in support for Content Security Policies.
Part of this support is associating a randomly generated nonce to each request that can then be
attached to <script> and <style> tags.

django-debug-toolbar already has support for CSP nonces generated by the django-csp third-party lib but
the nonces generated by django-csp and Django are accessed differently.

This commit adds support for the CSP nonces generated by the built-in Django implementation.
Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks very good.

Please change the CSP nonce import to use a django.VERSION comparison block so that we can automatically remove it in the future using django-upgrade (https://django-upgrade.readthedocs.io/en/latest/fixers.html#versioned-blocks)

@github-actions
Copy link

github-actions bot commented Nov 27, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  debug_toolbar
  _compat.py
  toolbar.py
  utils.py
Project Total  

This report was generated by python-coverage-comment-action

@ahumeau ahumeau requested a review from matthiask November 27, 2025 14:31
Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@matthiask matthiask merged commit 7382193 into django-commons:main Nov 27, 2025
28 checks passed
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

Successfully merging this pull request may close these issues.

2 participants