T09 · Insecure Skill Coding Practices
Error
- Location
- assets/bt-skills/bt-website-troubleshoot/SKILL.md:116
- Finding
- Shell Command Injection and Credential Exposure in Database Diagnostics<![CDATA[ ## Vulnerability Details **File Location**: `assets/bt-skills/bt-website-troubleshoot/SKILL.md`, lines 116–123 **Vulnerability Type**: Unsafe interpolation of untrusted configuration values into shell commands and plaintext password exposure through process arguments **Risk Level**: High ### Vulnerable Code ```text 1. Read `SiteGetConfig` to locate the project root, then find the framework database configuration: - WordPress: `Read: <root>/wp-config.php` → extract `DB_NAME`, `DB_USER`, `DB_PASSWORD`, `DB_HOST`. - Other frameworks: search `.env`, `config/database.php`, `application/database.php`, etc. 2. `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> <DB_NAME> -e "SELECT VERSION()"` → a successful connection returns the MySQL version; otherwise, inspect the error code in the next step. 3. If the connection fails, read the error code from the raw `mysql` client output and apply the following logic: - `2002` / `2003` → MySQL is not running. Proceed to service startup failure → MySQL. - `1045` → The password is incorrect. Compare `DB_PASSWORD` from the configuration with the `databases` table; report any discrepancy without automatically resetting the database password. - `1146` → A database table is missing. Use `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> <DB_NAME> -e "SHOW TABLES"` / `DESC <table>` to confirm. - `1040` → Too many connections. Run `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> -e "SHOW GLOBAL STATUS LIKE 'Threads_connected'; SHOW FULL PROCESSLIST"` to inspect connection counts and sources. ``` ### Technical Analysis The Skill directs the agent to read database connection fields from application-controlled files such as `wp-config.php` and `.env`, and then interpolate those values directly into a command executed through `RunCommand/Bash`. These fields are not guaranteed to be trustworthy. A compromised website, malicious repository, or attacker with write access ...[truncated 3067 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Do not interpolate configuration-derived values into shell command strings.** - Prefer a structured database API or a dedicated MCP database-connectivity tool. - If the `mysql` executable is necessary, invoke it through a process API using an argument array without a shell. 2. **Validate every connection field before use.** - Parse the application configuration using a format-aware parser. - Reject control characters, newlines, NUL bytes, shell metacharacters, and unexpected option prefixes. - Validate ports as integers in the range `1–65535`. - Apply restrictive allowlists for database names and usernames. - Validate hosts as IP addresses, Unix socket paths, or syntactically valid hostnames, as appropriate. 3. **Keep passwords out of command-line arguments.** - Use a narrowly scoped MySQL option file created with mode `0600`, pass it with `--defaults-extra-file`, and delete it immediately after use. - Alternatively, use a database client library that accepts credentials through an in-memory connection object. - Do not place the password in environment variables, command strings, logs, or Agent responses. 4. **Prevent option injection.** - Reject values beginning with `-` where they could be interpreted as command-line options. - Use explicit long-form options and a structured argument vector. - Do not rely solely on quoting generated by the language model. 5. **Minimize privileges.** - Run connectivity checks under an unprivileged service account. - Use a database account limited to the smallest set of read-only diagnostic permissions. - Do not run routine database checks through a root-capable shell when a restricted interface is available. 6. **Harden output handling.** - Redact passwords, tokens, connection strings, and sensitive query output before returning results. - Ensure tool-call arguments are not persisted when they may contain secrets. - Review exist ...[truncated 455 chars]
