Repository navigation
fix(infra): refuse a URL transcript source that is not media from its first bytes - #4150
Merged
Merged
Conversation
|
Sandchest reviewed Sandchest reviews every change for vulnerabilities an attacker could use · 6 credits · Review details |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

A transcript created from a URL that does not point to an audio or video file now fails as soon as its first bytes arrive. Before, Cap downloaded and stored the whole file, up to 2 GB, before failing it. The failure code and message are unchanged, and it is still never charged.
What changed
After the credit hold and before anything is stored, the download reads the first 4 KB of the response. It runs the same check that extraction already runs on the stored file (
sniffMedia). If those bytes are not a self-contained audio or video file, such as an HTML page, a playlist or anything else, the download is cancelled and the transcript ends withunsupported_formatand "The file is not a supported audio or video format". Otherwise the bytes that were read are passed back in front of the rest of the stream, so the stored file is identical.source_unreachable, as before.Measured
Each failing source was run through the real download step, with a local origin that sends the file as fast as it is read:
The check needs 4 KB. The tens of kilobytes read are the first network chunks the HTTP client delivers before the connection is cancelled. On main the 2 GB case took 0.58 s locally to fail; with this change it fails in 0.01 s.
Proof
The download tests' fake origin now starts its file with an MP3 tag so that it counts as media, and the test mocks of the media check keep the real
sniffMedia.Not covered


Confidence Score: 5/5
The PR appears safe to merge.Summary
URL transcripts now check their first 4 KB before storing the download.
No actionable issues were found. This review checked source code; it did not run tests.
Reviews (1) · Last reviewed commit: "test(infra): cover URL sources refused f..." · Reviewed by Greptile