T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/skill-zip-audit.sh:28
- Finding
- Untrusted ZIP Archives Are Extracted into a Predictable Shared Temporary Directory<![CDATA[ ## Vulnerability Details **File Location**: `scripts/skill-zip-audit.sh`, lines 28-34 **Vulnerability Type**: Unsafe temporary directory and archive extraction **Risk Level**: Medium ### Vulnerable Code ```bash TS="$(date +%Y%m%d-%H%M%S)" NAME="$(basename "$ZIP_PATH" .zip)" BASE="/tmp/skill-audit/${NAME}-${TS}" SRC_DIR="$BASE/src" mkdir -p "$SRC_DIR" unzip -qq "$ZIP_PATH" -d "$SRC_DIR" ``` ### Technical Analysis The script extracts an untrusted archive directly into a predictable location under the shared `/tmp` directory. The destination is derived from the archive name and a timestamp with one-second precision rather than being created atomically using a facility such as `mktemp`. The implementation does not: - Ensure that the audit directory is newly and atomically created. - Set restrictive permissions on the audit directory. - Reject pre-existing directories or symbolic links in the destination path. - Preflight archive entries for unsafe paths or symbolic links. - Limit the number, depth, or total expanded size of archive entries. - Apply a timeout or filesystem quota during extraction. A second local process may predict or observe the destination and pre-create components of the path. Depending on filesystem permissions and link placement, later report writes could then be redirected or disrupted. Independently, a malicious archive can contain a very large expanded payload or excessive numbers of files, causing disk-space or inode exhaustion. Archive traversal and symbolic-link behavior also depends on the installed `unzip` implementation. The script should not assume that every supported implementation safely handles every hostile archive layout. ### Attack Path 1. An attacker supplies a crafted ZIP file for auditing or places it in the watched drop directory. 2. The auditor derives a predictable path such as `/tmp/skill-audit/example-20260910-120000`. 3. A local attacker may pre-create that path or selected path components before `m ...[truncated 1078 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Create the audit directory atomically with restrictive permissions: ```bash umask 077 BASE="$(mktemp -d "${TMPDIR:-/tmp}/skill-audit.XXXXXXXX")" SRC_DIR="$BASE/src" mkdir -m 700 "$SRC_DIR" ``` 2. Reject archives containing absolute paths, parent-directory traversal components, symbolic links, hard links, excessive nesting, or other unsupported entry types before extraction. 3. Enforce limits on: - Compressed and expanded size. - Number of entries. - Maximum individual file size. - Directory depth. - Extraction duration. 4. Perform extraction in an isolated environment with no network access and access only to the input archive and dedicated output directory. 5. Verify after extraction that every regular output path resolves beneath the canonical extraction root. 6. Avoid reusing an existing audit directory and ensure cleanup is performed safely without following symbolic links. ]]>
