Back to skill

Security audit

leetcode-plan

Security checks for vulnerabilities and agentic risk

Overview

This LeetCode study helper is coherent overall, but it tells the agent to build a shell command from user text, which could run unintended commands.

Install only if you are comfortable with a Chinese-language LeetCode helper creating or rewriting errorset.md in the directory where the agent is run. Before use, the shell command examples should be changed to pass arguments through a structured process API with shell execution disabled, or the agent should be instructed not to interpolate user text into shell commands.

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:42
Finding

Shell Command Injection Through Interpolated Error Record Fields

Content
View full analysis

Vulnerability Details

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

Vulnerable Code

markdown
**User did not solve the problem**:
1. Ask the user to provide the reason for the error
2. After receiving the reason, automatically generate:
   - **Core idea**
   - **Similar problems**
3. Invoke the script to record the entry in `errorset.md`:
   ```bash
   python3 scripts/manage_errors.py add <day> "<problem ID>" "<problem title>" "<type>" "<error reason>" "<core idea>" "<similar problems>"
text

The source text is presented in Chinese in the audited file; the excerpt above is an English translation that preserves the command exactly in escaped XML form.

### Technical Analysis

The workflow asks the user to provide an error reason and instructs the agent to interpolate it into a shell command. Other values may also originate from user input or model-generated content. Enclosing these values in double quotes does not make them safe for shell execution: command substitutions such as `$(command)` and backtick substitutions are still evaluated by POSIX-compatible shells.

Consequently, if the agent follows this instruction by passing the assembled command to a shell, specially crafted field content can cause an arbitrary command to run before `manage_errors.py` starts.

The Python implementation in `scripts/manage_errors.py` does not itself invoke a shell; it reads positional arguments from `sys.argv`. The vulnerability therefore resides in the command-construction procedure documented by the Skill, not in Python argument parsing.

### Attack Path

1. An attacker triggers the workflow by reporting that a problem was not solved.
2. When asked for an error reason, the attacker supplies shell syntax, for example:
   ```text
   $(touch /tmp/skill-pwned)
  1. The agent follows the Skill instruction and constructs a command resembling:
    bash

...[truncated 1274 chars]

Remediation
View remediation

Remediation Suggestions

  1. Do not assemble a shell command from conversation-derived values. Launch the script with a process API that accepts an argument array, for example:

    python
    subprocess.run(
        [
            "python3",
            "scripts/manage_errors.py",
            "add",
            day,
            problem_id,
            title,
            error_type,
            reason,
            core_idea,
            similar,
        ],
        check=True,
        shell=False,
    )
    
  2. Prefer structured input over positional shell arguments. Accept a JSON document through standard input, validate its schema in manage_errors.py, and write only validated fields:

    json
    {
      "day": 1,
      "problem_id": "977",
      "title": "Sorted Squares",
      "type": "Array",
      "reason": "Incorrect pointer update",
      "core_idea": "Use two pointers",
      "similar": "88, 75"
    }
    
  3. Validate input types and lengths. Require day to be an integer in the expected schedule range, constrain text-field lengths, and reject control characters where they are unnecessary.

  4. If shell execution cannot be avoided, use a proven platform-specific escaping mechanism for every dynamic argument. Simple quoting, character replacement, or blacklisting is insufficient. Structured execution with shell=False remains the preferred fix.

  5. Update SKILL.md to prohibit shell interpolation explicitly. Document that user-controlled and model-generated fields must be passed as discrete process arguments or through standard input.

  6. Add regression tests containing payloads such as $(touch /tmp/test), backticks, quotes, semicolons, newlines, and redirection operators, and verify that they are stored strictly as text without executing commands.

Vulnerability Patterns
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • 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
89% confidence
Finding

The code is focused solely on wrong-problem record management via command-line commands: add, review, and list. It does write to errorset.md and recommend scheduled reviews, which partially matches the declared错题管理/间隔复习 functionality. However, major parts of the declared purpose are absent: there is no functionality to respond to “第X天”/“DX” with that day’s problem, no user-trigger logic, and no processing of submitted solutions. This is therefore a material description-behavior mismatch, with the actual code representing only the error-management subcomponent rather than the full described assistant.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
91% confidence
Finding

The skill instructs the agent to read from references/plan.md and write to errorset.md, but it does not declare any explicit tool scope or permissions boundaries. This is dangerous because file access exists implicitly and could lead to unintended reads or writes beyond what a user expects, especially in an agent environment where current working directory contents may be sensitive.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The description defines activation phrases and behavior entirely in Chinese, including required user inputs like "第X天" and "DX", without indicating that language is optional or configurable. This can violate language/locale policy expectations when a skill implicitly requires a specific language without user opt-in.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The skill writes errorset.md into the user's current working directory without an explicit warning or confirmation. This is dangerous because it modifies local files in a potentially sensitive directory, may overwrite or create files unexpectedly, and could cause data integrity issues if the agent is run from an unintended location.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
96% confidence
Finding

This markdown file is entirely written in Chinese and provides no indication that other languages are supported or that the language choice is intentional or optional. Under the policy rule for language or locale constraints, this is a natural-language policy issue because it imposes a specific language without user opt-in or justification.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
86% confidence
Finding

The top-level docstring presents the skill name and usage entirely in Chinese, which imposes a specific language on users without any opt-in or alternative. The policy scope explicitly covers language or locale constraints in natural-language content, including code docstrings.

Content

No source excerpt is available for this finding.