test(audio): attacker-supplied input must not steer ffmpeg to other files or URLs (red)
A file's CONTENT can tell ffmpeg to open other paths or URLs (HLS, concat playlists). ffmpeg 7.0.2 refuses the ones tried, but that is version luck and the image's ffmpeg is still to be chosen (#34). Pin protocol_whitelist to file,pipe and format_whitelist to the demuxers real audio uses, before the input. Red: audio.AllowedDemuxers is undefined. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,3 +58,22 @@ func TestFFmpegToWAV_MissingBinaryIsAnError(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
assert.False(t, errors.Is(err, context.Canceled))
|
||||
}
|
||||
|
||||
func TestFFmpegToWAV_RestrictsWhatTheFileMayMakeFFmpegOpen(t *testing.T) {
|
||||
rec := filepath.Join(t.TempDir(), "argv")
|
||||
bin := stub(t, `printf '%s\n' "$@" > `+rec+`
|
||||
for a; do last="$a"; done
|
||||
printf data > "$last"`)
|
||||
|
||||
err := (&audio.FFmpeg{Bin: bin}).ToWAV(context.Background(), "/spool/in", filepath.Join(t.TempDir(), "o.wav"))
|
||||
|
||||
require.NoError(t, err)
|
||||
args := argvOf(t, rec)
|
||||
pw, fw, in := indexOf(args, "-protocol_whitelist"), indexOf(args, "-format_whitelist"), indexOf(args, "-i")
|
||||
require.GreaterOrEqual(t, pw, 0, "argv: %v", args)
|
||||
require.GreaterOrEqual(t, fw, 0, "argv: %v", args)
|
||||
assert.Equal(t, "file,pipe", args[pw+1])
|
||||
assert.Equal(t, audio.AllowedDemuxers, args[fw+1])
|
||||
assert.Less(t, pw, in, "input options must come BEFORE -i or ffmpeg applies them to the output")
|
||||
assert.Less(t, fw, in)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user