Back to skill

Security audit

Codebase Index — 代码库索引系统

Security checks for vulnerabilities and agentic risk

Overview

The skill is mostly a local codebase indexer, but its scanner can follow symlinks outside the chosen project and persist sensitive code metadata without much warning.

Install only if you are comfortable with a local Python script scanning your code and producing a metadata-rich JSON index. Avoid running it on untrusted repositories until symlink handling is fixed, and keep generated indexes private because they may reveal paths, docstrings, imports, and snippets of assigned values.

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
scripts/indexer.py:123
Finding

Scan Root Escape Through Symbolic Links

Content
View full analysis

Vulnerability Details

File Location: scripts/indexer.py, lines 31–32, 87–93, and 123–124
Vulnerability Type: Improper symbolic-link handling leading to out-of-scope local file disclosure
Risk Level: Medium

Vulnerable Code

python
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
    tree = ast.parse(f.read(), filename=str(filepath))
python
elif isinstance(node, ast.Assign):
    for target in node.targets:
        if isinstance(target, ast.Name):
            # Module-level variable
            if isinstance(target.ctx, ast.Store):
                symbols.append({
                    'name': target.id,
                    'type': 'variable',
                    'file': rel_path,
                    'line': node.lineno,
                    'value': ast.dump(node.value)[:80],
                })
python
for filepath in root.rglob('*'):
    if not filepath.is_file():
        continue

Technical Analysis

The scanner resolves the supplied project root, but it neither rejects symbolic-link files nor resolves and validates each discovered file against that root. Path.is_file() follows symbolic links, and the subsequent open() operation reads the symlink target.

Consequently, an untrusted project can contain a .py symbolic link whose target is a readable Python file outside the requested scan directory. The scanner will parse that external file as though it belonged to the project. The generated index may include symbol names, imports, docstrings, and truncated AST representations of assignment values. Literal values embedded in external Python configuration files may therefore be copied into the JSON index.

Attack Path

  1. An attacker prepares a project directory containing a .py symbolic link.
  2. The symbolic link points to a readable Python source or configuration file outside the project root.
  3. A user invokes the scan c ...[truncated 1200 chars]
Remediation
View remediation

Remediation Suggestions

  • Reject symbolic links before reading files:

    python
    if filepath.is_symlink() or not filepath.is_file():
        continue
    
  • Apply defense in depth by resolving every candidate and ensuring it remains under the resolved project root:

    python
    try:
        resolved_file = filepath.resolve(strict=True)
        resolved_file.relative_to(root)
    except (OSError, ValueError):
        continue
    
    if not resolved_file.is_file():
        continue
    
  • Open the validated resolved path rather than the original path.

  • Where supported, use no-follow file-opening semantics to reduce time-of-check/time-of-use symlink races.

  • Catch file-resolution and permission errors without exposing sensitive absolute paths unnecessarily.

  • Avoid indexing assignment values by default. If they are required, redact string, byte, and numeric constants or provide an explicit opt-in option.

  • Add tests covering direct file symlinks, nested symlink paths, broken links, links escaping the root, and links remaining inside the root.

Vulnerability Patterns
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • 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
Findings (6)

Tp4

High
Category
MCP Tool Poisoning
Confidence
92% confidence
Finding

核心用途基本接近代码库索引与理解,但描述包含两项明显高于实际实现的能力。首先,虽然导入了 subprocess/re 等模块,代码并未调用 ripgrep,也没有对非 Python 通用文本做任何扫描提取;实际索引来源仅为 .py 文件的 AST 分析。其次,查询能力只实现了按名称/文档字符串搜索并可按符号类型过滤;“按文件查询”并未实现为查询接口,只能通过 files 命令列出含符号文件。未发现越权、网络、敏感资源访问等其他未声明行为。

Content

No source excerpt is available for this finding.

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · scripts/indexer.py (reported line 22)May include surrounding context.

python
IGNORE_DIRS = {
    '.git', '__pycache__', 'node_modules', '.venv', 'venv',
    '.env', 'dist', 'build', '.next', 'target', 'bin', 'obj',
    '.openclaw', '.claude', '.vscode', '.idea',
}

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
94% confidence
Finding

The skill advertises capabilities that imply reading projects, writing an index file, and invoking Python, but it does not declare any explicit tool scope or permission boundaries. In an agent environment, missing scope declarations can cause over-broad execution privileges or make it unclear what filesystem and shell access the skill is expected to have, increasing the chance of unintended file access or command execution.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The manifest description is entirely in Chinese and presents the skill as operating in that language, with no indication that users may choose another language or locale. Under the policy, language constraints should be opt-in or explicitly justified; this file does not provide either.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The module docstring and all user-facing CLI messages are written in Chinese, which effectively imposes a specific language on users. The file does not offer any language or locale selection, nor does it document a justified region-specific constraint.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
84% confidence
Finding

When --output is used, the tool writes a JSON index containing absolute project path, file names, symbol names, docstrings, import relationships, and truncated assigned values. In many codebases these fields can reveal sensitive internal structure or secrets embedded in source/docstrings, and the script does not warn the user, minimize data, or restrict output location/permissions.

Content

No source excerpt is available for this finding.