fix(media): prevent drawtext filtergraph injection in add_text - #6734
fix(media): prevent drawtext filtergraph injection in add_text#6734waleedlatif1 wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview
Adds Reviewed by Cursor Bugbot for commit e77c308. Configure here. |
Greptile SummaryThe PR prevents user-controlled captions from entering FFmpeg’s filtergraph parser by storing them in an operation-owned text file.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/media/ffmpeg.ts | Replaces unsafe inline caption interpolation with an operation-owned text file and disables drawtext expansion. |
| apps/sim/lib/media/ffmpeg.test.ts | Adds focused regression tests confirming normal and malicious captions remain outside the generated filtergraph. |
Sequence Diagram
sequenceDiagram
participant Caller
participant AddText as addText
participant Temp as Temporary directory
participant FFmpeg
Caller->>AddText: Caption and video
AddText->>Temp: Write caption.txt
AddText->>FFmpeg: "drawtext=textfile=caption.txt, cwd=temp dir"
FFmpeg->>Temp: Read literal caption bytes
FFmpeg-->>Caller: Rendered video
Reviews (3): Last reviewed commit: "fix(media): prevent drawtext filtergraph..." | Re-trigger Greptile
5676385 to
97732f5
Compare
|
@cursor review |
The add_text FFmpeg operation inlined the caller's caption into a single-quoted `drawtext=text='...'` filter option. FFmpeg's av_get_token copies bytes verbatim inside a single-quoted run, so a literal quote in the caption closed the quote and the remainder was parsed as filtergraph syntax. An attacker could inject `drawtext=textfile=<path>` (arbitrary local-file read) or `movie=filename=<url>:f=tty` (read-SSRF), rendering the target file bytes or HTTP response body into the returned video. Route the caption out-of-band: write it to a file the operation owns and reference it via `drawtext=textfile=caption.txt` with `expansion=none`, so the caption bytes never re-enter the filtergraph parser. The caption is referenced by a bare relative filename with FFmpeg's working directory set to the temp dir, because FFmpeg's tokenizer cannot round-trip a single quote inside a textfile= value — an absolute temp path would break add_text whenever os.tmpdir() contains a quote (e.g. a Windows profile). The working directory is passed via execve and never parsed as graph syntax, so any character in it is safe.
97732f5 to
e77c308
Compare
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e77c308. Configure here.
Summary
add_textFFmpeg operation inlined the caller's caption into a single-quoteddrawtext=text='...'filter option. FFmpeg'sav_get_tokencopies bytes verbatim inside a single-quoted run, so a literal quote in the caption closed the quote and the rest of the caption was parsed as filtergraph syntax.drawtext=textfile=<path>(arbitrary local-file read) ormovie=filename=<url>:f=tty(read-SSRF) — rendering the target file's bytes or an HTTP response body into the returned video.drawtext=textfile='<temp>'withexpansion=none, so caption bytes never re-enter the filtergraph parser. Only the app-controlled temp path is escaped (for FFmpeg's two-level option parsing);expansion=nonealso disables%{...}expansion so the caption renders fully literally.apps/sim/lib/media/ffmpeg.test.tscovering the two breakout classes (textfile file-read andmovie=SSRF) plus a normal caption.Type of Change
Testing
ffmpegtool tests, lint, and type-check all pass (no new errors).Checklist