X Tutup
Skip to content

Add support for Django 6.0 built-in Content Security Policy#431

Open
alimony wants to merge 1 commit intoIdentityPython:masterfrom
alimony:support-django-native-csp
Open

Add support for Django 6.0 built-in Content Security Policy#431
alimony wants to merge 1 commit intoIdentityPython:masterfrom
alimony:support-django-native-csp

Conversation

@alimony
Copy link

@alimony alimony commented Mar 5, 2026

Summary

  • Detect Django 6.0's built-in CSP when django-csp is not installed
  • Read SECURE_CSP settings, merge form-action: ["https:"], and apply via csp_override
  • Preserve backwards compatibility: django-csp is still tried first
  • Add Django 6.0 to test matrix (Python 3.12+ only)

Context

Django 6.0 introduced native CSP support via ContentSecurityPolicyMiddleware
and SECURE_CSP settings. Previously, djangosaml2 only detected django-csp for
automatic CSP configuration. Users on Django 6.0 using the built-in CSP had to
either install django-csp or configure a custom SAML_CSP_HANDLER.

Since Django's built-in CSP only provides csp_override (full replacement, no
merge), the implementation reads the existing SECURE_CSP dict, adds
form-action: https: to it, and applies the merged config via csp_override.

Django 6.0 ships with native Content Security Policy support via `ContentSecurityPolicyMiddleware`. When `django-csp` is not installed, `djangosaml2` now detects the native CSP middleware and uses `csp_override` to merge `form-action: https:` into the existing `SECURE_CSP` settings.

Detection order: `django-csp` → Django native CSP → warning + no-op.
@alimony alimony changed the title Add support for Django 6.0 built-in CSP Add support for Django 6.0 built-in Content Security Policy Mar 5, 2026
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.

1 participant

X Tutup