Repository navigation
feat: restrict input protocols and demuxers #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Utopia\Tests\E2E; | ||
|
|
||
| use Utopia\Video\Adapter\FFmpeg; | ||
| use Utopia\Video\Adapter\FFprobe; | ||
| use Utopia\Video\Encoder; | ||
| use Utopia\Video\Exception\Runtime; | ||
| use Utopia\Video\Process; | ||
|
|
||
| /** | ||
| * A source may be a playlist that names other files. With the demuxers | ||
| * restricted, neither ffprobe nor ffmpeg follows it, while a plain container | ||
| * still reads as before. | ||
| */ | ||
| class WhitelistTest extends Base | ||
| { | ||
| private const FORMATS = ['mov', 'matroska', 'mpegts']; | ||
|
|
||
| private const PROTOCOLS = ['file']; | ||
|
|
||
| private function playlist(): string | ||
| { | ||
| $segment = $this->dir.'/segment.ts'; | ||
|
|
||
| Process::run([ | ||
| 'ffmpeg', '-y', '-hide_banner', '-loglevel', 'error', | ||
| '-i', self::video(), '-c', 'copy', '-t', '2', $segment, | ||
| ], timeout: 60); | ||
|
|
||
| $path = $this->dir.'/list.m3u8'; | ||
| \file_put_contents($path, "#EXTM3U\n#EXT-X-TARGETDURATION:2\n#EXTINF:2,\n".$segment."\n#EXT-X-ENDLIST\n"); | ||
|
|
||
| return $path; | ||
| } | ||
|
|
||
| public function testAnUnrestrictedProbeFollowsAPlaylist(): void | ||
| { | ||
| $this->assertTrue((new FFprobe())->read($this->playlist())->hasVideo); | ||
| } | ||
|
|
||
| public function testARestrictedProbeRefusesAPlaylist(): void | ||
| { | ||
| $probe = new FFprobe(protocols: self::PROTOCOLS, formats: self::FORMATS); | ||
|
|
||
| $this->expectException(Runtime::class); | ||
| $probe->read($this->playlist()); | ||
| } | ||
|
|
||
| public function testARestrictedEncoderRefusesAPlaylist(): void | ||
| { | ||
| // The probe is left open so the refusal can only come from ffmpeg. | ||
| $encoder = new Encoder(new FFmpeg(protocols: self::PROTOCOLS, formats: self::FORMATS), new FFprobe()); | ||
|
|
||
| $this->expectException(Runtime::class); | ||
| $encoder->grab($this->playlist(), $this->dir.'/poster.jpg'); | ||
| } | ||
|
|
||
| public function testAProbeLimitedToOtherProtocolsRefusesALocalFile(): void | ||
| { | ||
| $probe = new FFprobe(protocols: ['https', 'tls', 'tcp']); | ||
|
|
||
| $this->expectException(Runtime::class); | ||
| $probe->read(self::video()); | ||
| } | ||
|
|
||
| public function testAnEncoderLimitedToOtherProtocolsRefusesALocalFile(): void | ||
| { | ||
| $encoder = new Encoder(new FFmpeg(protocols: ['https', 'tls', 'tcp']), new FFprobe()); | ||
|
|
||
| $this->expectException(Runtime::class); | ||
| $encoder->grab(self::video(), $this->dir.'/poster.jpg'); | ||
| } | ||
|
|
||
| public function testARestrictedEncoderStillEncodesAPlainContainer(): void | ||
| { | ||
| // The encode path builds its own command line; it must still run. | ||
| $encoder = new Encoder( | ||
| new FFmpeg(protocols: self::PROTOCOLS, formats: self::FORMATS), | ||
| new FFprobe(protocols: self::PROTOCOLS, formats: self::FORMATS), | ||
| ); | ||
|
|
||
| $this->assertWritten($encoder->open(self::video())->encode($this->dir.'/out.mp4')); | ||
| } | ||
|
|
||
| public function testARestrictedEncoderStillReadsAPlainContainer(): void | ||
| { | ||
| $encoder = new Encoder( | ||
| new FFmpeg(protocols: self::PROTOCOLS, formats: self::FORMATS), | ||
| new FFprobe(protocols: self::PROTOCOLS, formats: self::FORMATS), | ||
| ); | ||
|
|
||
| $this->assertTrue($encoder->probe(self::video())->hasVideo); | ||
| $this->assertWritten($encoder->grab(self::video(), $this->dir.'/poster.jpg')); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
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
🟡 Minor · testing · Reply if this doesn't apply.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
fileand excludehls, so their failures demonstrate the format restriction, not that-protocol_whitelistwas emitted. They also don’t assert the argument order for each input. The tests exercise playlist rejection, whileopens()builds both flags.Please add command-level assertions for the whitelist arguments and their placement before each FFmpeg input and the FFprobe source.
There was a problem hiding this comment.
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_whitelistreaches 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.There was a problem hiding this comment.
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