Back to skill

Security audit

data-analysis-sql

Security checks for vulnerabilities and agentic risk

Overview

This SQL/data-analysis skill is mostly coherent, but it needs Review because one reusable multi-tenant SQL template can produce unsafe tenant-mixing queries and some document-generation triggers are overbroad.

Review generated SQL before use, especially every JOIN in multi-tenant data, and require tenant filters wherever tenant-bearing tables are involved. Avoid using the broad document-generation triggers on private spreadsheets, schemas, or metric SQL unless the user explicitly wants those materials summarized or written to a chosen path.

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
references/business-metrics.md:202
Finding

Missing Tenant Isolation in Defect-Density SQL Template

Content
View full analysis

Vulnerability Details

File Location: references/business-metrics.md, lines 202-230
Vulnerability Type: Cross-tenant data association caused by incomplete join predicates
Risk Level: High

Vulnerable Code

sql
item_case AS (
    -- Items associated with test cases
    SELECT DISTINCT
        b."tenantkey",
        b."objectid"          AS item_id,
        fs."actual_finish_ts",
        rel."{case_id_field}"
    FROM base_items b
    INNER JOIN finished_status fs
        ON b."tenantkey" = fs."tenantkey"
       AND b."objectid"  = fs."objectid"
    INNER JOIN {schema}."{case_item_rel_table}" rel
        ON b."{key_field}" = rel."{item_fk_field}"
       AND rel."del_flag" = 0
),
case_defect AS (
    -- Test cases associated with defects through execution records
    SELECT DISTINCT
        ic."tenantkey",
        ic."item_id",
        ic."actual_finish_ts",
        dcr."{defect_id_field}"
    FROM item_case ic
    INNER JOIN {schema}."{exec_table}" ce
        ON ce."{case_id_field}" = ic."{case_id_field}"
    INNER JOIN {schema}."{defect_case_rel_table}" dcr
        ON ce."{exec_id_field}" = dcr."{case_id_field}"
       AND dcr."del_flag" = 0
),

Technical Analysis

The defect-density template carries b."tenantkey" into the item_case CTE, but three subsequent joins rely only on item, case, or execution identifiers:

  1. b."{key_field}" = rel."{item_fk_field}"
  2. ce."{case_id_field}" = ic."{case_id_field}"
  3. ce."{exec_id_field}" = dcr."{case_id_field}"

No tenant predicate constrains these joins. If the identifiers are unique only within a tenant rather than globally, rows belonging to another tenant can match the current tenant's records.

The resulting foreign records inherit ic."tenantkey" from the current tenant rather than retaining or validating their actual tenant ownership. This can make cross-tenant records appear to belong to the current tenant in the final aggregation.

This behavior directly conflicts with the ...[truncated 1870 chars]

Remediation
View remediation

Remediation Suggestions

  1. Add tenant predicates to every join where the joined table contains a tenant identifier:
sql
INNER JOIN {schema}."{exec_table}" ce
    ON ce."{case_id_field}" = ic."{case_id_field}"
   AND ce."tenantkey" = ic."tenantkey"

INNER JOIN {schema}."{defect_case_rel_table}" dcr
    ON ce."{exec_id_field}" = dcr."{case_id_field}"
   AND dcr."tenantkey" = ic."tenantkey"
   AND dcr."del_flag" = 0
  1. If {case_item_rel_table} has a tenant column, enforce it directly:
sql
INNER JOIN {schema}."{case_item_rel_table}" rel
    ON b."{key_field}" = rel."{item_fk_field}"
   AND rel."tenantkey" = b."tenantkey"
   AND rel."del_flag" = 0
  1. If a relationship table genuinely has no tenant column, resolve it through a tenant-scoped authoritative parent table before using it. Do not assume that carrying the main table's tenant key into the result proves ownership of the joined row.

  2. Require and document global uniqueness constraints if tenant-scoped joins are impossible. Such constraints should be enforced by the database rather than assumed by the template.

  3. Add automated regression tests containing two tenants with deliberately duplicated item keys, case IDs, and execution IDs. Verify that each tenant's output contains only its own defects.

  4. Add a static SQL review rule that flags joins between tenant-bearing tables when no tenant equality predicate is present.

  5. Apply row-level security or tenant-filtered database views as defense in depth so that malformed analytical SQL cannot read records outside the authorized tenant.

Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (24)

Tp4

High
Category
MCP Tool Poisoning
Confidence
94% confidence
Finding

The declared description presents a comprehensive big-data SQL and data-engineering skill with many capabilities across modeling, optimization, ETL, documentation, and migration. The supplied code instead has a much narrower and different primary purpose: comparing two SQL statements and reporting structural/logical differences. While SQL diffing could be loosely related to '改SQL' or debugging workflows, it does not implement most of the declared capabilities, and its primary behavior is not accurately represented by the broad description. There is no evidence of external resource access or dangerous undeclared permissions, but the description materially overstates and mischaracterizes the actual functionality.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

