T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/import-credentials.sh:73
- Finding
- Unvalidated Credential Archive Extraction Allows Arbitrary File Overwrite<![CDATA[ ## Vulnerability Details **File Location**: `scripts/import-credentials.sh:73-80` **Vulnerability Type**: Unsafe archive extraction **Risk Level**: High ### Vulnerable Code ```bash elif [ -f "$BUNDLE" ]; then # File: assume base64-encoded tar.gz. echo "Importing from file: $BUNDLE" base64 -d < "$BUNDLE" | tar -xzf - -C "$CREDS_DIR" else # Raw base64 string: decode and extract. echo "Importing from base64 string..." echo "$BUNDLE" | base64 -d | tar -xzf - -C "$CREDS_DIR" fi ``` ### Technical Analysis The script extracts a user-supplied archive directly into the credential directory without validating archive members. It does not reject: - Absolute paths - `../` path traversal - Symbolic or hard links - Device nodes or other special files - Files outside the expected `accounts.json`, `tls.cert`, and `admin.macaroon` allowlist The later existence and permission checks do not undo files written outside the destination. A malicious tar archive can therefore use traversal entries or links to overwrite arbitrary files writable by the invoking user. ### Attack Path 1. An attacker supplies a crafted base64-encoded tarball as the signer credential bundle. 2. The victim invokes the documented `import-credentials.sh --bundle` workflow. 3. `tar` processes a malicious traversal or link entry. 4. The entry escapes `~/.lnget/lnd/signer-credentials`. 5. An attacker-selected configuration, shell startup file, executable, or other user-writable file is overwritten. 6. The overwritten file may subsequently trigger code execution under the victim's account. ### Impact Assessment An attacker can overwrite files with the privileges of the user running the Skill. Depending on writable targets and subsequent application behavior, this can cause credential replacement, configuration poisoning, denial of service, or local code execution. ]]>
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Decode the bundle into a newly created directory from `mktemp -d`. 2. List and validate every archive member before extraction. 3. Reject absolute paths, `..` components, links, devices, FIFOs, and unexpected file types. 4. Permit exactly three regular files with fixed names. 5. Extract with restrictive ownership and permission options. 6. Copy validated files into the destination only after all checks succeed. 7. Remove the temporary directory using a safely quoted trap. ]]>
