T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:63
- Finding
- Unsafe SQL Construction with User-Controlled Note Content and Search Terms## Vulnerability Details **File Location**: `SKILL.md`, lines 63 and 68 **Vulnerability Type**: SQL injection through direct interpolation of user-controlled values **Risk Level**: High ### Vulnerable Code ```sql INSERT INTO notes (content) VALUES ('优化后的笔记内容'); ``` ```sql SELECT * FROM notes WHERE content LIKE '%关键词%'; ``` ### Technical Analysis The skill documentation instructs the agent to embed optimized note content and search keywords directly into SQL string literals. Both values originate from user input, but the documented queries do not use parameter binding or define an escaping procedure. A single quote in ordinary note content can cause a syntax error. More deliberately crafted input could terminate the original string literal and append attacker-selected SQL. Whether stacked statements can execute depends on the SQLite interface used by the host agent, which is not included in the audited project. Even when stacked statements are rejected, unsafe interpolation can still permit query manipulation or denial of service. ### Attack Path 1. An attacker asks the agent to create a note or search for a keyword containing a quote and malicious SQL syntax. 2. The agent follows `SKILL.md` and places that value directly inside the documented SQL literal. 3. The resulting SQL changes structure rather than treating the complete value as data. 4. The SQLite execution layer evaluates the modified query. 5. Depending on the database API and permissions, the attacker may manipulate query results, corrupt or delete notes, modify archive state, or disrupt note operations. Example malicious note content, assuming the execution interface permits multiple statements: ```text '); DELETE FROM notes; -- ``` This could produce: ```sql INSERT INTO notes (content) VALUES (''); DELETE FROM notes; --'); ``` ### Impact Assessment Exploitation is limited to the permissions of the process executing SQLite operat ...[truncated 705 chars]
- Remediation
- ## Remediation Suggestions Use parameterized statements for every user-controlled value. Do not ask the agent to generate SQL by concatenating or interpolating note content or search terms. For example, with Python's `sqlite3` API: ```python connection.execute( "INSERT INTO notes (content) VALUES (?)", (optimized_content,), ) connection.execute( "SELECT * FROM notes WHERE content LIKE ?", (f"%{keyword}%",), ) ``` Additional hardening measures should include: 1. Encapsulate all database operations in reviewed scripts rather than having the agent construct arbitrary SQL. 2. Expose narrowly scoped operations such as `add`, `search`, `list`, and `archive`. 3. Validate note IDs as integers before using them in archive or lookup operations. 4. Reject operation types outside an explicit allowlist. 5. Execute only one prepared statement per operation. 6. Run database operations with the minimum filesystem permissions required. 7. Maintain protected backups and test restoration procedures. 8. Add tests using quotes, SQL metacharacters, comment sequences, and attempted stacked statements.
