T09 · Insecure Skill Coding Practices
- Location
build.sh:11- Finding
Path Traversal and Unsafe Recursive Deletion Through Unvalidated Version Argument
- Content
View full analysis
- Remediation
View remediation
&2 exit 1 fi ``` 2. Store the trusted temporary root separately and clean up only that exact directory: ```bash TMP_ROOT="$(mktemp -d)" trap 'rm -rf -- "$TMP_ROOT"' EXIT STAGE_DIR="$TMP_ROOT/${SLUG}-v${VER}" mkdir -p -- "$STAGE_DIR" ``` 3. Remove the derived cleanup operation: ```bash rm -rf "$(dirname "$STAGE_DIR")" ``` Cleanup should never be calculated from an attacker-influenced child path. 4. Use `--` for filesystem commands where supported so option-like values cannot be interpreted as command options: ```bash mkdir -p -- "$OUT_DIR" "$STAGE_DIR" cp -- "$SRC_DIR/$f" "$STAGE_DIR/$f" ``` 5. Canonicalize and verify output paths before writing: ```bash EXPECTED_PARENT="$(cd "$SRC_DIR/.." && pwd)" OUT_DIR="$EXPECTED_PARENT/zips-v${VER}" case "$OUT_DIR" in "$EXPECTED_PARENT"/zips-v*) ;; *) echo "ERROR: output path escaped expected directory" >&2 exit 1 ;; esac ``` 6. Run builds as an unprivileged account with access limited to the source workspace, temporary directory, and designated artifact directory. 7. Add negative tests that ensure versions containing `/`, `..`, whitespace, shell metacharacters, absolute paths, and option prefixes are rejected before any filesystem modification occurs. ]]>