声明描述的是一个覆盖面极广的大数据与SQL工程技能,而实际代码只是单一的SQL formatter 脚本,不进行SQL执行、分析、优化、建模、文档生成或知识库维护。虽然“改SQL”这一触发词与格式化存在轻微关联,但这不足以支撑声明中的主要能力范围。因此描述与实际行为存在明显且实质性的不匹配。

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The file title and the entire skill documentation are presented in Chinese only, with no indication that users may choose another language or that the skill is intentionally restricted to a Chinese-speaking environment. Under the policy provided, forcing a specific language without user opt-in is a natural-language policy concern.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The trigger phrases are broad enough to match routine conversation such as '整理文档', '生成md', or '沉淀一下', which can cause this skill to activate outside clearly data-SQL-specific contexts. In an agent system, unintended activation can override more appropriate skills, pull in unnecessary repository context, or cause the agent to generate file/document outputs when the user did not intend to invoke this capability.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
70% confidence
Finding

Without declared permissions the skill's intent is opaque and cannot be validated.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The trigger phrases are extremely broad, including common requests like writing SQL, generating markdown, organizing documents, and maintaining a knowledge base. Overbroad activation can cause the skill to engage in contexts beyond the user's intent, increasing the chance of unintended file generation, mishandling sensitive schema/business data, or unsafe automation in unrelated conversations.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
85% confidence
Finding

The skill metadata and body are entirely written in Chinese and present the skill as Chinese-language by default, with no indication that users may choose another language. Under the policy, a language or locale constraint should either be user-selectable or explicitly justified as region-specific.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The document-generation guidance is ambiguous and lacks limits on input sources, output locations, sensitive-content handling, and whether generated documentation may include schemas, SQL logic, or enumerations copied from private material. In a data-analysis skill, this is more dangerous because inputs often contain confidential table structures, business metrics, and tenant-specific logic that could be broadly transformed into exportable markdown without clear safeguards.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The document is written entirely in Chinese, including headings, instructions, and comments, with no indication that users may choose another language. Under the stated policy, forcing a specific language without user opt-in is a natural-language policy violation unless the locale constraint is explicitly justified.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The file title and all explanatory natural-language content are written in Chinese, with no indication that other languages are supported or that the locale restriction is intentional. Under the stated policy, forcing a specific language without user opt-in is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The trigger phrases are overly broad and overlap with common user language such as '整理一下', '生成文档', and '写个文档'. In an agent skill, this can cause unintended activation on ordinary conversation or unrelated requests, leading to incorrect tool invocation, unwanted document generation, or processing of sensitive SQL/schema content without clear user intent.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
87% confidence
Finding

The file is written entirely in Chinese and presents the rules as mandatory guidance for all applicable SQL writing, but it does not indicate that language choice is optional or limited to a justified Chinese-only context. Under the policy, forcing a specific language without user opt-in can be a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

This Python file is a code file, so SQP-3 applies to its docstrings and user-facing strings. The top-level description and usage text are only provided in Chinese, with no indication that other languages are supported or that Chinese is a required locale, which can violate a language/locale policy requiring user choice or explicit justification.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The user-facing console messages, prompts, and help output are all in Chinese, and the script provides no locale selection or opt-in mechanism. Under SQP-3, this is a natural-language policy concern because the skill enforces a specific language across its interface without documenting a justified regional constraint.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

This markdown file contains user-facing instructional content exclusively in Chinese. Under the policy, forcing a specific language without user opt-in can be a natural-language policy violation when no locale choice or justification is provided.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
84% confidence
Finding

整份技能说明与输出模板均固定为中文表述,未说明是否支持按用户偏好切换语言,也未提供用户选择语言的机制。对于通用文档生成技能,这可能构成未经用户选择即强制特定语言的自然语言策略问题。

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
93% confidence
Finding

The instruction '统一使用英文命名' imposes a specific language policy for folder names. Under the stated policy rules, forcing a language without user opt-in or a documented justification is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

This markdown skill/reference forces a specific language presentation for all users, and there is no indication that Chinese is optional or that the document is intended only for a Chinese-language audience. The policy specifically calls for flagging language or locale constraints when they are imposed without user opt-in or clear justification.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
93% confidence
Finding

This markdown file presents all instructions and examples in Chinese, which can amount to a language/locale policy issue when no user opt-in or alternative language option is provided. The content does not indicate that the skill is region-specific or intentionally limited to Chinese-speaking users.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
94% confidence
Finding

This markdown file contains user-facing instructional content exclusively in Chinese, beginning with the title and continuing throughout the document. Under the policy, forcing a specific language without user opt-in can be a natural-language policy violation unless the locale restriction is explicitly justified, which is not present here.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

This markdown file contains user-facing instructional content only in Chinese, and there is no note offering alternative languages or stating that the language is intentionally region-specific. Per the policy, forcing a specific language without user opt-in can be a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

This markdown file is written entirely in Chinese and begins with a Chinese-only title, with no indication that another language is available or that the content is intentionally limited to a Chinese-speaking audience. Under the stated policy, forcing a specific language without user opt-in is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
94% confidence
Finding

The file’s description and usage text are written only in Chinese, and the script later prints all user-facing messages in Chinese as well. This imposes a specific language on users without any visible opt-in or documented locale constraint, which matches the language/locale policy violation category.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
94% confidence
Finding

This code file contains natural-language documentation entirely in Chinese, including the tool description and usage instructions. The policy requires avoiding forced language or locale constraints unless the skill offers user choice or clearly documents a justified regional requirement, which is not present here.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.