T09 · Insecure Skill Coding Practices
- Location
scripts/setup.sh:39- Finding
Persistent Shell Command Injection Through Unescaped Credential Values
- Content
View full analysis
Vulnerability Details
File Location:
scripts/setup.sh, lines 39, 52, and 101–102
Vulnerability Type: Shell command injection through unsafe shell-profile generation
Risk Level: HighVulnerable Code
bash read -p "User Key: " USER_KEYbash read -p "MCP Key: " MCP_KEYbash echo "export MEEGLE_USER_KEY=\"$USER_KEY\"" >> "$SHELL_CONFIG" echo "export MEEGLE_MCP_KEY=\"$MCP_KEY\"" >> "$SHELL_CONFIG"Technical Analysis
The setup script incorporates raw credential input into an executable shell initialization file such as
.bashrc,.bash_profile, or.zshrc. It does not validate or safely encode the values before writing them.Shell metacharacters contained in a credential therefore become part of the generated shell program. For example, a supplied value containing:
bash "; attacker_command; #produces a profile entry equivalent to:
bash export MEEGLE_USER_KEY=""; attacker_command; #"Command substitutions can also be persisted inside the quoted assignment:
bash $(attacker_command)Variable expansion performed by the setup script does not immediately evaluate command-substitution syntax contained in the variable. However, the syntax is written literally to the profile and is evaluated when the shell later sources that file.
Because shell profiles are automatically loaded by new interactive or login shells, this flaw creates a persistent code-execution condition rather than a one-time malformed configuration.
Attack Path
- An attacker distributes or presents a crafted value as a purported Meegle User Key or MCP Key.
- The user runs
scripts/setup.sh. - The user pastes the crafted value into one of the credential prompts.
- The script writes the unescaped value into
.bashrc,.bash_profile, or.zshrc. - The user starts a new shell or manually sources the affected profile.
- The injected shell comman ...[truncated 782 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not construct executable shell-profile statements from raw user input.
- Prefer a dedicated secret manager, operating-system credential store, or permission-restricted configuration file rather than shell initialization files.
- If shell-profile persistence is unavoidable, serialize values with a reliable shell-escaping mechanism such as Bash
printf '%q'. - Reject newline characters, control characters, and other invalid credential characters before storing values.
- Write configuration updates to a temporary file with restrictive permissions and replace the destination atomically after successful validation.
- Avoid broad substring deletion with
sed; use a clearly delimited, application-owned configuration block. - Add automated tests using values containing quotes, semicolons, dollar signs, backticks, command substitutions, backslashes, and whitespace.
