T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:31
- Finding
- User-Controlled Slug Embedded Directly in an SQLite Query## Vulnerability Details **File Location**: `SKILL.md`, lines 31-38 **Vulnerability Type**: SQL injection through unvalidated query construction **Risk Level**: High ### Vulnerable Code ```bash sqlite3 $DB \ "SELECT c.id, c.front, c.back FROM cards c JOIN decks d ON d.id = c.deck_id JOIN materials m ON m.id = d.material_id WHERE m.slug = 'SLUG' AND c.type = 'argumentative' ORDER BY RANDOM() LIMIT 5;" ``` ### Technical Analysis The skill accepts a slug through the `/algernon debate [SLUG]` command and instructs the agent to substitute it into a quoted SQL statement. No validation, escaping, or parameter binding is required before the value is incorporated into the query. A slug containing a single quote and additional SQL syntax could terminate the intended string literal and change the query semantics. Depending on how the instruction is implemented and which statements the installed `sqlite3` client accepts, this could permit access to unrelated tables or modification of the database. The database is also not explicitly opened in read-only mode, increasing the possible integrity impact. ### Attack Path 1. An attacker supplies a specially crafted value as the debate slug. 2. The agent substitutes that value for `SLUG` in the SQL command. 3. The substituted value terminates the `m.slug` string literal and introduces additional SQL syntax. 4. The local `sqlite3` process executes the altered query under the agent user's database permissions. 5. The attacker may cause unrelated records to be returned or, where stacked statements are accepted, attempt to modify accessible database content. ### Impact Assessment Successful exploitation could disclose information from other tables in `vestibular.db`, bypass the intended material filter, or damage database integrity. Access is limited to the SQLite database and filesystem permissions of the user running the agent; this finding does not establish privil ...[truncated 35 chars]
- Remediation
- ## Remediation Suggestions - Validate the slug before use with a strict allowlist appropriate to material identifiers, such as `^[A-Za-z0-9_-]+$`. - Reject empty, malformed, or unexpectedly long values. - Replace shell-based SQL interpolation with a database API that supports bound parameters. - Open the database in read-only mode for this operation. - Run the query using an account with access only to the required database. - If the `sqlite3` CLI must be retained, resolve the slug against a trusted list rather than inserting raw user input into SQL.
