T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/script.sh:19
- Finding
- Option Injection Through Unvalidated ZIP Command Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/script.sh:19-27`, `scripts/script.sh:62-71`, and `scripts/script.sh:112-121` **Vulnerability Type**: OS command option injection **Risk Level**: High ### Vulnerable Code ```bash cmd_create() { check_deps local archive="${1:?Usage: zip create <archive.zip> <files...>}" shift [ $# -eq 0 ] && die "No files specified" zip -rv "$archive" "$@" 2>&1 | while IFS= read -r line; do echo " $line" done ``` ```bash cmd_add() { check_deps local archive="${1:?Usage: zip add <archive.zip> <files...>}" shift [ $# -eq 0 ] && die "No files specified" [ ! -f "$archive" ] && die "Archive not found: $archive" zip -rv "$archive" "$@" 2>&1 | while IFS= read -r line; do echo " $line" done ``` ```bash cmd_password() { check_deps local archive="${1:?Usage: zip password <archive.zip> <password> <files...>}" local pass="${2:?Missing password}" shift 2 [ $# -eq 0 ] && die "No files specified" zip -e -P "$pass" -rv "$archive" "$@" 2>&1 | while IFS= read -r line; do echo " $line" done ``` ### Technical Analysis Quoting shell variables prevents shell word splitting and shell metacharacter expansion, but it does not prevent the invoked `zip` program from interpreting an argument beginning with `-` as an option. The archive name and user-provided file operands are forwarded directly to `zip` without validation or a supported end-of-options delimiter. Consequently, an attacker who controls the archive name or file arguments can supply option-like values that alter the behavior of `zip`. Common Info-ZIP implementations support security-sensitive options, including archive test command configuration such as `-T` and `-TT`. Where options are accepted after the archive operand, malicious file arguments can therefore reach utility-level command execution functionality. Even where the installed `zip` implementation or argum ...[truncated 1490 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Reject archive and file operands that can be interpreted as options, particularly values beginning with `-`. 2. Use the installed ZIP implementation's documented end-of-options mechanism before untrusted path operands. 3. If an end-of-options mechanism is unavailable or inconsistent across supported implementations, normalize user paths to explicit path forms such as absolute paths or `./relative-path` after validating them. 4. Canonicalize paths and enforce an allowlisted working directory when callers should only archive files from a designated location. 5. Avoid forwarding arbitrary caller-controlled arguments as utility options. 6. Add security regression tests covering operands such as `-T`, `-TT`, `--help`, and filenames beginning with a hyphen. 7. Verify behavior against every supported `zip` implementation because option parsing and command-related features can differ between versions. ]]>
