T09 · Insecure Skill Coding Practices
- Location
SKILL.md:57- Finding
Unqualified EXPLAIN ANALYZE Guidance Can Execute State-Changing SQL
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 57–62
Vulnerability Type: Unsafe execution guidance for arbitrary SQL
Risk Level: HighComplete Code Snippet:
sql -- The agent recommends running: EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) <your query>; -- For even more detail: EXPLAIN (ANALYZE, BUFFERS, VERBOSE, SETTINGS, WAL, FORMAT TEXT) <your query>;Technical Analysis
PostgreSQL's
EXPLAIN ANALYZEdoes not merely inspect a statement. It executes the supplied SQL and collects runtime measurements. The skill accepts arbitrary slow SQL but recommends this command without restricting it to read-only statements, validating the statement type, requiring a non-production environment, or placing execution inside a rollback transaction.Consequently, using this guidance with
INSERT,UPDATE,DELETE,MERGE, or SQL that invokes side-effecting functions can change database state. Even read-oriented statements can consume substantial resources or acquire locks when executed against large production datasets.Attack Path
- An attacker or another untrusted source supplies a state-changing or resource-intensive SQL statement as a query-optimization request.
- The skill recommends wrapping the supplied statement in
EXPLAIN (ANALYZE, BUFFERS). - A user executes the generated command against a live PostgreSQL database.
- PostgreSQL executes the underlying statement.
- The statement modifies data, invokes triggers or side-effecting functions, acquires disruptive locks, or exhausts database resources.
Impact Assessment
The operation runs with the privileges of the database role used by the user. It does not independently elevate privileges, but it may exercise every data-access and mutation privilege already granted to that role.
Potential scope includes unauthorized or unintended insertion, modification, or deletion of accessible records; trigger execution; lock contention; excessive CPU, memory, an ...[truncated 138 chars]
- Remediation
View remediation
Remediation Suggestions
- Inspect and classify the SQL statement before recommending
EXPLAIN ANALYZE. - For untrusted or state-changing SQL, recommend plain
EXPLAINfirst because it does not execute the statement. - Require runtime analysis of mutation statements to occur on an isolated staging database populated with non-sensitive test data.
- Where transaction rollback is appropriate, provide guarded instructions such as:
sql BEGIN; SET LOCAL statement_timeout = '30s'; EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) <statement>; ROLLBACK;- Explicitly warn that rollback does not neutralize every possible side effect, including sequence changes, external calls made by functions, autonomous external effects, and resource consumption.
- Recommend a least-privileged database role, a restrictive
statement_timeout, and appropriate lock and resource limits. - Require explicit confirmation before analyzing any non-
SELECTstatement on a live database.
- Inspect and classify the SQL statement before recommending
