Skip to content

fix: bound resource use in Studio video-download endpoint - #860

Merged
Kelketek merged 1 commit into
opencraft/teakfrom
fox/backport-security-patches
Aug 17, 2026
Merged

fix: bound resource use in Studio video-download endpoint#860
Kelketek merged 1 commit into
opencraft/teakfrom
fox/backport-security-patches

Conversation

@Kelketek

@Kelketek Kelketek commented Aug 11, 2026

Copy link
Copy Markdown
Member

Per upstream:

The PUT /api/contentstore/v1/videos/{course_id}/download endpoint returns a zip of selected course videos -- the operation is a download. (The original implementation used PUT, which is the wrong verb for a read; that's tracked as a separate cleanup.) The handler synchronously fetched each requested video, materialised each response in RAM and wrote it to a temp file before zipping. A course author requesting download of many large videos in one request could tie up a uWSGI worker for many minutes; concurrent requests exhausted the worker pool.

Stream the zip directly into the response instead -- each video is fetched with stream=True and piped chunk-by-chunk into a streaming zip entry, so peak memory is roughly the chunk size and no temp files are written to disk. Rate-limit the endpoint per user via the new VIDEO_DOWNLOAD_RATE_LIMIT setting (default 12/hour, via a UserRateThrottle subclass on the view). Per-request wall-clock is bounded by the WSGI server's request timeout.

Closes GHSA-g266-6v7f-j465.

Internal ticket: https://tasks.opencraft.com/browse/BB-11055

The PUT /api/contentstore/v1/videos/{course_id}/download endpoint
returns a zip of selected course videos -- the operation is a
download. (The original implementation used PUT, which is the wrong
verb for a read; that's tracked as a separate cleanup.) The handler
synchronously fetched each requested video, materialised each
response in RAM and wrote it to a temp file before zipping. A course
author requesting download of many large videos in one request could
tie up a uWSGI worker for many minutes; concurrent requests exhausted
the worker pool.

Stream the zip directly into the response instead -- each video is
fetched with stream=True and piped chunk-by-chunk into a streaming zip
entry, so peak memory is roughly the chunk size and no temp files are
written to disk. Rate-limit the endpoint per user via the new
VIDEO_DOWNLOAD_RATE_LIMIT setting (default 12/hour, via a
UserRateThrottle subclass on the view). Per-request wall-clock is
bounded by the WSGI server's request timeout.

Closes GHSA-g266-6v7f-j465.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Kelketek Kelketek self-assigned this Aug 14, 2026
@Kelketek
Kelketek requested a review from samuelallan72 August 14, 2026 15:37
@samuelallan72

Copy link
Copy Markdown
Member

@Kelketek the cherry pick looks good to me. Please take a look at the failing tests though. Thanks! :)

@Kelketek

Copy link
Copy Markdown
Member Author

@samuelallan72 I created an additional PR with an empty commit, and it failed with identical messages. Given that there are no new errors, I'm going ahead with merging. Looks like almost everyone will be off Teak soon anyway.

@Kelketek
Kelketek merged commit 36e2225 into opencraft/teak Aug 17, 2026
45 of 48 checks passed
@Kelketek
Kelketek deleted the fox/backport-security-patches branch August 17, 2026 16:38
@samuelallan72

Copy link
Copy Markdown
Member

@Kelketek sounds good, thanks for checking 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants