T09 · Insecure Skill Coding Practices
- Location
SKILL.md:87- Finding
SQL Injection Through Direct Interpolation of Memory Content
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 87-96
Vulnerability Type: SQL injection caused by manual string escaping
Risk Level: HighVulnerable Code
bash sc "SELECT MEMORY_STORE('default', 'Luis prefers dark roast and takes calls after 10am') AS id" \ | jq -r '.data.rows[0][0]' # mem_1kzv0fkzy_AK7TUftext Note the SQL string quoting: **single quotes are strings, double quotes are identifiers.** A double-quoted value is read as a column name and will error. Escape an apostrophe by doubling it — `'Luis''s laptop'`.Technical Analysis
The skill constructs SQL by inserting memory content directly into a quoted SQL string. Although the
schelper usesjqto encode the resulting SQL as JSON, JSON encoding does not parameterize the SQL statement or make its embedded values safe.The documented protection consists only of instructing the agent to double apostrophes. This is error-prone because every caller must correctly identify and escape all attacker-controlled values before constructing the statement. If a memory supplied by a user contains an unescaped quote, it can terminate the intended string literal and alter the surrounding SQL syntax.
The same construction pattern applies to recall queries, namespaces, memory identifiers, and metadata if those values are dynamically substituted into the documented templates. The namespace validation rule is described in prose but is not enforced by the helper.
Attack Path
- An attacker asks the agent to remember text containing SQL control characters and a quote that closes the
MEMORY_STOREcontent argument. - The agent places the text into the documented SQL template without complete SQL-literal escaping.
jqsafely serializes the modified SQL into JSON, but leaves the SQL semantics unchanged.- The helper sends the attacker-influenced statement to
/v1/query/executeusing the configured bearer credentia ...[truncated 1315 chars]
- An attacker asks the agent to remember text containing SQL control characters and a quote that closes the
- Remediation
View remediation
Remediation Suggestions
- Replace SQL string interpolation with a gateway API that supports prepared statements and separately bound parameters.
- If parameter binding is unavailable, provide a single audited helper that converts input into a valid SQL literal. Do not require the agent or user to perform manual escaping.
- Validate namespaces in code against
^[A-Za-z_][A-Za-z0-9_]*$before constructing any query. - Treat memory IDs, recall queries, metadata, and all user-provided content as untrusted input.
- Configure the query endpoint to reject multiple statements and dangerous administrative operations where they are not required.
- Use a least-privilege API key restricted to the necessary memory namespaces and functions.
- Add tests covering apostrophes, comment tokens, statement separators, Unicode quote variants, malformed metadata, and attempted nested expressions.
- Avoid exposing a general-purpose SQL execution endpoint to the skill when purpose-specific memory endpoints can be used instead.
