T09 · Insecure Skill Coding Practices
- Location
scripts/pass-secrets.sh:42- Finding
Shell Command Injection in Generated Environment Export
- Content
View full analysis
Vulnerability Details
File Location:
scripts/pass-secrets.sh, lines 42–46
Vulnerability Type: Shell command injection through unsafe shell-code generation
Risk Level: HighVulnerable Code
bash env) [ -z "$path" ] && { echo "Error: path required"; exit 1; } value=$(pass show "$path" 2>/dev/null) || { echo "Error: secret not found: $path"; exit 1; } var_name=$(basename "$path" | tr '[:lower:]-' '[:upper:]_')_KEY echo "export $var_name=\"$value\"" ;;Technical Analysis
The
envcommand builds executable shell syntax by directly interpolating both a decrypted secret and a path-derived variable name. Neither value is safely encoded for reuse by a shell.A secret containing a double quote, command substitution, backticks, shell operators, or embedded newlines can break out of the quoted assignment when the output is evaluated or sourced. For example, a value containing
"$(malicious_command)"can cause command execution in a shell that evaluates the generated line.The derived variable name is also unsafe.
tronly converts lowercase letters to uppercase and hyphens to underscores; it does not reject spaces, quotes, semicolons, command substitutions, newlines, or other shell metacharacters present in the path basename.Printing the decrypted value to standard output additionally exposes it to terminal capture, logs, command pipelines, and other output collectors. The principal confirmed vulnerability, however, is command injection when the advertised export command is consumed as shell code.
Attack Path
- An attacker gains the ability to influence a stored secret value or secret path, such as through an import process, shared password store, repository synchronization, or another user-assisted workflow.
- The attacker inserts shell syntax into the secret value or the basename of its path.
- The victim runs:
bash scripts/pass-secrets.sh env path
...[truncated 1163 chars]
- Remediation
View remediation
Remediation Suggestions
- Avoid generating shell source code containing decrypted secrets. Prefer returning only the raw secret to a trusted caller or setting the environment variable directly within a controlled process.
- If shell-code generation is required, strictly validate the variable name:
bash [[ "$var_name" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || { echo "Error: invalid environment variable name" >&2 exit 1 } - Serialize the value with Bash-safe escaping rather than interpolating it inside double quotes:
bash printf 'export %s=%q\n' "$var_name" "$value" - Clearly document that generated output must not be evaluated when either the secret path or value originates from an untrusted source.
- Minimize secret exposure by avoiding terminal output where possible and ensuring CI systems, wrappers, and logs do not capture decrypted values.
- Add tests covering quotes, command substitutions, backticks, semicolons, spaces, and multiline values in both secret values and path basenames.
