Back to skill

Security audit

KWDB Troubleshooting

Security checks for vulnerabilities and agentic risk

Overview

This KWDB troubleshooting skill is mostly coherent, but it tells agents to run EXPLAIN ANALYZE on supplied SQL without safety limits or explicit approval, which can affect a live database.

Install only for authorized KWDB diagnostics. Before following the performance workflow, require operator approval and run SQL analysis only against a safe target, preferably a read-only account on staging or a replica with timeouts and resource limits. Do not run EXPLAIN ANALYZE on untrusted or mutating SQL in production.

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

Warning
Location
references/key-rules.md:64
Finding

Unprotected execution of user-supplied SQL through EXPLAIN ANALYZE

Content
View full analysis

Vulnerability Details

File Location: references/key-rules.md:64-66; references/triage-playbook.md:20-23; assets/demo-prompts.md:6
Vulnerability Type: Unsafe execution of untrusted diagnostic SQL
Risk Level: Medium

Vulnerable Code

references/key-rules.md:64-66:

markdown
- performance issue with a user-provided slow SQL statement: start from `EXPLAIN ANALYZE`
- performance issue without a confirmed slow SQL statement: start from the `query-metrics-history` tool results
- slow SQL identified after metrics analysis: use `EXPLAIN ANALYZE`

references/triage-playbook.md:20-23:

markdown
3. if the user already provided the slow SQL statement, go directly to `EXPLAIN ANALYZE`
4. if no slow SQL statement is confirmed, call the `kwdb-mcp-server` `query-metrics-history` tool for the fault time window
5. decide whether the first hard bottleneck is CPU, IO, memory, or slow SQL
6. if slow SQL is primary, capture the SQL text and run `EXPLAIN ANALYZE` when possible

assets/demo-prompts.md:6:

markdown
- 这是一次性能问题,用户已经提供慢 SQL。请直接用 `EXPLAIN ANALYZE` 定位瓶颈,并输出通用诊断报告。

The last snippet instructs the agent to use EXPLAIN ANALYZE directly when a slow SQL statement has been supplied.

Technical Analysis

Unlike plain EXPLAIN, EXPLAIN ANALYZE executes the underlying SQL statement to collect runtime statistics. The skill directs the agent to apply it directly to user-provided SQL but does not require the statement to be parsed and verified as read-only. It also does not require explicit execution approval, reject multiple statements, restrict the target to a test environment or read replica, or impose statement, lock, and resource limits.

Consequently, an incident submitter can present a mutating, locking, or computationally expensive statement as “slow SQL.” If an agent or operator follows the skill against a live database, the statement executes with the privileges of the ...[truncated 1771 chars]

Remediation
View remediation

Remediation Suggestions

  1. Make plain EXPLAIN the default diagnostic operation because it does not execute the underlying statement.
  2. Permit EXPLAIN ANALYZE only after parsing and verifying that the input is exactly one read-only statement. Reject multi-statement input and all DDL, DML, administrative, and transaction-control operations.
  3. Require explicit user approval immediately before runtime execution, identifying the target cluster, database, statement, and execution risks.
  4. Prefer a staging environment or read replica containing representative statistics and data. Do not default to a production primary.
  5. Use a dedicated least-privilege, read-only database account with no schema-modification, write, administrative, or role-management permissions.
  6. Apply strict statement and lock timeouts, resource limits, concurrency controls, and result-size limits.
  7. Where supported, use a read-only, rollback-only transaction and verify that the session cannot perform writes.
  8. Require the operator to review the plain execution plan and estimated cost before authorizing runtime analysis.
  9. Update the cited rule, playbook, and demonstration prompt consistently so none of them instructs the agent to execute user-provided SQL directly.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • System Prompt LeakageDirect Leakage, Indirect Extraction, Tool-Based Exfiltration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (10)

Direct Prompt Extraction

High
Category
System Prompt Leakage
Confidence
85% confidence
Finding

Skill contains instructions that could directly expose system prompts, internal rules, or hidden instructions to users or external parties.

Content

Scanner excerpt · references/key-rules.md (reported line 77)May include surrounding context.

md
- use git history only when source access is available, the code path is already confirmed, and the user explicitly asks for history attribution
- do not claim a causal branch or commit unless the code path and symptom both match

## Output Rules

- always reply in Chinese
- if the user does not specify a template, use the general diagnostic report

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The skill explicitly requires answering in Chinese regardless of the user's preference, which overrides normal user-driven language selection. This can reduce usability, create confusion in incident response, and increase the chance of operator error if the requester cannot reliably read Chinese, though it does not directly enable code execution or data exfiltration.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

Line L34 instructs the skill to use a Chinese phrase (高度吻合某类已知问题模式) as part of its output. This imposes a specific language in user-facing content without any indication that the user can opt in or choose their preferred language, which matches the locale-policy violation criteria.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The skill hard-codes a language constraint with 'always reply in Chinese', which overrides user preference and can cause unsafe or unusable interactions for users who cannot read Chinese. In a troubleshooting skill, this can distort incident handling by preventing clear communication, user verification, or accurate relay of diagnostic steps and findings.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

This instruction forces responses to be in Chinese regardless of the user's language or preference. While not a direct code-execution or data-exfiltration issue, it can undermine usability, informed review, and safe incident handling if operators cannot accurately understand the output during troubleshooting.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The seven-section mode repeats the same hard requirement to always reply in Chinese without user opt-in. In an incident-response context, rigid language constraints can cause misunderstanding, delay handoff, and reduce the effectiveness of human review across multilingual teams.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
95% confidence
Finding

The demo prompts are entirely written as imperative Chinese instructions and prescribe fixed output behavior, such as producing a diagnostic report and a fixed seven-part format. This can constitute a language/locale policy violation when the skill does not provide any user opt-in or alternative language choice.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
97% confidence
Finding

This markdown template presents all operational instructions and placeholders in Chinese, which can impose a specific language on users without opt-in. The file does not indicate that it is intended only for a Chinese-speaking or region-specific audience, nor does it offer an alternative language.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
95% confidence
Finding

This markdown template presents all user-facing instructions in Chinese and does not indicate that the skill is region-specific or that users may choose another language. Under the language/locale policy rule, forcing a specific language without opt-in is a natural-language policy concern.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
82% confidence
Finding

This is a markdown file, so SQP-2 applies to missing warnings in the skill description. The steps direct the operator to call kwdb-mcp-server query-metrics-history and to capture SQL text, which may expose sensitive workload or user data, but the document provides no caution about data sensitivity, privacy, or limiting collection to what is necessary.

Content

No source excerpt is available for this finding.