T09 · Insecure Skill Coding Practices
- Location
scripts/add-subtitles.sh:41- Finding
FFmpeg Filtergraph Injection Through Unvalidated User-Controlled Parameters
- Content
View full analysis
= 0.5 && $RATE <= 2.0" | bc -l) )); then ffmpeg -i "$INPUT" -filter_complex "[0:v]setpts=PTS/$RATE[v];[0:a]atempo=$RATE[a]" -map "[v]" -map "[a]" "$OUTPUT" else echo "Warning: Speed rate outside 0.5-2.0 range may require multiple filter passes" ffmpeg -i "$INPUT" -filter_complex "[0:v]setpts=PTS/$RATE[v]" -map "[v]" -an "$OUTPUT" fi ``` ### Technical Analysis The scripts interpolate user-controlled subtitle paths, crop coordinates, dimensions, scale values, and speed rates directly into FFmpeg filter expressions. Shell quoting prevents these values from being split into separate shell arguments, so this is not ordinary shell-command injection. However, shell quoting does not escape FFmpeg's independent filtergraph grammar. Characters meaningful to FFmpeg—including quotes, commas, semicolons, brackets, colons, and backslashes—can change how the resulting filter expression is parsed. The numeric options are only checked for being non ...[truncated 1829 chars]- Remediation
View remediation
&2 exit 1 fi ``` 3. Validate speed as a positive decimal and enforce the range supported by the selected audio-filter construction: ```bash if [[ ! "$RATE" =~ ^([0-9]+([.][0-9]+)?|[.][0-9]+)$ ]]; then echo "Error: invalid speed rate" >&2 exit 1 fi ``` 4. Escape subtitle paths according to FFmpeg filter-expression rules. Account for backslashes, colons, apostrophes, commas, and other filtergraph metacharacters. Do not assume shell quoting provides FFmpeg escaping. 5. Prefer generating a controlled filter script or using an implementation that separates validated parameter values from filtergraph structure. 6. Where operationally possible, explicitly restrict the protocols FFmpeg may use and run media processing in a sandbox with: - Minimal filesystem access. - No unnecessary network access. - CPU, memory, file-size, and execution-time limits. - A dedicated low-privilege account. ]]>
