Back to skill

Security audit

gate-switch

Security checks for vulnerabilities and agentic risk

Overview

The skill is a disclosed verification tool, but its specs can run arbitrary shell commands, so it needs careful review before installation.

Install only if you trust every spec that will be run. Treat any spec using script_exit as code, because it can execute shell commands with the agent's current permissions. Prefer removing or disabling script_exit, or require an allowlisted argv-style runner and sandbox before using this in shared, automated, or sensitive environments. Also review the audit log location because bindings and file paths may reveal private project details.

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
scripts/gate_switch.py:138
Finding

Arbitrary Command Execution Through Untrusted Gate Specifications

Content
View full analysis

Vulnerability Details

File Location: scripts/gate_switch.py, lines 138–143
Vulnerability Type: OS command injection through shell=True
Risk Level: High

Vulnerable Code

python
if t == "script_exit":
    r = subprocess.run(c["cmd"], shell=True, capture_output=True, text=True, timeout=300)
    expect = c.get("expect", 0)
    ok = r.returncode == expect
    tail = (r.stdout or r.stderr).strip().splitlines()
    return ok, f"{label}: exit={r.returncode} expect={expect} {tail[-1] if tail else ''}"

The dangerous command value can also be populated through unrestricted placeholder substitution in scripts/gate_switch.py, lines 151–153:

python
raw = open(spec_path, encoding="utf-8").read()
for k, v in bindings.items():
    raw = raw.replace("{%s}" % k, v)

Technical Analysis

The script_exit check reads checks[].cmd from a supplied JSON specification and passes it directly to subprocess.run() with shell=True. No executable allowlist, argument validation, shell-metacharacter filtering, or trust-boundary enforcement is applied.

As a result, a specification author can execute arbitrary shell syntax rather than merely invoke a verification program. The documented --set key=value mechanism increases the exposure because binding values are inserted into the raw JSON before parsing. If a command field contains a placeholder, an attacker who controls the corresponding binding may introduce shell operators, command substitutions, redirections, pipelines, or additional commands.

The timeout limits execution duration but does not constrain what the command can access or modify. Capturing output similarly provides no meaningful security boundary.

