T09 · Insecure Skill Coding Practices
- Location
- scripts/setup.sh:44
- Finding
- Arbitrary Command Execution Through Sourced Credential File<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup.sh:44-50`, `scripts/check-usage.sh:20-21`, and `scripts/refresh-token.sh:13` **Vulnerability Type**: Shell command injection through executable credential storage **Risk Level**: High ### Vulnerable Code `scripts/setup.sh:44-50`: ```bash cat > "$TOKEN_FILE" <<EOF # Claude Code OAuth Tokens # Generated: $(date) ACCESS_TOKEN="$ACCESS_TOKEN" REFRESH_TOKEN="$REFRESH_TOKEN" EOF ``` `scripts/check-usage.sh:20-21`: ```bash # Load tokens source "$TOKEN_FILE" ``` `scripts/refresh-token.sh:13`: ```bash source "$TOKEN_FILE" ``` ### Technical Analysis The setup script inserts user-provided token strings into a file formatted as a shell script. It does not escape quotation marks, command substitutions, semicolons, or other shell metacharacters. The usage and refresh scripts then execute the credential file with `source`. Consequently, `.tokens` is not treated as passive data: every shell construct in the file is evaluated with the privileges of the invoking user. For example, a malicious access-token input containing the following value can break out of the assignment: ```bash "; id > /tmp/token-skill-pwned; # ``` This produces an executable line resembling: ```bash ACCESS_TOKEN=""; id > /tmp/token-skill-pwned; #" ``` The same issue applies if another process, package update, or malicious repository contributor modifies `.tokens` after setup. ### Attack Path 1. An attacker persuades a user to enter a crafted token, supplies a preconfigured `.tokens` file, or gains the ability to modify that file. 2. The attacker inserts shell syntax into `ACCESS_TOKEN`, `REFRESH_TOKEN`, or another line in the file. 3. The user runs `scripts/check-usage.sh`, `scripts/report.sh`, or `scripts/refresh-token.sh`. 4. The affected script executes `source "$TOKEN_FILE"`. 5. The attacker's commands execute as the user running the Skill. ### Impact Assessment Successful exploitation provides arbitrary command exec ...[truncated 368 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Never execute credential files with `source`. - Store credentials in a non-executable structured format such as JSON. - Parse the file with a JSON parser and return only expected string fields. - Validate tokens against the documented token format and reject newlines, quotes, shell metacharacters, or malformed prefixes. - Create the credential file atomically with mode `0600`. - Prefer an operating-system credential store over repository-local plaintext storage. - If an environment-file format must be retained, use a dedicated parser that treats all values as data rather than shell syntax. ]]>
