Opened 11 minutes ago
#37567 new New feature
Add system check when SECURE_CSP or SECURE_CSP_REPORT_ONLY is set without ContentSecurityPolicyMiddleware
| Reported by: | VCoder101 | Owned by: | |
|---|---|---|---|
| Component: | CSP | Version: | dev |
| Severity: | Low | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When a project defines a non-empty SECURE_CSP or SECURE_CSP_REPORT_ONLY
dict without adding django.middleware.csp.ContentSecurityPolicyMiddleware to
MIDDLEWARE, Django emits no warning and sends no CSP header (silent
fail-open). This also suppresses security.W027 (#37084), which is gated on
_csp_middleware(), and unlike invalid directives (#36831), browsers emit no
console feedback because no header is present.
Proposed check (security.W028, mirroring security.W001/W002/W003 and
security.W027): warn when either SECURE_CSP or SECURE_CSP_REPORT_ONLY is
a non-empty dict and ContentSecurityPolicyMiddleware is missing from
MIDDLEWARE.
Happy to submit a focused PR with tests and docs if this is accepted.