Attack Path

  1. An attacker gains the ability to supply or modify the JSON file passed through --spec, or controls a --set value used inside a script_exit command.

  2. The attacker defines a check such as:

    json
    {
      "gate": "attacker-controlled-gate",
      "che
    

...[truncated 1676 chars]

Remediation
View remediation

Remediation Suggestions

  1. Remove shell interpretation

    • Replace command strings with JSON argument arrays.
    • Invoke subprocess.run() with shell=False, which is the default.

    Example specification:

    json
    {
      "type": "script_exit",
      "argv": ["python3", "scripts/check_result.py", "--input", "result.json"],
      "expect": 0
    }
    

    Example implementation:

    python
    if t == "script_exit":
        argv = c["argv"]
        if not isinstance(argv, list) or not argv or not all(
            isinstance(arg, str) for arg in argv
        ):
            raise SpecError("script_exit.argv must be a non-empty string array")
    
        r = subprocess.run(
            argv,
            shell=False,
            capture_output=True,
            text=True,
            timeout=300,
            check=False,
        )
    
  2. Restrict executable selection

    • Maintain an explicit allowlist of approved verification executables or scripts.
    • Resolve paths canonically and ensure approved scripts remain inside a trusted directory.
    • Reject symbolic-link escapes and relative traversal outside that directory.
  3. Treat specifications as trusted code

    • Do not execute script_exit checks from arbitrary or externally supplied specifications.
    • Require specifications to come from a controlled directory and consider integrity verification or signatures when crossing trust boundaries.
    • Document that command-capable specifications carry code-execution authority.
  4. Harden placeholder handling

    • Avoid textual substitution across raw JSON.
    • Parse JSON first, then substitute only into explicitly permitted data fields.
    • Keep command arguments as separate array elements so substituted values cannot become shell syntax.
    • Validate each binding according to its expected type and permitted character set.
  5. Apply least privilege

    • Run verification in a sandbox or restricted subprocess account.
    • Limit filesystem acc ...[truncated 457 chars]
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Tool MisuseTool Parameter Abuse, Chaining Abuse, Unsafe Defaults
  • Rogue AgentSelf-Modification, Session Persistence
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
Findings (13)

Context-Inappropriate Capability

High
Category
Not specified by scanner
Confidence
99% confidence
Finding

The script_exit check allows arbitrary shell execution from the spec, which exceeds the stated role of 'mechanical verification' and creates a direct remote code execution surface. In this skill context, specs are explicitly meant to be generated at workflow time, so treating spec content as executable is especially dangerous.

Content

No source excerpt is available for this finding.

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
99% confidence
Finding

This is classic tool-parameter abuse: an untrusted input field (c['cmd']) is passed into a powerful execution sink with shell=True. An attacker controlling the spec can run arbitrary commands, read/write files, exfiltrate data, or pivot further depending on the agent's privileges.

Content

Scanner excerpt · scripts/gate_switch.py (reported line 132)May include surrounding context.

python
ok = os.path.getmtime(c["path"]) > os.path.getmtime(c["ref_path"])
        return ok, f"{label}: 产物{'新于' if ok else '不新于'}参照"
    if t == "script_exit":
        r = subprocess.run(c["cmd"], shell=True, capture_output=True, text=True, timeout=300)
        expect = c.get("expect", 0)
        ok = r.returncode == expect
        tail = (r.stdout or r.stderr).strip().splitlines()

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
92% confidence
Finding

The skill advertises and operationalizes shell execution, file reads, and append-only logging, but it does not declare any explicit tool scope or allowed permissions in the manifest. That creates an authorization ambiguity: an agent or host may grant broader capabilities than intended, making filesystem access and command execution harder to constrain or audit.

Content

No source excerpt is available for this finding.

Session Persistence

Medium
Category
Rogue Agent
Confidence
81% confidence
Finding

The skill explicitly logs every gate decision to a persistent JSONL file under ~/.agents/logs/gate_switch.jsonl, creating cross-session state. Persistent logs can accumulate sensitive filenames, verification targets, command results, and workflow metadata that may later be read, correlated, or misused by other tools or users on the same system.

Content

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

md
---
name: gate-switch
description: "Claim-verification gate engine for LLM agent workflows. Whenever an agent claims 'X is done / written / synced / verified', write X as a spec JSON of mechanical checks; the engine verifies each check and returns a verdict (A=pass / B=block with violations / CLARIFY / VIOLATION). Cures three chronic LLM failures: skipped work, partial delivery, fabricated claims. 声称 X 已满足,就机械核验 X——判定禁止手写,照抄输出。"
---

# gate-switch — Claim-Verification Gate Engine / 声称即核验门禁引擎

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The description says '判定禁止手写,照抄输出', which instructs the model to mechanically copy output, and the surrounding text prominently mixes enforced Chinese phrasing into the core behavior description. This creates a language/locale policy concern because the skill presents a fixed bilingual/Chinese output mode without stating that the user can choose language or locale.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The natural-language documentation and user-facing CLI descriptions are entirely in Chinese, with no indication that the user can choose another language or that the locale restriction is intentional and justified. Under the policy, forcing a specific language without opt-in is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
86% confidence
Finding

The documentation frames the engine as a constrained, mechanical verifier, but the script_exit primitive breaks that boundary by permitting arbitrary external behavior. This mismatch is dangerous because users and downstream agents may trust the tool as a safe verifier while it can actually execute attacker-controlled commands.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The engine executes shell commands from the spec without any warning, consent, or policy gate. In agent workflows, that makes exploitation easier because a caller may believe it is only running passive checks while the skill performs active command execution on the system.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
99% confidence
Finding

The code executes a shell command taken directly from the untrusted spec via subprocess.run(..., shell=True). Because the skill is intended to consume dynamically generated verification specs, this gives whoever controls the spec a command-execution primitive on the host, turning a verification tool into arbitrary code execution.

Content

Scanner excerpt · scripts/gate_switch.py (reported line 132)May include surrounding context.

python
ok = os.path.getmtime(c["path"]) > os.path.getmtime(c["ref_path"])
        return ok, f"{label}: 产物{'新于' if ok else '不新于'}参照"
    if t == "script_exit":
        r = subprocess.run(c["cmd"], shell=True, capture_output=True, text=True, timeout=300)
        expect = c.get("expect", 0)
        ok = r.returncode == expect
        tail = (r.stdout or r.stderr).strip().splitlines()

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The natural-language description on this line is written entirely in Chinese and provides no indication that users may choose another language or locale. Under the policy, locale or language constraints must be optional or clearly justified; this file presents a language-specific instruction without opt-in or rationale.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The description includes hard language-direction text ('判定禁止手写,照抄输出') and otherwise presents the skill in Chinese without any user opt-in or documented locale requirement. In an agent workflow, forcing a non-user-requested language can degrade usability, create operator misunderstanding, and cause downstream validation or review failures, though it is not a direct code-execution or privilege-escalation issue.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The template is predominantly written in Chinese and explicitly frames output/operation in Chinese without offering a language-selection mechanism or documenting a hard locale requirement. In an agent workflow, this can cause operators or downstream tools to misunderstand verification criteria, leading to incorrect security judgments, failed reviews, or silent policy bypass through human confusion rather than direct 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 entire template, including headings, instructions, and required field labels, is written in Chinese and presents this as the required format for use. There is no indication that users may opt into another language or that the template is restricted to a Chinese-only compliance or regional context, which creates a language/locale policy concern.

Content

No source excerpt is available for this finding.