Back to skill

Security audit

知识库健康度检测

Security checks for vulnerabilities and agentic risk

Overview

The skill’s stated knowledge-base review purpose is coherent, but its file-reading helper has an under-scoped path check that could expose unintended local files in some setups.

Review this skill before installing in shared, multi-user, or sensitive workspaces. It should be acceptable only if you control the input paths and files; the file reader should be hardened with canonical path checks and pinned dependencies before use with untrusted files or agents.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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

Warning
Location
scripts/read_file.py:27
Finding

Path Containment Bypass Enables Unauthorized Local File Disclosure

Content
View full analysis

Vulnerability Details

File Location: scripts/read_file.py, lines 27–42
Vulnerability Type: Improper path containment validation
Risk Level: Medium

Vulnerable Code:

python
def validate_file_path(file_path):
    abs_path = os.path.abspath(file_path)
    script_dir = os.path.dirname(os.path.abspath(__file__))
    skill_dir = os.path.dirname(script_dir)
    project_root = os.path.dirname(skill_dir)
    if not abs_path.startswith(project_root):
        raise ValueError("错误:文件路径超出允许范围")
    if not os.path.exists(abs_path):
        raise FileNotFoundError("错误:文件不存在")
    if os.path.isdir(abs_path):
        raise ValueError("错误:路径是目录而非文件")
    file_size = os.path.getsize(abs_path)
    if file_size > MAX_FILE_SIZE:
        raise ValueError("错误:文件大小超过限制")
    return abs_path

Technical Analysis

The function attempts to restrict input files to project_root using a string-prefix comparison:

python
abs_path.startswith(project_root)

String prefixes do not represent filesystem containment boundaries. For example, if the permitted root is /tmp/project, a sibling path such as /tmp/project-backup/secret.txt also begins with /tmp/project and passes this check.

In addition, os.path.abspath() normalizes relative path components but does not resolve symbolic links. A symbolic link located under an accepted path can therefore reference a file outside the intended root while still passing the lexical prefix check. The subsequent calls to exists(), getsize(), and open() follow that link.

Once validation succeeds, files with an accepted extension are read and returned in full. In particular, .md, .txt, .json, and .csv files are passed directly to read_text_file().

Attack Path

  1. The attacker identifies the value of the parent directory treated as project_root.
  2. The attacker supplies either:
    • A file in a sibling directory whose path shares ...[truncated 974 chars]
Remediation
View remediation

Remediation Suggestions

Resolve canonical filesystem paths and compare path components rather than string prefixes:

python
from pathlib import Path

def validate_file_path(file_path):
    allowed_root = Path(__file__).resolve().parents[2]
    candidate = Path(file_path).resolve(strict=True)

    if not candidate.is_relative_to(allowed_root):
        raise ValueError("File path is outside the permitted directory")
    if not candidate.is_file():
        raise ValueError("Path is not a regular file")
    if candidate.stat().st_size > MAX_FILE_SIZE:
        raise ValueError("File exceeds the size limit")

    return str(candidate)

Additional hardening measures should include:

  • Define the permitted upload directory explicitly instead of deriving an unnecessarily broad parent directory.
  • Reject symbolic links with Path.is_symlink() if links are not required.
  • Open the file defensively to reduce time-of-check/time-of-use race conditions.
  • Run the Skill under a least-privileged account without access to unrelated secrets.
  • Validate the actual file type rather than relying exclusively on the filename extension.
  • Add tests covering sibling prefix collisions, .. traversal, symbolic links, broken links, and paths outside the allowed root.

T08 · Insecure Dependencies

Note
Location
SKILL.md:89
Finding

Unpinned Third-Party Dependency Installation

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 89–91
Vulnerability Type: Unpinned dependencies without integrity verification
Risk Level: Low

Vulnerable Documentation:

markdown
- **依赖**:`scripts/read_file.py` 需 pandas、openpyxl,安装命令:`pip install pandas openpyxl`

Technical Analysis

The documented installation command retrieves the latest package versions available under the pandas and openpyxl names. It specifies neither reviewed versions nor cryptographic hashes.

The package names are established public packages, and the project does not specify a suspicious package source. Therefore, there is no evidence that the current dependencies are malicious. Nevertheless, the installation is not reproducible and implicitly trusts whatever releases and transitive dependencies are served at installation time.

This creates supply-chain exposure if a future release, package index, dependency, or installation environment is compromised. It can also introduce unexpected compatibility or security regressions without any change to the audited project.

Attack Path

  1. A user follows the documented pip install pandas openpyxl command.
  2. pip resolves current package versions and their transitive dependencies from the configured package index.
  3. A compromised or unexpectedly unsafe release is selected because no approved versions or hashes are enforced.
  4. Package installation or later import executes attacker-controlled package code in the context of the installing or running account.

This attack path depends on an external supply-chain compromise or unsafe package-index configuration; the audited project itself does not provide evidence of such a compromise.

Impact Assessment

If dependency resolution returns a malicious package, code could execute with the privileges of the account performing installation or running the script. The resulting scope could include access to that acco ...[truncated 264 chars]

Remediation
View remediation

Remediation Suggestions

  • Pin all direct and transitive dependencies to reviewed versions in a lock file.
  • Generate and enforce cryptographic hashes, such as with pip install --require-hashes -r requirements.txt.
  • Install packages only from an approved HTTPS package index.
  • Review dependency advisories and update pinned versions through a controlled process.
  • Perform installation in an isolated virtual environment under a non-privileged account.
  • Consider documenting optional Excel dependencies separately so users install only the components required for their file formats.
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 (4)

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

声明描述的是一个面向知识库与客服对话的分析比对技能,核心能力应包括数据比对、内容一致性分析、过时/缺失检测以及报告建议生成。但提供的代码块只是通用文件读取脚本:限制文件路径在项目目录内,限制文件大小,按扩展名读取 Excel 或文本文件,并原样/结构化输出内容。它既没有处理 FAQ 与客服对话这两类输入之间的关系,也没有实现任何分析、比对、归纳或报告能力。因此代码的实际主要用途与声明目的存在明显且实质性的偏差,属于描述与行为不一致。

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
84% confidence
Finding

The display name and full skill description are presented exclusively in Chinese, and the operational instructions throughout the file also assume Chinese-language use. The policy requires avoiding forced language/locale constraints unless the skill offers user choice or clearly documents a justified region-specific limitation, which this file does not do.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

This code emits all natural-language error messages and the usage prompt in Chinese, including strings at L031-L038, L044, L051, L055-L060, L079-L082, L087-L098, and L102. Under the policy, forcing a specific language without user opt-in or a documented justification is a natural-language policy violation.

Content

No source excerpt is available for this finding.