Back to skill

Security audit

Phy Sql Explainer

Security checks for vulnerabilities and agentic risk

Overview

This SQL helper is mostly coherent, but it can direct an agent to run live database analysis without clear confirmation or safety limits.

Review before installing. Use this skill only for pasted execution plans or clearly approved analysis, and do not let it run EXPLAIN ANALYZE on production or untrusted SQL unless you have confirmed the target database, permissions, statement safety, and resource limits.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Error
Location
SKILL.md:65
Finding

Untrusted SQL May Be Executed During Query Analysis

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 65-83
Vulnerability Type: Unsafe execution of user-controlled SQL through EXPLAIN ANALYZE
Risk Level: High

Vulnerable Code

markdown
## Step 1: Run EXPLAIN ANALYZE

If the user provides a query but no EXPLAIN output, run it:

### PostgreSQL
```sql
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT * FROM orders WHERE user_id = 123 AND status = 'pending';

MySQL

sql
EXPLAIN FORMAT=JSON
SELECT * FROM orders WHERE user_id = 123 AND status = 'pending';

-- Or for runtime stats:
EXPLAIN ANALYZE
SELECT * FROM orders WHERE user_id = 123 AND status = 'pending';
text

### Technical Analysis

The skill instructs the agent to run a user-provided query when no execution plan is supplied. In PostgreSQL and supported MySQL versions, `EXPLAIN ANALYZE` does not merely inspect a statement: it executes the statement to collect runtime statistics.

The instructions do not:

- Restrict analyzed statements to a single read-only `SELECT`.
- Reject DML, DDL, transaction-control statements, or side-effecting stored functions.
- Require an explicit confirmation before executing the statement.
- Require a read-only transaction or least-privileged database account.
- Require execution against a disposable or non-production database.
- Define statement timeouts, lock timeouts, row limits, or resource controls.

Consequently, attacker-controlled SQL could be executed with the privileges of the database account available to the agent. Even syntactically read-only queries may invoke volatile functions, trigger expensive operations, acquire locks, or consume excessive CPU, memory, and I/O.

### Attack Path

1. The agent has access to a database and loads this skill to diagnose SQL performance.
2. An attacker submits a side-effecting or resource-intensive SQL statement while withholding an existing execution plan.
3. The skill directs th
...[truncated 1416 chars]
Remediation
View remediation

Remediation Suggestions

  1. Use non-executing plans by default. Run plain EXPLAIN rather than EXPLAIN ANALYZE for user-provided SQL unless runtime execution is explicitly required.

  2. Require explicit informed confirmation. Before runtime analysis, explain that the statement will execute and obtain confirmation identifying the target database and environment.

  3. Allow only validated read-only statements. Parse SQL using a database-aware parser and permit exactly one approved SELECT statement. Reject DML, DDL, transaction commands, multi-statement input, COPY, administrative commands, and unsafe stored-function calls. Keyword filtering alone is insufficient.

  4. Enforce read-only execution at the database layer. Use a dedicated least-privileged read-only account and a read-only transaction. Do not rely solely on prompt instructions or application-side validation.

  5. Use an isolated environment. Prefer a disposable database, staging environment, or read-only replica containing appropriately sanitized data. Runtime analysis should not default to production.

  6. Add resource limits. Configure statement and lock timeouts, connection limits, workload controls, and temporary-file or memory limits. Cancel queries that exceed defined thresholds.

  7. Use rollback protection where supported. Execute approved analysis in an explicit read-only transaction and roll it back after collecting results. Note that rollback is not a substitute for read-only privileges because some external or volatile side effects may not be transactional.

  8. Document safe behavior directly in the skill. Replace “run it” with a policy such as: “Generate plain EXPLAIN only. Run EXPLAIN ANALYZE solely for a validated read-only query after explicit approval, using a read-only account on a non-production system with strict timeouts.”

Vulnerability Patterns
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (4)

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The description embeds broad trigger phrases such as 'slow query', 'optimize sql', and 'add index' that can match ordinary conversation and cause unintended activation. While not directly exploitable as code execution, overbroad activation can route unrelated database discussions into a skill that recommends or initiates database actions, increasing the chance of unsafe or confusing behavior.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The documented trigger list contains generic phrases like 'database slow' and 'missing index' without clear activation boundaries, which makes accidental triggering likely. In context, this is more concerning because the skill later instructs the agent to run EXPLAIN/EXPLAIN ANALYZE if a database is accessible, so accidental activation could lead to unintended operational actions.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The skill says the agent will run EXPLAIN ANALYZE if the database is accessible, but it does not clearly warn that this may execute against a live database. That is dangerous because EXPLAIN ANALYZE can actually run the query, consuming resources, touching data-modifying statements in some databases, and creating production impact without explicit informed consent.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

These instructions tell the agent to run EXPLAIN/EXPLAIN ANALYZE but omit a user-facing warning that EXPLAIN ANALYZE can impose runtime cost and may be unsafe on production systems. In this skill's context, that materially increases risk because the tool is aimed at diagnosing slow queries, exactly the scenario where re-running expensive queries on production could worsen outages or performance incidents.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.