T09 · Insecure Skill Coding Practices
- Location
mp4_to_gif.sh:20- Finding
FFmpeg Filter-Graph Injection Through Unvalidated Width and FPS Parameters
- Content
View full analysis
/dev/null echo "Converting to GIF..." ffmpeg -y -i "$INPUT" -i "$PALETTE" -lavfi "fps=$FPS,scale=${WIDTH}:-1:flags=lanczos [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" "$OUTPUT" 2>/dev/null ``` ### Technical Analysis The `-w` and `-f` arguments are accepted as unrestricted strings and interpolated directly into FFmpeg `-vf` and `-lavfi` filter-graph expressions. Shell quoting prevents these values from being split into separate shell arguments and prevents ordinary shell metacharacters from directly creating a new shell command. However, quoting does not prevent FFmpeg from interpreting commas, semicolons, labels, option separators, and other filter-graph syntax contained in the values. An attacker able to control the script arguments could therefore alter the intended graph, append FFmpeg filters, reference additional resources supported by installed filters, or deliberately construct computationally expensive processing. The exact filters available depend on the local FFmpeg build. ### Attack Path 1. An attacker obtains control over, or influences, the values passed to `-w` or `-f`. 2. The script stores the supplied value without validating that it is a decimal number. 3. The value is embedded in the `-vf` and `-lavfi` expressions. 4. FFmpeg parses attacker-provided filter-graph syntax with the privileges of the invoking user. 5. The injected graph can modify generated output, consume ...[truncated 891 chars]- Remediation
View remediation
4096 )); then echo "Invalid width: expected an integer from 1 to 4096." >&2 exit 1 fi if ! [[ "$FPS" =~ ^[0-9]+$ ]] || (( FPS < 1 || FPS > 60 )); then echo "Invalid FPS: expected an integer from 1 to 60." >&2 exit 1 fi ``` Additional hardening should include: - Use application-appropriate upper bounds to prevent resource exhaustion. - Reject signs, decimals, whitespace, commas, semicolons, brackets, backslashes, and all other non-digit characters. - Consider limiting input duration, dimensions, and output size. - Preserve FFmpeg diagnostics or report them through a controlled error path instead of always discarding standard error. - Add regression tests using malformed values containing FFmpeg filter separators. ]]>
