feat(audio): restrict ffmpeg/ffprobe input to local files and audio demuxers
The upload is attacker-supplied and its CONTENT can steer ffmpeg to open other files or URLs (HLS/concat playlists). Pins -protocol_whitelist file,pipe and -format_whitelist to the containers real recordings use, before the input (after -i it would apply to the output). Verified with the real static ffmpeg 7.0.2 on koala: real AAC .m4a and WAV still probe/convert; a crafted concat file is rejected with 'Format not on whitelist'. Note ffmpeg 7.0.2 ALREADY refused the playlists tried without the whitelist, so the live check cannot prove the whitelist -- the argv unit tests do; this protects against a different ffmpeg version being put in the image. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,8 +27,10 @@ func (f *FFmpeg) ToWAV(ctx context.Context, src, dst string) error {
|
||||
if bin == "" {
|
||||
bin = "ffmpeg"
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, bin,
|
||||
"-y", "-v", "error", "-i", src, "-vn", "-ac", "1", "-ar", "16000", "-c:a", "pcm_s16le", "-f", "wav", dst)
|
||||
// Input restrictions go BEFORE -i: placed after it they would apply to the output.
|
||||
args := append([]string{"-y", "-v", "error"}, inputRestrictions...)
|
||||
args = append(args, "-i", src, "-vn", "-ac", "1", "-ar", "16000", "-c:a", "pcm_s16le", "-f", "wav", dst)
|
||||
cmd := exec.CommandContext(ctx, bin, args...)
|
||||
cmd.WaitDelay = killGrace
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user