Back to skill

Security audit

历史基线分析

Security checks for vulnerabilities and agentic risk

Overview

The skill has a coherent store-sales analysis purpose, but it uses unsafe database query construction and loads an unreviewed external module from a hard-coded local path.

Review this skill before installing in any environment with real store data. It should use parameterized queries, validate store/date inputs, run with read-only least-privilege database access, remove the hard-coded external import path, and accurately document that week/month analysis is not implemented yet.

Vulnerability Patterns
  • Tool Hijacking and SpoofingModifies or replaces tools so legitimate-looking calls execute attacker logic
  • 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
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
analyze.py:110
Finding

SQL Injection Through Direct Interpolation of Database Query Parameters

Content
View full analysis

Vulnerability Details

File Location: analyze.py:110-125, analyze.py:152-168, and analyze.py:179-192
Vulnerability Type: SQL injection
Risk Level: High

Vulnerable Code

python
def fetch_daily_data(store_id: str, from_date: str, to_date: str) -> List[Dict]:
    """
    获取日粒度历史数据
    
    数据源:v_gmv_daily_by_store
    """
    sql = f"""
        SELECT 
            biz_date,
            weekday_name,
            deal_amount,
            order_count,
            customer_unit_price,
            deal_attach_rate,
            deal_discount
        FROM v_gmv_daily_by_store
        WHERE store_id = '{store_id}'
          AND biz_date BETWEEN '{from_date}' AND '{to_date}'
        ORDER BY biz_date
    """
    
    result = query_database(sql)
python
def fetch_weekly_data(store_id: str, from_date: str, to_date: str) -> List[Dict]:
    """
    获取周粒度历史数据
    
    数据源:v_gmv_weekly_by_store
    """
    sql = f"""
        SELECT 
            year_week,
            week_start_date,
            week_end_date,
            deal_amount,
            order_count,
            customer_unit_price,
            deal_attach_rate
        FROM v_gmv_weekly_by_store
        WHERE store_id = '{store_id}'
          AND week_start_date >= '{from_date}'
          AND week_end_date <= '{to_date}'
        ORDER BY year_week
    """
    
    result = query_database(sql)
