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

Aperta Adatta ai principianti
#6,407 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
django, python
Ambito
backend, testing

Direzione di ricerca

Inizia da contentcuration/contentcuration/views/zip.py, in particolare dal controllo If-Modified-Since, dal gestore BadZipfile e da POSSIBLE_ZIPPED_FILE_EXTENSIONS. Leggi test_invalid_zip in contentcuration/contentcuration/tests/test_zipcontentview.py e aggiungi test per le richieste condizionali relative a voci mancanti ed esistenti. Il lavoro è completato quando le voci inesistenti e i file zip non validi o non supportati restituiscono 404 senza un rapporto Sentry, mentre una risposta 304 per una voce esistente include gli stessi header CORS di una risposta 200.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
212
Fork
321
Merge medio
1g 7h
PR unite (30g)
14

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di learningequality/studio

Tutte le issue di learningequality/studio

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.