T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:61
- Finding
- Registration credentials are written to predictable temporary files## Vulnerability Details **File Location**: `SKILL.md`, lines 61-95 **Vulnerability Type**: Unsafe temporary-file handling and plaintext credential storage **Risk Level**: Medium ### Vulnerable Code ```bash # 1) Create challenge (or fail fast if name taken) curl -sS -X POST "$BASE/api/v1/registrations" \ -H "content-type: application/json" \ --data "{\"username\":\"$USERNAME\",\"bip321Uri\":\"$BIP321_URI\"}" \ > /tmp/clank_register_challenge.json ERROR_CODE="$(python3 -c 'import json; d=json.load(open("/tmp/clank_register_challenge.json")); e=d.get("error"); print((e.get("code") if isinstance(e,dict) else e) or "")')" if [ "$ERROR_CODE" = "username_unavailable" ]; then echo "Username is taken. Pick another USERNAME and rerun." exit 1 fi if [ "$ERROR_CODE" != "payment_required" ]; then echo "Unexpected challenge response:" cat /tmp/clank_register_challenge.json exit 1 fi MACAROON="$(python3 -c 'import json; print(json.load(open("/tmp/clank_register_challenge.json"))["macaroon"])')" INVOICE="$(python3 -c 'import json; print(json.load(open("/tmp/clank_register_challenge.json"))["invoice"])')" echo "Pay this invoice now:" echo "$INVOICE" # 2) After payment, paste your preimage read -r -p "PASTE_PREIMAGE=" PREIMAGE # 3) Complete paid registration curl -sS -X POST "$BASE/api/v1/registrations" \ -H "content-type: application/json" \ -H "Authorization: L402 $MACAROON:$PREIMAGE" \ --data "{\"username\":\"$USERNAME\",\"bip321Uri\":\"$BIP321_URI\"}" \ > /tmp/clank_register_result.json MGMT="$(python3 -c 'import json; d=json.load(open("/tmp/clank_register_result.json")); print(d.get("managementToken",""))')" if [ -z "$MGMT" ]; then echo "No managementToken in final response:" cat /tmp/clank_register_result.json exit 1 fi ``` ### Technical Analysis The documented workflow writes API responses to fixed paths in the shared `/tmp` directory. It does not estab ...[truncated 2202 chars]
- Remediation
- ## Remediation Suggestions - Set `umask 077` before creating any file containing API responses or credentials. - Create a private temporary directory atomically with `mktemp -d` rather than using fixed filenames in `/tmp`. - Register a shell `trap` to remove temporary files on normal exit, errors, and signals. - Ensure temporary destinations are regular files and are not symbolic links. - Avoid retaining the entire final response after extracting the management token. - Write the management token atomically to a mode-`600` file inside a mode-`700` directory. - Do not print complete API responses on error when those responses may contain authentication material. A hardened pattern is: ```bash umask 077 TMP_DIR="$(mktemp -d)" trap 'rm -rf -- "$TMP_DIR"' EXIT HUP INT TERM CHALLENGE_FILE="$TMP_DIR/challenge.json" RESULT_FILE="$TMP_DIR/result.json" mkdir -p -- "$(dirname "$TOKEN_FILE")" chmod 700 -- "$(dirname "$TOKEN_FILE")" # Write responses only beneath the private temporary directory. # After validating the result, atomically install the token. TOKEN_TMP="$(mktemp "$(dirname "$TOKEN_FILE")/.management_token.XXXXXX")" printf '%s\n' "$MGMT" > "$TOKEN_TMP" chmod 600 "$TOKEN_TMP" mv -f -- "$TOKEN_TMP" "$TOKEN_FILE" ```
