Back to skill

Security audit

Dead Code Cleaner

Security checks for vulnerabilities and agentic risk

Overview

This is a real dead-code cleanup workflow, but it deserves review because it can delete project files and change local MCP/UI settings automatically.

Install only if you are comfortable letting the agent modify the target repository. Use it on trusted codebases, commit or stash first, ask for a dry-run and explicit pre-delete file list, and avoid automatic MCP repair, persistent UI enablement, browser opening, or project build/test execution unless you specifically want those actions.

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
SKILL.md:145
Finding

Shell Command Injection Through Unquoted User-Derived Paths

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 145–163
Vulnerability Type: Shell command injection
Risk Level: High

Vulnerable Code

bash
find <repo-path> -type f \
  -not -path '*/node_modules/*' \
  -not -path '*/vendor/*' \
  -not -path '*/.git/*' \
  -not -path '*/dist/*' \
  -not -path '*/build/*' \
  -not -path '*/target/*' \
  -not -path '*/__pycache__/*' \
  -not -path '*/bin/*' \
  -not -path '*/obj/*' \
  -not -name '*.json' \
  -not -name '*.yaml' -not -name '*.yml' \
  -not -name '*.md' -not -name '*.txt' -not -name '*.rst' \
  -not -name '*.lock' \
  -not -name '*.svg' -not -name '*.png' -not -name '*.jpg' \
  | sed 's/.*\.//' | sort | uniq -c | sort -rn | head -30

The same unsafe interpolation pattern also appears in references/verification-patterns.md, including lines 33–42 and 94–112:

