You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: add a site-wide Content-Security-Policy (Report-Only first) #3041
Right now www.python.org does not send a Content-Security-Policy header (a quick check of the response headers shows only X-Frame-Options: SAMEORIGIN and HSTS). Adding a CSP would give the site meaningful defense-in-depth against XSS: even if user-influenced HTML is ever mis-sanitized, a strict script-src with no unsafe-inline stops injected scripts and javascript: URIs from executing.
This follows up on a request from @sethmlarson to propose a CSP for the python.org service.
Why Report-Only first
python.org serves some inline scripts/styles and pulls assets from a CDN plus a few third-party origins, so a strict policy dropped straight into enforcing mode would break pages. The safe path is to roll out in Content-Security-Policy-Report-Only mode first, collect violation reports, tune the allowlist, and only then switch to enforcing.
This is only a starting point. The exact script-src / style-src / img-src / connect-src origins depend on which third-party services python.org actually loads, which the Report-Only telemetry will surface.
Open questions for maintainers
Which third-party origins (CDN, analytics, fonts, embedded widgets, donation flow) need allowlisting?
Nonces vs hashes for the existing inline scripts and styles?
Preferred reporting endpoint (self-hosted report handler vs an external collector)?
Happy to open a Report-Only PR (django-csp plus nonce wiring and the starting policy above) once the approach looks right.
Activity
linear-code commentedon Jul 2, 2026
PYORG-2992
sethmlarson commentedon Jul 2, 2026
It looks like Sentry supports CSP Reporting, we could use our existing Sentry configuration for this potentially cc @JacobCoffee
Add a Content-Security-Policy in Report-Only mode
Add a Content-Security-Policy in Report-Only mode (refs #3041) (#3042)
saitanallensantiago26-beep commentedon Sep 18, 2026
fix(csp): allow HTTPS images in report-only img-src (#3154)
JacobCoffee commentedon Oct 7, 2026
its in report only now