T09 · Insecure Skill Coding Practices
- Location
scripts/ocr-cli.sh:26- Finding
Unquoted Argument Construction Allows Option Injection and Unsafe Path Handling
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ocr-cli.sh, lines 26–37
Vulnerability Type: Argument injection through unquoted shell variable expansion
Risk Level: Mediumbash if [ -d "$INPUT" ]; then SOURCE_ARG="--sourcedir $INPUT" else SOURCE_ARG="--sourceimg $INPUT" fi VIZ_FLAG="" [ -n "$VIZ" ] && VIZ_FLAG="--viz True" "$VENV" "$OCR" $SOURCE_ARG --output "$OUTDIR" $VIZ_FLAG >/dev/null 2>&1Technical Analysis
The script combines attacker-influenced
INPUTdata with an option name in the scalarSOURCE_ARG, then expands that variable without quotes when invoking the Python OCR program. Bash therefore applies word splitting and pathname expansion to its contents.An input path containing whitespace can be converted into multiple Python arguments. Subsequent path components beginning with
-or--may consequently be interpreted bysrc/ocr.pyas additional options rather than as part of the source path. The same unsafe scalar-expansion pattern is used forVIZ_FLAG.This is argument injection, not direct shell-command injection: shell metacharacters stored in
INPUTare not reparsed as shell syntax during ordinary parameter expansion. The exact security impact cannot be fully established because the audited artifact does not contain the referencedsrc/ocr.py. The artifact also lacks the expected.venv/bin/pythonexecutable, so the documented OCR workflow cannot run from the supplied files alone.Attack Path
- An attacker creates or supplies an image or directory whose path contains whitespace and option-like tokens.
- An agent invokes
scripts/ocr-cli.shwith that path. - The script embeds the path in
SOURCE_ARG. - Unquoted expansion splits
SOURCE_ARGinto multiple command-line arguments and may perform pathname expansion. - The missing
src/ocr.pyimplementation may interpret injected tokens as options and perform unintended behavior supported by its ...[truncated 676 chars]
- Remediation
View remediation
Remediation Suggestions
Construct command arguments with Bash arrays so each value retains its intended argument boundary:
bash if [ "$#" -lt 1 ]; then printf 'Usage: %s <image-or-directory> [--json] [--viz]\n' "$0" >&2 exit 2 fi INPUT="$1" shift if [ ! -e "$INPUT" ]; then printf 'Input does not exist: %s\n' "$INPUT" >&2 exit 1 fi if [ -d "$INPUT" ]; then source_args=(--sourcedir "$INPUT") else source_args=(--sourceimg "$INPUT") fi viz_args=() if [ -n "$VIZ" ]; then viz_args=(--viz True) fi "$VENV" "$OCR" \ "${source_args[@]}" \ --output "$OUTDIR" \ "${viz_args[@]}" \ >/dev/null 2>&1Additionally:
- Validate the input path and reject unsupported input types before invoking Python.
- Reject unknown wrapper options instead of silently ignoring them.
- Verify that
$VENVis executable and$OCRis a regular trusted file before execution. - Avoid suppressing all diagnostics, or capture them in a controlled log, so parsing failures and security-relevant errors remain observable.
- Include and audit
src/ocr.pyand the dependency specification before distributing the skill as operational.
