T09 · Insecure Skill Coding Practices
Error
- Location
- bin/tldr-cmd:35
- Finding
- Unrestricted Local Executable Invocation Through User-Controlled Command Input<![CDATA[ ## Vulnerability Details **File Location**: `bin/tldr-cmd`, lines 35–39 **Vulnerability Type**: Unrestricted execution of a user-selected local program **Risk Level**: High ### Vulnerable Code ```bash if [[ -z "$about" && -z "$usage" ]] && command -v "$cmd" >/dev/null 2>&1; then help="$("$cmd" --help 2>&1 || true)" if [[ -n "$help" ]]; then about="$(printf '%s\n' "$help" | head -1 | tr -s ' \t' ' ' | sed 's/^ *//;s/ *$//')" usage="$cmd [options]" ``` ### Technical Analysis The positional argument assigned to `cmd` is controlled by the caller. If no usable man-page description or synopsis is found, the script resolves that value with `command -v` and directly executes the selected program with `--help`. The quoted expansion prevents shell metacharacters inside `cmd` from being interpreted as additional shell syntax, so this is not conventional shell command injection. It nevertheless allows the caller to select an arbitrary executable, including an executable referenced by an absolute path, relative path, or attacker-influenced `PATH`. Passing `--help` does not make an executable safe. A program may ignore that argument and perform arbitrary actions before returning help output. The `|| true` expression only suppresses a nonzero exit status and does not prevent the program's side effects. This behavior also conflicts with the statement in `SKILL.md` that the Skill “does **not** run the command,” potentially causing callers to pass untrusted command names under an incorrect security assumption. The command output is captured without a timeout or size limit. A selected executable can therefore also hang the Skill or generate enough output to consume excessive memory. ### Attack Path 1. An attacker creates or identifies an executable that performs harmful actions regardless of receiving `--help`. 2. The attacker supplies its absolute path, relative path, or name as the first argument to `bin/tldr-cmd`. Alternatively, the attacker plac ...[truncated 1287 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the executable fallback and limit the Skill to parsing trusted, non-executing documentation sources such as locally installed man pages. 2. If fallback execution is an essential feature, use a strict allowlist of commands that have been reviewed as safe to invoke with `--help`. 3. Reject command values containing `/` and validate names against a conservative pattern such as `^[A-Za-z0-9._+-]+$`. This reduces path-based selection but must not replace an allowlist. 4. Resolve allowed commands against trusted system directories rather than an inherited, potentially attacker-controlled `PATH`. 5. Execute any unavoidable fallback in a sandbox with minimal privileges, a sanitized environment, no sensitive working-directory access, restricted filesystem access, disabled network access, and resource limits. 6. Apply a short timeout and a strict output-size limit to prevent hanging processes and memory exhaustion. 7. Update `SKILL.md` to disclose accurately that the fallback executes the requested program. If execution is removed, retain and enforce the existing non-execution guarantee. ]]>
