Back to skill

Security audit

trouble-shooting

Security checks for vulnerabilities and agentic risk

Overview

This troubleshooting skill is mostly purpose-aligned, but it can run high-impact Git operations and has a real data-loss risk if its finish action is mistyped or miscalled.

Install only if you are comfortable with a skill that can create Git worktrees, merge a troubleshooting branch into your current branch, and force-delete temporary worktrees and branches. Use explicit commands, review .trouble-shooting/active.json before finishing, and avoid calling the finish script through automation unless action validation is fixed.

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/finish_troubleshoot.py:111
Finding

Invalid Action Values Silently Trigger Destructive Worktree Discard

Content
View full analysis

Vulnerability Details

File Location: scripts/finish_troubleshoot.py, lines 111–125
Vulnerability Type: Missing input validation leading to unintended destructive behavior
Risk Level: Medium

Vulnerable Code

python
action = sys.argv[1]  # 'apply' or 'discard'
solution = sys.argv[2] if len(sys.argv) > 2 else "Fixed"

# Load snapshot
snapshot = load_snapshot()
if not snapshot:
    print(json.dumps({"error": "No active troubleshooting session"}))
    sys.exit(1)

# Process worktree changes
if snapshot.get("mode") == "worktree":
    if action == "apply":
        result = apply_worktree_changes(snapshot)
    else:
        result = discard_worktree(snapshot)
else:
    result = {"success": True, "mode": "subagent"}

The resulting destructive operations are implemented in discard_worktree at lines 86–96:

python
if os.path.exists(worktree_path):
    subprocess.run(
        ["git", "worktree", "remove", "-f", worktree_path],
        capture_output=True, check=True
    )

# Delete temporary branch
subprocess.run(
    ["git", "branch", "-D", f"trouble/{snapshot['id']}"],
    capture_output=True
)

Technical Analysis

The documented command interface accepts only apply and discard, but the program never validates the supplied action against that allowlist. Instead, every value other than exactly apply enters the discard branch.

This fail-open control flow converts malformed input, such as a typo, unsupported value, or unexpected automation input, into authorization to perform destructive cleanup. The cleanup uses both git worktree remove -f and git branch -D, which can delete uncommitted worktree changes and force-delete the associated branch.

This is an insecure coding practice because the destructive operation is selected implicitly rather than through an explicit, validated discard request.

Attack Path

  1. A troubleshooting session is ...[truncated 1326 chars]
Remediation
View remediation

Remediation Suggestions

  1. Validate the action against an explicit allowlist before loading state or performing any repository operation:

    python
    action = sys.argv[1]
    if action not in {"apply", "discard"}:
        print(json.dumps({
            "error": "Invalid action",
            "allowed_actions": ["apply", "discard"]
        }))
        sys.exit(2)
    
  2. Use explicit branches and reject all unexpected values:

    python
    if action == "apply":
        result = apply_worktree_changes(snapshot)
    elif action == "discard":
        result = discard_worktree(snapshot)
    else:
        raise ValueError("Unsupported action")
    
  3. Require a separate confirmation flag before force-removing a worktree containing uncommitted changes, especially for noninteractive callers.

  4. Check worktree status before deletion and refuse destructive cleanup by default when modifications are present. Preserve or export a patch unless the caller explicitly authorizes permanent deletion.

  5. Avoid -f and -D where possible. Use non-forced Git operations first and report a clear error if uncommitted or unmerged work would be lost.

  6. Archive the session and remove active.json only after the requested operation succeeds. If cleanup fails, retain active state so recovery remains possible.

  7. Add regression tests proving that empty, misspelled, differently cased, and unsupported action values terminate without changing the worktree, branch, archive, or active-session state.

Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
Findings (19)

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

The skill promises isolated troubleshooting via worktree or subagent, but the finding indicates the implemented behavior does not actually create an isolation environment and instead only accesses historical archive records. This kind of description-behavior mismatch is dangerous because users may trust that experimentation is safely sandboxed when it is not, leading to accidental modification of the main context or incorrect operational assumptions.

Content

No source excerpt is available for this finding.

Vague Triggers

High
Category
Not specified by scanner
Confidence
97% confidence
Finding

The trigger phrases '报错了', '有问题', and '排查' are extremely broad and likely to appear in ordinary conversation, so the skill may activate unintentionally. In this skill's context, accidental activation is more dangerous than usual because activation can lead to file operations, shell usage, context switching, and potential application or cleanup of changes.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
92% confidence
Finding

