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

未关闭 适合新手
#6,407 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
django, python
领域
backend, testing

调研方向

从 contentcuration/contentcuration/views/zip.py 入手,重点查看 If-Modified-Since 检查、BadZipfile 处理器和 POSSIBLE_ZIPPED_FILE_EXTENSIONS。阅读 contentcuration/contentcuration/tests/test_zipcontentview.py 中的 test_invalid_zip,并补充对缺失条目和现有条目的条件请求的覆盖。完成标准:不存在的条目以及无效或不受支持的 zip 文件返回 404,且不会产生 Sentry 报告;现有条目返回 304 时包含与 200 响应相同的 CORS 标头。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
212
派生
321
平均合并
1 天 7 小时
30 天内合并 PR
14

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

learningequality/studio 的其他 Issue

查看 learningequality/studio 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。