T09 · Insecure Skill Coding Practices
- Location
scripts/generate-report.sh:24- Finding
Unvalidated Model ID Allows Path Traversal and File Overwrite
- Content
View full analysis
"$REPORT_FILE" << EOF ``` ### Technical Analysis The script uses the attacker-controlled `MODEL_ID` argument directly as a path component. It does not reject absolute paths, `..` traversal components, directory separators, symbolic links, or unexpected characters. Although the script verifies that `OUTPUT_DIR` exists, it does not establish that the canonical directory remains inside `$HOME/vllm-compose`. The subsequent redirection truncates or creates `DEPLOYMENT_REPORT.md` in the resolved directory. Shell quoting prevents word splitting and command substitution at this location, but it does not prevent filesystem path traversal. The fixed output filename limits the overwrite target to a file named `DEPLOYMENT_REPORT.md`; however, an attacker can target any existing writable directory reachable from the invoking account. ### Attack Path 1. The attacker identifies or creates a writable target directory, such as `$HOME/target`. 2. The attacker invokes the script with a traversing model ID: ```bash ./scripts/generate-report.sh \ "../../target" \ "container" \ "8000" \ "Success" ``` 3. `OUTPUT_DIR` resolves lexically to: ```text $HOME/vllm-compose/../../target ``` 4. If the resolved directory exists, the directory check succeeds. 5. The script opens `DEPLOYMENT_REPORT.md` with shell redirection and truncates any existing file at that location. 6. Report content containing attacker-suppli ...[truncated 659 chars]- Remediation
View remediation
&2 exit 1 fi ``` 3. Explicitly reject absolute paths, `/`, backslashes, empty components, `.` components, and `..` components. 4. Resolve both the base directory and destination with `realpath`, then enforce containment: ```bash BASE_DIR="$(realpath -m "$HOME/vllm-compose")" OUTPUT_DIR="$(realpath -m "$BASE_DIR/$MODEL_ID")" case "$OUTPUT_DIR/" in "$BASE_DIR"/*) ;; *) echo "ERROR: Output path escapes deployment root" >&2 exit 1 ;; esac ``` 5. Reject symbolic-link output directories or verify the canonical path after resolving links. 6. Create reports atomically using a securely created temporary file inside the validated output directory, then rename it into place. 7. Avoid overwriting an existing report unless replacement was explicitly requested. ]]>