The skill describes and implicitly relies on filesystem and shell-capable operations such as creating worktrees, applying changes, and cleaning up environments, but it declares no explicit tool scope or permission boundary. In an agent setting, missing scope declarations can cause overbroad tool access or unclear authorization, increasing the chance that troubleshooting actions affect the main repository, unrelated files, or execute unintended shell commands.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The file presents the skill instructions, examples, and user-facing interaction entirely in Chinese, with no indication that language selection is optional or limited to a China-specific environment. Under the policy, forcing a specific language without user opt-in is a natural-language policy concern.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The usage section repeats ambiguous activation rules without adding safeguards, reinforcing that ordinary phrases can trigger the workflow. Repetition of loose triggers increases the operational risk that the agent enters a troubleshooting flow and performs side-effecting actions when the user was only describing a problem rather than requesting the skill.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/finish_troubleshoot.py (reported line 50)May include surrounding context.

python
try:
        # 切换到原分支
        subprocess.run(
            ["git", "checkout", snapshot['branch']],
            capture_output=True, check=True
        )

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
80% confidence
Finding

The script merges a branch name derived from untrusted snapshot metadata directly into the current branch without validating that the troubleshooting session metadata is authentic or expected. An attacker who can tamper with active.json could cause unintended branch merges, polluting the main branch or introducing malicious code under the guise of troubleshooting cleanup.

Content

Scanner excerpt · scripts/finish_troubleshoot.py (reported line 56)May include surrounding context.

python
)

        # 从 worktree 分支 cherry-pick 或合并变更
        result = subprocess.run(
            ["git", "merge", f"trouble/{snapshot['id']}", "--no-edit"],
            capture_output=True, text=True
        )

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/finish_troubleshoot.py (reported line 66)May include surrounding context.

python
return {"success": False, "error": "Merge failed, manual resolution needed"}

        # 清理 worktree
        subprocess.run(
            ["git", "worktree", "remove", "-f", worktree_path],
            capture_output=True, check=True
        )

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/finish_troubleshoot.py (reported line 88)May include surrounding context.

python
return {"success": False, "error": "Merge failed, manual resolution needed"}

        # 清理 worktree
        subprocess.run(
            ["git", "worktree", "remove", "-f", worktree_path],
            capture_output=True, check=True
        )

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/finish_troubleshoot.py (reported line 72)May include surrounding context.

python
)

        # 删除临时分支
        subprocess.run(
            ["git", "branch", "-D", f"trouble/{snapshot['id']}"],
            capture_output=True
        )

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/finish_troubleshoot.py (reported line 94)May include surrounding context.

python
)

        # 删除临时分支
        subprocess.run(
            ["git", "branch", "-D", f"trouble/{snapshot['id']}"],
            capture_output=True
        )

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The discard path force-removes the worktree and deletes the troubleshooting branch with no explicit confirmation, preview, or safeguard. In a troubleshooting skill designed to isolate work, this is more dangerous because operators may assume safety boundaries, yet a mistaken or coerced 'discard' can irreversibly destroy unmerged diagnostic work or evidence.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

This Python file contains natural-language strings exclusively in Chinese, including the module description and console output, with no indication that the skill is region-specific or that users can opt into another language. That can violate language/locale policy because it imposes a specific language by default.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/start_troubleshoot.py (reported line 38)May include surrounding context.

python
def get_current_branch():
    try:
        result = subprocess.run(
            ["git", "rev-parse", "--abbrev-ref", "HEAD"],
            capture_output=True, text=True, check=True
        )

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/start_troubleshoot.py (reported line 56)May include surrounding context.

python
"""创建 git worktree 进行物理隔离"""
    worktree_path = f"../{os.path.basename(os.getcwd())}-trouble-{issue_id}"
    try:
        subprocess.run(
            ["git", "worktree", "add", "-b", f"trouble/{issue_id}", worktree_path],
            capture_output=True, check=True
        )

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/start_troubleshoot.py (reported line 64)May include surrounding context.

python
except subprocess.CalledProcessError:
        # 分支可能已存在,尝试直接添加
        try:
            subprocess.run(
                ["git", "worktree", "add", worktree_path, f"trouble/{issue_id}"],
                capture_output=True, check=True
            )

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The script automatically persists troubleshooting metadata to .trouble-shooting/active.json before any user confirmation, including the current working directory, branch name, timestamp, issue identifier, and user-supplied title. In an agent setting, that can silently retain potentially sensitive context on disk and create privacy or data-handling issues, especially because the skill is explicitly designed to capture and preserve session context.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
93% confidence
Finding

The top-level user-facing description and inline messaging are written only in Chinese, which imposes a language choice without opt-in. The policy allows locale constraints only when the choice is explicit or clearly justified, neither of which is present here.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
85% confidence
Finding

The module docstring and inline comments are written only in Chinese, with no indication of language choice or opt-in. This can violate language/locale policy when a skill implicitly requires a specific language for understanding or safe use.

Content

No source excerpt is available for this finding.