T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/ocr-cli.sh:26
- Finding
- Unquoted Argument Construction Allows Option Injection and Unsafe Path Handling## Vulnerability Details **File Location**: `scripts/ocr-cli.sh`, lines 26–37 **Vulnerability Type**: Argument injection through unquoted shell variable expansion **Risk Level**: Medium ```bash 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>&1 ``` ### Technical Analysis The script combines attacker-influenced `INPUT` data with an option name in the scalar `SOURCE_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 by `src/ocr.py` as additional options rather than as part of the source path. The same unsafe scalar-expansion pattern is used for `VIZ_FLAG`. This is argument injection, not direct shell-command injection: shell metacharacters stored in `INPUT` are 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 referenced `src/ocr.py`. The artifact also lacks the expected `.venv/bin/python` executable, so the documented OCR workflow cannot run from the supplied files alone. ### Attack Path 1. An attacker creates or supplies an image or directory whose path contains whitespace and option-like tokens. 2. An agent invokes `scripts/ocr-cli.sh` with that path. 3. The script embeds the path in `SOURCE_ARG`. 4. Unquoted expansion splits `SOURCE_ARG` into multiple command-line arguments and may perform pathname expansion. 5. The missing `src/ocr.py` implementation may interpret injected tokens as options and perform unintended behavior supported by its ...[truncated 676 chars]
- 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>&1 ``` Additionally: - Validate the input path and reject unsupported input types before invoking Python. - Reject unknown wrapper options instead of silently ignoring them. - Verify that `$VENV` is executable and `$OCR` is 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.py` and the dependency specification before distributing the skill as operational.