python
def fetch_monthly_data(store_id: str, from_date: str, to_date: str) -> List[Dict]:
    """
    获取月粒度历史数据
    
    数据源:v_gmv_monthly_by_store
    """
    sql = f"""
        SELECT 
            year_month,
            deal_amount,
            order_count,
            customer_unit_price,
            deal_attach_rate
        FROM v_gmv_monthly_by_store
        WHERE store_id = '{store_id}'
          AND year_month BETWEEN '{from_date[:7]}' AND '
...[truncated 2278 chars]
Remediation
View remediation

Remediation Suggestions

  1. Replace f-string SQL construction with parameterized queries supported by the database client:

    python
    sql = """
        SELECT biz_date, weekday_name, deal_amount, order_count,
               customer_unit_price, deal_attach_rate, deal_discount
        FROM v_gmv_daily_by_store
        WHERE store_id = :store_id
          AND biz_date BETWEEN :from_date AND :to_date
        ORDER BY biz_date
    """
    result = query_database(
        sql,
        {
            "store_id": store_id,
            "from_date": from_date,
            "to_date": to_date,
        },
    )
    

    Adapt placeholder syntax to the actual database driver. Parameterization must occur in the database client rather than through manual quoting or string replacement.

  2. Validate store_id against the application's canonical identifier format and reject unexpected characters or lengths.

  3. Parse every date parameter with datetime.strptime(value, "%Y-%m-%d") before it reaches query construction, including calls made directly to exported fetch functions.

  4. Enforce server-side authorization so the authenticated caller can query only permitted store IDs. Input validation alone is not an authorization control.

  5. Configure the database identity as read-only and grant access only to the required views.

  6. Make the fetch functions internal if direct external invocation is unnecessary, and add tests proving that quote characters and SQL metacharacters cannot alter query structure.

T07 · Tool Hijacking and Spoofing

Warning
Location
analyze.py:20
Finding

Arbitrary Module Execution Through a Hard-Coded High-Priority Import Path

Content
View full analysis

Vulnerability Details

File Location: analyze.py:20-21
Vulnerability Type: Python import-path hijacking
Risk Level: Medium

Vulnerable Code

python
sys.path.insert(0, '/Users/yangguangwei/.openclaw/workspace-front-door')
from api_client import query_database

Technical Analysis

The Skill prepends a user-specific directory outside the audited project to sys.path. Index zero has the highest normal import priority, so Python resolves api_client from that external location before considering other installed modules.

Importing a Python module executes its top-level code. Consequently, anyone able to create or replace api_client.py, or an equivalent package, in the referenced directory can cause arbitrary Python code to execute when analyze.py is imported. The external module was not included in the audited project, so its integrity and behavior cannot be established from the reviewed files.

This also creates a portability and integrity problem: the Skill's effective behavior depends on mutable code located outside the package and outside its declared dependency boundary.

Attack Path

  1. An attacker gains write access to /Users/yangguangwei/.openclaw/workspace-front-door, or compromises a process that can modify files there.
  2. The attacker creates or replaces api_client.py with a malicious implementation or malicious module-level initialization code.
  3. A user or agent imports the Skill package.
  4. analyze.py inserts the attacker-controlled directory at the beginning of sys.path.
  5. Python resolves and executes the substituted api_client module.
  6. The malicious module runs with the permissions and accessible credentials of the process hosting the Skill.

Impact Assessment

Successful exploitation provides arbitrary code execution in the Skill host process. The attacker could access environment variables, application credentials, local files, and network resources a ...[truncated 444 chars]

Remediation
View remediation

Remediation Suggestions

  1. Remove the runtime sys.path.insert() call.

  2. Package the database client as an audited project module and use an explicit package-relative import, for example:

    python
    from .api_client import query_database
    
  3. If the client is a third-party dependency, declare and pin it through the project's dependency management mechanism. Install it from a trusted package repository with integrity hashes or equivalent provenance controls.

  4. Avoid loading executable dependencies from user-writable directories. Ensure package and virtual-environment paths are writable only by trusted deployment identities.

  5. Verify the source and integrity of the existing external api_client before deployment because its implementation was outside this audit's scope.

  6. Run the Skill under a least-privileged service account with restricted filesystem, credential, and network access to reduce the impact of any future import compromise.

Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (9)

Tp4

High
Category
MCP Tool Poisoning
Confidence
97% confidence
Finding

总体目的与描述基本一致,都是门店历史基线分析,且数据源也与声明一致。但描述把多周期、多基线类型能力表述为已提供的核心能力,而实际代码只有weekday(日数据按星期几)分析真正可用。fetch_weekly_data 和 fetch_monthly_data 是占位实现,analyze 对 week/month 也没有完成计算逻辑,只返回框架提示,因此这是对核心能力的实质性高报。另一方面,analyze_current_vs_baseline 提供了“当前业绩是否正常”及简单归因分析,这与触发条件中的异常识别场景相关,但作为代码能力看属于描述未充分声明的附加能力。综合判断,存在明显描述与行为不一致。

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

Natural-language content in the description and trigger conditions is presented only in Chinese, which can impose a language-specific experience without explicit user opt-in. The file does not state that the skill is region-specific or provide an alternative language option.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The trigger section uses broad natural-language examples such as '和历史比怎么样', '周一通常卖多少', and '今天的业绩正常吗' without defining boundaries for when this skill should activate versus other analytics skills. There are no exclusion conditions or negative examples, so the invocation scope is underspecified.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The module title, descriptions, comments, and user-facing output strings are Chinese-only, which effectively enforces a specific language without any opt-in or explanation. The policy allows locale constraints only when they are optional or clearly justified as region-specific.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

This code builds and executes a database query using user-supplied identifiers and date ranges, which causes store-related data to be retrieved and transmitted to an external API client. Although the function has an internal docstring, there is no user-facing confirmation, warning, or visible disclosure that data will be sent to a database access layer.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The fetch_weekly_data() and fetch_monthly_data() docstrings explicitly say they retrieve weekly/monthly historical data from the corresponding views. However, both functions execute a query and then return an empty list with a placeholder comment, which directly contradicts the documented intent of the functions.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
84% confidence
Finding

These helper functions query weekly and monthly database views through the API client, but they do not provide any user-visible notice that business data will be fetched from backend systems. The current comments and docstrings are developer-oriented and do not satisfy the requirement for user disclosure.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The manifest advertises multiple baseline types including weekday, natural week, and natural month, and the module docstring also lists weekly/monthly data sources. In the main analyze() path, only the weekday branch performs actual analysis; all other baseline types fall through to a TODO placeholder response, so the implemented behavior does not match the described capability.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

The natural-language documentation in this file is entirely Chinese, including the feature list and usage examples. Under the policy criteria, forcing a specific language without opt-in or a stated regional/compliance justification can be a language-policy violation.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.