T09 · Insecure Skill Coding Practices
- Location
scripts/cli.sh:17- Finding
Persistent Shell Command Injection Through the Stored Authentication Token
- Content
View full analysis
" exit 1 fi } ``` ```bash # Save config with secure permissions mkdir -p "$HOME/.fiu-market" echo "export FIU_MCP_TOKEN=\"$TOKEN\"" > "$CONFIG_FILE" chmod 600 "$CONFIG_FILE" # Secure: only owner can read ``` The installer uses the same unsafe serialization pattern: ```bash TOKEN="$1" CONFIG_DIR="$HOME/.fiu-market" CONFIG_FILE="$CONFIG_DIR/config" # Create config directory mkdir -p "$CONFIG_DIR" # Save token echo "export FIU_MCP_TOKEN=\"$TOKEN\"" > "$CONFIG_FILE" ``` ### Technical Analysis The setup argument is embedded directly inside executable shell syntax without escaping or validation. The resulting file is later executed with `source`, rather than parsed as data. A malicious value can close the double-quoted assignment and append shell commands. For example, a token shaped like the following would create executable configuration content: ```text "; attacker_command; # ``` The generated file would be equivalent to: ```bash export FIU_MCP_TOKEN=""; attacker_command; #" ``` Restricting the file to mode `600` does not prevent exploitation because the commands are written and subsequently executed by the file owner. The vulnerability creates a persistent execution path: setup stores the payload, while a later command triggers it. ### Attack Path 1. An attacker persuades a user or Agent to run `setup` with a crafted token. 2. `cmd_setup` writes the token into `~/.fiu-market/config` as shell source code. 3. The user subsequently invokes `status`, `test`, `discover` ...[truncated 645 chars]- Remediation
View remediation
"$CONFIG_FILE" chmod 600 "$CONFIG_FILE" ``` 3. Read the value without shell evaluation: ```bash IFS= read -r FIU_MCP_TOKEN < "$CONFIG_FILE" export FIU_MCP_TOKEN ``` 4. Validate the supplied token against the expected JWT character set and structure before storing it. 5. Use `printf '%s'` instead of `echo` to avoid option and escape-sequence ambiguities. 6. Prefer an operating-system credential store or an environment-variable reference in MCP configuration. 7. Remove or migrate existing executable configuration files. Users should rotate tokens if an untrusted setup value may have been used. ]]>
