T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/eye.sh:8
- Finding
- Execution of Untrusted JavaScript Outside the Skill Directory<![CDATA[ ## Vulnerability Details **File Location**: `scripts/eye.sh:8-9`, with execution at `scripts/eye.sh:58` **Vulnerability Type**: Unsafe external path resolution and arbitrary local code execution **Risk Level**: High ### Vulnerable Code ```bash SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" SERVER="$PROJECT_ROOT/server.js" ``` The resolved file is subsequently executed: ```bash echo "[eye] Starting glyph viewer on port $PORT..." node "$SERVER" --port "$PORT" & disown ``` ### Technical Analysis The script resides at `<project>/scripts/eye.sh`. Starting from the `scripts` directory and traversing three parent directories causes `PROJECT_ROOT` to resolve outside the installed Skill directory. For the audited artifact path, it resolves to `/tmp`, making `SERVER` equal to `/tmp/server.js`. The package does not contain the documented `server.js`. Consequently, the launcher does not execute a reviewed, package-controlled server. Instead, it executes whichever file is present at the external path. Shared temporary directories such as `/tmp` are commonly writable by unprivileged local users and processes, making this an unsafe trust-boundary violation. This behavior is not required for the declared glyph-viewer functionality and exceeds minimum privilege by allowing code outside the Skill package to inherit the invoking user's execution context. ### Attack Path 1. An attacker or compromised local process creates `/tmp/server.js`. 2. The file contains attacker-controlled Node.js code. 3. A user or Agent invokes: ```bash ./scripts/eye.sh start ``` 4. The wrapper computes `SERVER=/tmp/server.js`. 5. Node.js executes the attacker-controlled file with the permissions and environment of the invoking user. 6. The payload can access user-readable files, inherited environment variables, local services, and available network resources. ### Impact Assessment Successful exploitation provides arbitrary co ...[truncated 514 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Resolve the project root as the direct parent of the script directory: ```bash SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" PROJECT_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd -P)" SERVER="$PROJECT_ROOT/server.js" ``` 2. Package `server.js` inside the Skill directory. 3. Fail closed if the server is missing or is not a regular file: ```bash if [[ ! -f "$SERVER" || -L "$SERVER" ]]; then echo "[eye] Refusing to start: packaged server is missing or unsafe" >&2 exit 1 fi ``` 4. Canonicalize the server path and verify that it remains beneath the canonical Skill root. 5. Do not search shared temporary directories or parent projects for executable code. 6. Consider validating the packaged server against a signed manifest or expected cryptographic hash. 7. Add installation and CI tests that confirm all documented runtime files are included and that no executable path escapes the package. ]]>
