Proposal: add a site-wide Content-Security-Policy (Report-Only first)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Bắt đầu bằng cách xem xét tích hợp middleware django-csp và các template cơ sở chứa các thẻ script và style inline. Kiểm tra các origin của bên thứ ba mà python.org tải và xác định cách thu thập các báo cáo vi phạm. Công việc được xem là hoàn tất khi có policy Report-Only, wiring của nonce và một quy trình được ghi lại để tinh chỉnh allowlist trước khi áp dụng chính sách.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
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.
Proposed rollout
- Add
django-cspand enable its middleware. - Wire a per-request nonce into the
<script>/<style>tags in the base templates. - Ship a
Content-Security-Policy-Report-Onlypolicy with a reporting endpoint and collect violations for a couple of weeks. - Tighten the allowlist from the reports (CDN, analytics, fonts, donate/embed widgets, and so on).
- Flip Report-Only to enforcing once the reports are clean.
Starting policy (Report-Only, to be tuned from reports)
default-src 'self';
script-src 'self' 'nonce-{request_nonce}';
style-src 'self' 'nonce-{request_nonce}';
img-src 'self' data:;
font-src 'self';
connect-src 'self';
frame-ancestors 'self';
base-uri 'self';
object-src 'none';
form-action 'self';
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.
- Ngôn ngữ chính
- Python
- Star
- 1.7k
- Fork
- 702
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 18
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/pythondotorg
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
python/pythondotorg#3149 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: The code examples on the main page don't match their source codeCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python/pythondotorg#3137 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
app/pages bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
python/pythondotorg#2677 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend easy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
python/pythondotorg#2453 · 8 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: Nominee list shows nominations of you, not nominations you made, and ignores the electionCó thể đã có người làm @jefftriplett đã nhận 53 ngày trước. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
python/pythondotorg#3094 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python/pythondotorg
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Juniper/ansible-junos-stdlib#904 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
pollen-robotics/reachy_mini#1457 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:runtime good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
WATonomous/wato_f1tenth#39 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
FireDynamics/fdsreader#123 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100