T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/extract_frames.sh:53
- Finding
- Unvalidated FPS Argument Allows FFmpeg Filtergraph Injection## Vulnerability Details **File Location**: `scripts/extract_frames.sh`, lines 7 and 53 **Vulnerability Type**: FFmpeg filtergraph expression injection **Risk Level**: Medium ### Vulnerable Code ```bash FPS="${3:-1}" ``` ```bash ffmpeg -i "$VIDEO_PATH" -vf "fps=$FPS" "$OUTPUT_DIR/frame_%03d.jpg" -y -loglevel warning ``` ### Technical Analysis The third command-line argument is documented as a numeric frame rate, but the script performs no type, range, or syntax validation before interpolating it into the FFmpeg `-vf` filtergraph. Shell quoting prevents ordinary shell metacharacters from being evaluated by Bash, but it does not make the value safe for FFmpeg's filtergraph parser. An attacker-controlled value can include FFmpeg filter separators and options. For example, a value structurally similar to: ```text 1,drawtext=textfile=/path/to/readable/file ``` can append a second video filter. Where the relevant FFmpeg filter is available, this can cause FFmpeg to read local file content and render it into generated frames. Other available filters may provide additional unintended file or resource access. ### Attack Path 1. An attacker obtains control over, or persuades a user or agent to supply, the optional `fps` argument. 2. The attacker supplies a crafted FFmpeg filter expression instead of a numeric frame rate. 3. The script concatenates the value into `-vf "fps=$FPS"` without validation. 4. FFmpeg parses the injected syntax as additional filtergraph operations. 5. The injected filter accesses a local resource readable by the script's user and places resulting information into the output frames. 6. The attacker obtains the generated frames or causes them to be processed by a downstream agent. ### Impact Assessment Exploitation occurs with the permissions of the user running the script. It does not directly grant elevated operating-system privileges, but it can exceed the documented capability of sel ...[truncated 403 chars]
- Remediation
- ## Remediation Suggestions Treat the FPS value as a numeric parameter rather than an FFmpeg expression. 1. Validate the argument against a strict decimal-number allowlist. 2. Reject zero, negative, non-finite, and excessively large values. 3. Apply a reasonable upper bound to prevent resource exhaustion. 4. Do not allow commas, colons, semicolons, brackets, backslashes, or filter names. 5. Exit before invoking FFmpeg when validation fails. Example hardening: ```bash FPS="${3:-1}" if [[ ! "$FPS" =~ ^([0-9]+)([.][0-9]+)?$ ]]; then echo "Error: fps must be a positive numeric value" >&2 exit 1 fi if ! awk -v fps="$FPS" 'BEGIN { exit !(fps > 0 && fps <= 60) }'; then echo "Error: fps must be greater than 0 and no greater than 60" >&2 exit 1 fi ``` The final implementation should also be tested with malformed values to verify that no FFmpeg filtergraph syntax is accepted.
