Skip to content

feat: restrict input protocols and demuxers - #13

Merged
ChiragAgg5k merged 3 commits into
mainfrom
feat/input-whitelists
Nov 17, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
feat/input-whitelists

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Adds optional protocols and formats constructor arguments to every adapter. When set, they are passed as -protocol_whitelist / -format_whitelist before each ffmpeg -i and before ffprobe's input, so callers handling user uploads can stop playlist demuxers (hls, concat) from opening other files or URLs. Both default to empty, leaving current behaviour unchanged.

Checked against ffmpeg 8.1.2: with formats set, an HLS playlist is rejected (Format not on whitelist) and no segment is requested, while an MP4 still probes and transcodes.

🤖 Generated with Claude Code

Related: appwrite-labs/cloud#6673

Adapters take optional protocols and formats lists, passed as
-protocol_whitelist and -format_whitelist before every ffmpeg input
and to ffprobe. Both default to empty, which keeps current behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@appwrite

appwrite Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental tests exercise the new protocol-only rejection cases and the standalone encode path without introducing an issue.

Adds optional protocol and demuxer allowlists to FFmpeg and FFprobe inputs, with empty defaults preserving existing behavior. Documents using the allowlists with untrusted media and adds end-to-end coverage for playlist rejection, local-file protocol rejection, and normal MP4 probe, encode, and transcode behavior.

Latest changes: The new commits add end-to-end checks that protocol-only allowlists reject local files in both probe and FFmpeg paths, and that standalone encoding still works with both allowlists enabled.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
README.md Documents configuring protocol and format allowlists when handling untrusted media.
src/Video/Adapter.php Adds allowlist constructor options and builds input-scoped FFmpeg/FFprobe options.
src/Video/Adapter/FFmpeg.php Applies allowlist options before FFmpeg inputs.
src/Video/Adapter/FFprobe.php Applies allowlist options to FFprobe input reads.
tests/Video/E2E/WhitelistTest.php Tests playlist restrictions, protocol-only local-file rejection, and allowed MP4 operations, including standalone encoding.

Reviewed the commits since 1d80302 · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

$video = $info->hasVideo && ($rep === null || $rep->scaled());

$args = $this->prefix();
\array_push($args, ...$this->opens());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add coverage for the input whitelist arguments

The existing adapter and ffprobe tests do not verify these new flags or that they appear before each input. If the flags are later omitted or misplaced, configured adapters could silently allow playlist or nested resource opens again; please add command-level coverage for ffmpeg and ffprobe.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Video/Adapter/FFmpeg.php
Line: 101

Comment:
**Add coverage for the input whitelist arguments**

The existing adapter and ffprobe tests do not verify these new flags or that they appear before each input. If the flags are later omitted or misplaced, configured adapters could silently allow playlist or nested resource opens again; please add command-level coverage for ffmpeg and ffprobe.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests/Video/E2E/WhitelistTest.php, which runs real ffprobe and ffmpeg: an unrestricted probe follows a local HLS playlist, while a restricted probe and a restricted encoder (with an open probe, so the refusal comes from ffmpeg) both fail on it, and a restricted encoder still probes and grabs from an MP4. Passes locally on ffmpeg 8.1.2.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end-to-end tests are useful, but they don’t fully cover the requested arguments. Both restricted cases allow file and exclude hls, so their failures demonstrate the format restriction, not that -protocol_whitelist was emitted. They also don’t assert the argument order for each input. The tests exercise playlist rejection, while opens() builds both flags.

Please add command-level assertions for the whitelist arguments and their placement before each FFmpeg input and the FFprobe source.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added cases that restrict protocols only (https,tls,tcp, no format list): ffprobe and ffmpeg (behind an open probe) each refuse a local MP4, so -protocol_whitelist reaches both commands independently of -format_whitelist. A restricted encode of an MP4 also runs. These stay end to end against real binaries rather than asserting argv, since the argv is built in protected methods with no seam to observe it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. The end-to-end tests cover the restrictions against real ffprobe and ffmpeg binaries, so I’ve dismissed the command-level assertion finding. WhitelistTest.php

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 17, 2026
@ChiragAgg5k
ChiragAgg5k merged commit ae53ec4 into main Nov 17, 2026
6 checks passed
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.

1 participant