bash
rg -l "{basename}" <repo-path> --type-not sql --type-not json --type-not yaml --type-not svg --type-not png
bash
rg -l "from ['"]@/${rel_path}['"]" <source-dir>/

Technical Analysis

The skill derives repo-path from the current directory or user-supplied project information and then inserts it into shell command templates without quoting it or separating it safely from command syntax. Other filesystem-derived placeholders, including source-dir, basename, and rel_path, are similarly embedded in shell commands and regular expressions without consistent shell and regular-expression escaping.

If an Agent implements these templates through literal shell-string substitution, shell metacharacters in an attacker-controlled path can terminate the intended argument and introduce additional commands. Whitespace and glob characters can also change argument boundaries or expand unexpectedly.

Dynamic filenames embedded in rg expressions create an additional correctness and safety concern. Regular-expression metacharacters m ...[truncated 1901 chars]

Remediation
View remediation

Remediation Suggestions

  1. Treat every repository path, source directory, filename, and relative path as untrusted input.

  2. Pass dynamic values as distinct process arguments rather than constructing shell command strings. Prefer an execution API that accepts an argument array and does not invoke a shell.

  3. When shell use is unavoidable, quote path variables and terminate option parsing explicitly:

    bash
    find -- "$repo_path" -type f
    rg -l --fixed-strings -- "$basename" "$repo_path"
    
  4. Do not concatenate user-derived paths with shell syntax. Construct derived paths using a safe path API or assign them to variables and quote every expansion:

    bash
    source_path="${source_dir%/}/"
    rg -l -- "$pattern" "$source_path"
    
  5. Use fixed-string searches where regular expressions are unnecessary. Where a regular expression is required, escape dynamic values with a tested regex-escaping function before insertion.

  6. Canonicalize the repository path, confirm that it exists and is a directory, and reject control characters or unexpected path forms before running commands.

  7. Before deletion, resolve every candidate to a canonical path and verify that it remains beneath the approved repository root.

  8. Add explicit guidance forbidding eval, sh -c, and equivalent execution of dynamically assembled command strings.

  9. Add tests covering paths and filenames containing spaces, quotes, semicolons, dollar signs, command substitutions, leading hyphens, glob characters, newlines, and regular-expression metacharacters.

  10. Apply these protections consistently to all placeholder-based commands in SKILL.md and references/verification-patterns.md.

Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (10)

Hidden Instructions

High
Category
Prompt Injection
Confidence
70% confidence
Finding

Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.

Content

Scanner excerpt · SKILL.md (reported line 268)May include surrounding context.

md
- **子串误匹配**:如 `vul-list` 包含 `ul-list`。用 `grep -v "vul-list"` 排除。
- **同名异文件**:如 `a/foo.vue` 被误判为引用了 `b/foo.vue`。此问题主要在阶段 2 的「同名校验」步骤中解决——当检测到同名文件时,必须用精确路径反查替换裸 basename 匹配(见 verification-patterns.md 同名校验节)。阶段 3 交叉验证时再次确认:逐一检查每个命中的 import/标签路径,确保其引用的文件路径与候选文件完全一致,排除指向同名异文件的所有命中。
- **注释/文档引用**:注释或文档中的引用不是代码引用。
- **HTML 注释排除(Vue/React 必做)**:`<!-- <Component /> -->` 中的组件标签不算代码引用。L-template-tag 层命中后必须用 `grep -v "<!--.*<"` 排除被 HTML 注释包裹的行。详见 verification-patterns.md L-template-tag 节。

3.2 标记规则:
- 任一层的任一命中经核实为**有效引用** → 标记 ALIVE,退出该文件的验证

Hidden Instructions

High
Category
Prompt Injection
Confidence
70% confidence
Finding

Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.

Content

Scanner excerpt · SKILL.md (reported line 268)May include surrounding context.

md
- **子串误匹配**:如 `vul-list` 包含 `ul-list`。用 `grep -v "vul-list"` 排除。
- **同名异文件**:如 `a/foo.vue` 被误判为引用了 `b/foo.vue`。此问题主要在阶段 2 的「同名校验」步骤中解决——当检测到同名文件时,必须用精确路径反查替换裸 basename 匹配(见 verification-patterns.md 同名校验节)。阶段 3 交叉验证时再次确认:逐一检查每个命中的 import/标签路径,确保其引用的文件路径与候选文件完全一致,排除指向同名异文件的所有命中。
- **注释/文档引用**:注释或文档中的引用不是代码引用。
- **HTML 注释排除(Vue/React 必做)**:`<!-- <Component /> -->` 中的组件标签不算代码引用。L-template-tag 层命中后必须用 `grep -v "<!--.*<"` 排除被 HTML 注释包裹的行。详见 verification-patterns.md L-template-tag 节。

3.2 标记规则:
- 任一层的任一命中经核实为**有效引用** → 标记 ALIVE,退出该文件的验证

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The workflow requires actual deletion of files (rm/git rm) and emphasizes that analysis-only output is insufficient, but it does not require an explicit confirmation immediately before destructive action. In practice, this can cause unintended loss of tracked project files if the analysis is wrong, the repository is hostile, or the user did not expect automatic deletion at that point.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The environment setup instructs running local binaries, attempting automated repair via codebase-memory-mcp install, enabling a persistent UI mode, and probing/opening a localhost service. These actions go beyond core dead-code identification and can modify the host environment or launch services without a narrowly scoped need, increasing attack surface and persistence.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The skill directs the agent to execute repository-defined build and test commands such as npm, yarn, mvn, gradle, cargo, pytest, and similar tooling. In an adversarial or untrusted repository, those commands can run arbitrary code via scripts, plugins, hooks, or build steps unrelated to dead-code analysis, expanding impact from code cleanup into full local code execution.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The file is entirely written as a Chinese-only output template, beginning with a Chinese title and prescribing section headings in Chinese. Under the policy rule for natural-language violations, this constitutes a language/locale constraint without any indication that the user can choose another language or opt in to Chinese output.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
97% confidence
Finding

The natural-language description defines usage and triggering entirely in Chinese and does not offer an alternative language or indicate that the user can interact in another language. Under the policy, forcing a specific language without user opt-in is a locale/language policy violation.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Low
Category
Not specified by scanner
Confidence
77% confidence
Finding

The skill presents itself as a dead-code cleaner that deletes files without automatically committing changes, suggesting a limited repository-modification scope. Later steps introduce additional side effects—restoring files with git checkout -- and launching a browser—which are not reflected in the high-level description and broaden actual behavior beyond pure analysis/cleanup.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

The skill instructs opening a browser to a local service after completion, which is outside the core manifest purpose of dead-code cleanup. Automatically launching a browser can leak context, trigger unintended local interactions, or normalize extra side effects not required for the primary task.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

The entire document is written in Chinese, including headings, instructions, and examples, with no indication that users may choose another language or that the locale restriction is optional. Under the policy for natural-language violations, forcing a specific language without user opt-in is a reportable issue unless the locale constraint is explicitly documented and justified.

Content

No source excerpt is available for this finding.