Back to skill

Security audit

Token Guard Model Switch

Security checks for vulnerabilities and agentic risk

Overview

This is a local token-usage reporting and model-switch guidance skill with some rough edges, but I found no hidden data collection, persistence, or destructive behavior.

Install this only if you want a Chinese-language helper for token pressure reports and model-switch prompts. Review the fallback model list before use, and require explicit confirmation before `/compact` or any session model change. Treat script arguments as trusted input only; wrappers should validate token counts and sanitize model or quota strings.

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

Note
Location
scripts/monitor.js:7
Finding
Unchecked command-line arguments allow monitor denial of service and status-output spoofing<![CDATA[ ## Vulnerability Details **File Location**: `scripts/monitor.js`, lines 7–18 and 29–42 **Vulnerability Type**: Unvalidated numeric input and unsanitized terminal/Markdown output **Risk Level**: Low ### Vulnerable Code ```javascript if (args.length < 3) { console.log("Usage: node monitor.js <current_tokens> <max_tokens> <current_model> [quota_remaining_percent]"); process.exit(1); } const current = parseInt(args[0], 10); const max = parseInt(args[1], 10); const model = args[2]; const quota = args[3] || "N/A"; const ratio = (current / max); const percent = Math.round(ratio * 100); // Generate progress bar const barLength = 10; const filledLength = Math.round(ratio * barLength); const bar = "▓".repeat(Math.min(filledLength, barLength)) + "░".repeat(Math.max(0, barLength - filledLength)); ``` ```javascript if (ratio >= 0.95) { riskLevel = "緊急 (Critical)"; color = "🔴"; } else if (ratio >= 0.85) { riskLevel = "警告 (Warning)"; color = "🟡"; } console.log(` --- ### 🛡️ Token Guard 狀態回報 **【風險等級:${riskLevel} ${color}】** - **目前模型:** ${model} - **上下文負載:** \`[${bar}] ${percent}%\` - **剩餘配額:** ${quota}% **⚠️ 診測建議:** ${ratio >= 0.85 ? "建議立即執行 /compact 或換模型以免中斷。" : "目前尚在安全範圍,請繼續任務。"} --- `); ``` ### Technical Analysis The script checks only the number of arguments. It does not verify that `current` and `max` are finite numbers, that `current` is non-negative, or that `max` is greater than zero. A negative `current` value can produce a negative `filledLength`. That value is passed to `String.prototype.repeat()` when constructing the unfilled portion of the progress bar, resulting in a `RangeError` and termination of the monitoring process. Zero, nonnumeric, infinite, or otherwise malformed values can also produce invalid ratios and misleading status calculations. The `model` and `quota` arguments are inserted directly into a formatted terminal and Markdown report. If these values originate from an attacker-controlled or unreliable integratio ...[truncated 1416 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Parse numeric arguments with `Number()` and reject values for which `Number.isFinite()` is false. 2. Require `current` to be non-negative and `max` to be strictly greater than zero. 3. If quota is numeric, enforce an expected range such as `0` through `100`; otherwise, permit only a fixed safe placeholder. 4. Reject invalid arguments with a concise error message and a nonzero exit status before performing ratio or progress-bar calculations. 5. Clamp the calculated ratio and progress-bar lengths to safe ranges before calling `String.repeat()`. 6. Remove ANSI and other terminal-control characters from `model` and `quota`. 7. Escape Markdown metacharacters and normalize or reject line breaks before interpolating external text into the report. 8. Add tests covering negative values, zero maximum, nonnumeric values, extreme numbers, embedded newlines, Markdown injection, and ANSI escape sequences. Example validation pattern: ```javascript const current = Number(args[0]); const max = Number(args[1]); if ( !Number.isFinite(current) || !Number.isFinite(max) || current < 0 || max <= 0 ) { console.error("Invalid token values: current must be non-negative and max must be positive."); process.exit(1); } const ratio = current / max; const displayRatio = Math.max(0, Math.min(ratio, 1)); const filledLength = Math.max( 0, Math.min(barLength, Math.round(displayRatio * barLength)) ); function sanitizeDisplay(value) { return String(value) .replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "") .replace(/[\r\n]/g, " ") .replace(/([\\`*_{}[\]()#+.!|>~-])/g, "\\$1"); } ``` ]]>
Vulnerability Patterns
  • 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
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (4)

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding
描述聲稱此技能會『主動監控』token 使用率與上下文壓力,並『防止對話中斷且自動引導切換至備援模型』。但實際程式只是單次執行的 CLI 報表工具:解析輸入參數、計算比例、顯示進度條、標示風險等級,並在高使用率時輸出「建議立即執行 /compact 或換模型」的靜態文字。它沒有任何主動監控機制、沒有觸發器、沒有自動化切換模型的邏輯,也沒有與外部系統互動來實際防止中斷。因此描述明顯高估了實際能力,屬於目的與行為不符。

Natural-Language Policy Violations

Medium
Confidence
95% confidence
Finding
The file’s natural-language description, operational instructions, and required user-facing message templates are all written in Chinese and prescribe exact response wording, but there is no indication that the user can choose another language. This creates a locale/language policy issue because the skill effectively enforces a specific language without opt-in or a documented region-specific justification.

Intent-Code Divergence

Medium
Confidence
94% confidence
Finding
The file first declares a concrete model pool in metadata at L12-L15, but the later '當前建議模型池 (2026 基準)' section lists entirely different models as the recommended pool. Because this document instructs the agent to choose from that later pool when triggered, the documentation actively conflicts with the configured models that appear to define the skill's actual intended options.

Natural-Language Policy Violations

Medium
Confidence
95% confidence
Finding
The script emits user-facing status labels and recommendations primarily in Traditional Chinese, such as "正常", "警告", and the status report body, with no option to select another language. This creates a natural-language locale policy issue because the skill imposes a specific language on users without opt-in or justification.