Back to skill

Security audit

Construction Assistant

Security checks for vulnerabilities and agentic risk

Overview

This is a local Chinese construction-management helper with disclosed file-based scripts, with some overwrite and record-accuracy bugs but no hidden network, credential, persistence, or privilege behavior.

Install only if you are comfortable with a Chinese-language construction workflow that creates and updates local project files. Use version control or backups for schedules and reports, choose .md output names for material reports, and manually verify generated dates and safety/compliance records before relying on them.

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

Note
Location
scripts/material_summary.py:236
Finding

Unintended Report Overwrite Due to Unsafe Output Path Derivation

Content
View full analysis

Vulnerability Details

File Location: scripts/material_summary.py, lines 236–256
Vulnerability Type: Unsafe file path derivation and unintended file overwrite
Risk Level: Low

Complete Code Snippet

python
if args.output:
    with open(args.output, "w", encoding="utf-8") as f:
        f.write(report)
    print(f"✓ 材料报告已保存:{args.output}")
else:
    print(report)

# 同时输出 JSON 格式便于程序处理
json_output = {
    "period": {
        "start": period_start.strftime("%Y-%m-%d"),
        "end": period_end.strftime("%Y-%m-%d")
    },
    "materials": materials,
    "purchase_plan": purchase_plan
}

if args.output:
    json_path = args.output.replace(".md", ".json")
    with open(json_path, "w", encoding="utf-8") as f:
        json.dump(json_output, f, ensure_ascii=False, indent=2)
    print(f"✓ JSON 数据已保存:{json_path}")

Technical Analysis

The script writes the Markdown report directly to the user-supplied --output path. It then derives a companion JSON path using:

python
json_path = args.output.replace(".md", ".json")

If the output path does not contain the exact substring .md, str.replace() returns the original path unchanged. Consequently, the JSON write targets the same file that was just used for the Markdown report and silently replaces its contents.

The script also opens both destinations in write mode without checking whether the paths are identical or whether an existing file would be overwritten. This is an integrity flaw in local file handling rather than a command-execution, privilege-escalation, or data-exfiltration vulnerability.

Attack Path

  1. Prepare a valid schedule file containing tasks with estimable material requirements.

  2. Invoke the script with an output filename that does not contain .md:

    bash
    python3 scripts/material_summary.py \
      --schedule schedule.json \
      --output report.txt
    
  3. The script ...[truncated 886 chars]

Remediation
View remediation

Remediation Suggestions

  1. Use pathlib.Path.with_suffix() rather than raw string replacement:

    python
    from pathlib import Path
    
    report_path = Path(args.output)
    json_path = report_path.with_suffix(".json")
    
  2. Verify that the two destinations are different before either write:

    python
    if report_path.resolve() == json_path.resolve():
        raise ValueError("Report and JSON output paths must be different")
    
  3. Validate the report extension or require separate explicit options such as --report-output and --json-output.

  4. Avoid silently replacing existing files. Reject an existing destination unless the caller supplies an explicit --overwrite option.

  5. Use atomic writes through temporary files followed by os.replace() after successful serialization, reducing the chance of partially written or corrupted output.

  6. Add regression tests for output names including report.md, report.txt, report, uppercase suffixes, multiple suffixes, and pre-existing destination files.

Vulnerability Patterns
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (9)

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

该代码块的实际功能非常单一,主要是基于预设公式进行工程量计算,并支持命令行参数输入及结果输出到文件。这与声明中的“工程量计算”部分一致,但无法支持其余核心声明能力,如进度计划管理、材料设备管理、安全检查记录、施工日志生成和成本估算。因此,描述将其表述为完整的施工项目管理助手,明显超出了代码实际行为范围,属于描述与行为不一致。

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.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

The script's natural-language interface and descriptions are entirely in Chinese, including the top-level docstring and user-facing help/output strings, without offering any language choice or explaining that the tool is intended only for a Chinese-speaking context. This is a locale-policy concern because the skill effectively imposes a language on all users without opt-in.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

This Python file contains user-facing natural-language strings such as the module docstring, argument descriptions, output template, and status message entirely in Chinese. Under the policy, forcing a specific language without user opt-in is a natural-language policy violation unless the locale constraint is clearly documented and justified, which is not present here.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The function accepts a user-supplied construction date but displays the current system date (today) in the generated log, creating a mismatch between the reported work date and the actual project record. In a construction-management context, daily logs are compliance and evidence documents, so incorrect dates can undermine auditability, delay investigations, and enable accidental or deliberate falsification of site activity records.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
83% confidence
Finding

The instructions repeatedly direct generation and updating of files such as schedule.json, progress_report.md, and daily_log.md without warning about overwriting existing project artifacts. In a file-capable agent environment, this can lead to unintended data loss or corruption if the user does not realize existing outputs may be replaced.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

The file title, section headings, formulas, and usage guidance are all presented only in Chinese. Under the policy, forcing a specific language without user opt-in can be a natural-language policy violation unless the locale constraint is clearly documented and justified.

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 contains user-facing report templates and headings exclusively in Chinese, such as '施工报告模板' and the section labels throughout the file. Under the policy rule for natural-language violations, forcing a specific language without user opt-in can be a locale policy issue unless the regional constraint is explicitly documented and 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
90% confidence
Finding

SQP-3 applies to all file types and covers natural-language locale policy violations. This checklist presents all instructions and labels only in Chinese, which can amount to forcing a specific language on users without explicit opt-in or justification in the file.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.