zipcontent returns 304 before checking the entry exists, and 500 for non-zip files

Đang mở Phù hợp với người mới
#6,407 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
django, python
Lĩnh vực
backend, testing

Hướng nghiên cứu

Bắt đầu với contentcuration/contentcuration/views/zip.py, đặc biệt là phần kiểm tra If-Modified-Since, trình xử lý BadZipfile và POSSIBLE_ZIPPED_FILE_EXTENSIONS. Đọc test_invalid_zip trong contentcuration/contentcuration/tests/test_zipcontentview.py và bổ sung kiểm thử cho các yêu cầu có điều kiện đối với mục bị thiếu và mục hiện có. Công việc hoàn tất khi các mục không tồn tại và tệp zip không hợp lệ hoặc không được hỗ trợ trả về 404 mà không có báo cáo Sentry, còn phản hồi 304 cho một mục hiện có bao gồm cùng các header CORS như phản hồi 200.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

DEV: backend

Overview

ZipContentView answers any request carrying an If-Modified-Since header with 304 before it checks the entry inside the zip exists. For a stored file that isn't a zip, it returns a deliberate 500 and reports it to Sentry on every request. Both are reachable anonymously.

Complexity: Low
Target branch: hotfixes

Context

All behaviour below was reproduced:

  • The If-Modified-Since check runs before the lookup. If-Modified-Since: garbage on a nonexistent entry returns 304 instead of 404, and the 304 has none of the CORS headers the 200 carries.
  • The BadZipfile handler returns HttpResponseServerError and calls capture_message. /zipcontent/<checksum>.pdf/index.html reaches it. POSSIBLE_ZIPPED_FILE_EXTENSIONS is defined but never checked.
  • test_invalid_zip in contentcuration/contentcuration/tests/test_zipcontentview.py asserts the 500.
  • Related: #906, #844.
The Change
  • If-Modified-Since should only produce a 304 for an entry that exists, and the 304 should carry the same CORS headers as the 200.
  • A request for a stored file whose extension isn't in POSSIBLE_ZIPPED_FILE_EXTENSIONS, or that isn't a valid zip, should return 404 without a Sentry report.
Acceptance Criteria
General
  • A request with any If-Modified-Since for a nonexistent entry returns 404.
  • A request with If-Modified-Since for an existing entry returns 304 with the same CORS headers as the 200.
  • /zipcontent/<checksum>.pdf/index.html returns 404 and sends nothing to Sentry.
Testing
  • test_invalid_zip asserts 404, and new tests cover the two If-Modified-Since cases.

AI usage

I scoped the audit. Claude Code found and reproduced these failures and drafted this issue.

Ngôn ngữ chính
Python
Star
212
Fork
321
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của learningequality/studio

Tất cả issue của learningequality/studio

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.