Back to skill

Security audit

Claude Code Architecture

Security checks for vulnerabilities and agentic risk

Overview

This skill is coherent as an agent-architecture template pack, but some included safety-critical templates could teach or generate unsafe authorization and context-compression behavior.

Install only if you want Chinese-language reference patterns and will review/adapt the code before use. Do not copy the permission gate or context compressor into a production agent without fixing authorization state, approval binding, and preservation of all system/developer safety messages.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • 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
Findings (3)

T05 · Unauthorized Access and Privilege Escalation

Error
Location
references/permission_gate_full.py:39
Finding

Caller-Controlled Permission Level Allows Authorization Bypass

Content
View full analysis
bool: """判断是否允许执行。未显式注册的工具默认拒绝。""" if tool_name in self._readonly_tools: return True if tool_name not in self._permissions: return False # 未注册工具默认拒绝 required = self._permissions[tool_name] return level >= required def request_approval(self, tool_name: str, reason: str = "") -> str: """生成授权请求(由调用方展示给用户)""" return ( f"⚠️ 需要授权执行 {tool_name}\n" f" 原因: {reason or '未指定'}\n" f" 确认吗?(y/n)" ) ``` ### Technical Analysis The authorization decision accepts `level` directly from the caller and compares it with the configured requirement. The gate does not derive the caller's effective permission from an authenticated user, trusted session, capability, or approval record. Consequently, any caller able to invoke: ```python gate.can_execute("sensitive_tool", PermissionLevel.ADMIN) ``` can satisfy the check for every registered tool, including tools configured as `WRITE` or `ADMIN`. The `_permissions` mapping therefore behaves as a table of required levels, not as a record of permissions actually possessed by a principal. The approval mechanism is also disconnected from enforcement. `request_approval()` only formats a string; it does not create a pending approval, verify a user response, issue a single-use authorization token, or alter the result of `can_execute()`. An integration that treats a successful call to `can_execute()` as sufficient authorization can therefore bypass the advertised confirmation requirement. The included examples reinforce the ambiguity by calling `can_execute()` without supplying an effective authorization level while asserting that `WRITE` and ...[truncated 1398 chars]
Remediation
View remediation
bool: required = self._requirements.get(tool_name) if required is None: return False effective = self._resolve_permission(principal) return effective >= required ``` - Keep tool requirements and principal grants in separate mappings with unambiguous names such as `_tool_requirements` and `_principal_permissions`. - Do not automatically authorize a tool merely because it was labeled read-only. Validate the tool's implementation and bind the classification to a trusted registration record. - Implement approvals as verified state transitions. A successful approval should produce a short-lived, scoped, single-use token bound to the authenticated user, tool name, normalized arguments, and expiration time. - Consume and invalidate approval tokens atomically when the protected operation starts. - Add tests for `NONE`, `READ`, `WRITE`, and `ADMIN` principals against every requirement level, including attempts to forge a higher level. - Correct the examples so their expected results match the implementation and demonstrate a complete authenticated approval flow. ]]>

T09 · Insecure Skill Coding Practices

Error
Location
references/context_compressor_full.py:72
Finding

Context Pruning Deletes Distinct Consecutive System Safety Messages

Content
View full analysis
list[dict]: """删除低价值消息""" kept = [] for msg in messages: content = msg.get("content", "") # 跳过空消息 if not content.strip(): continue # 跳过重复的系统提示 if msg.get("role") == "system" and kept and kept[-1].get("role") == "system": continue kept.append(msg) return kept ``` ### Technical Analysis The implementation assumes that every system message immediately following another system message is a duplicate. It does not compare message contents, identifiers, origins, priorities, or cryptographic provenance. Agent runtimes commonly construct system context from multiple adjacent messages, such as: 1. The base assistant policy. 2. Organization-specific restrictions. 3. Tool authorization rules. 4. Data-handling constraints. 5. Session-specific administrative instructions. The current logic retains only the first message in such a sequence and silently removes every subsequent system message. This can eliminate safety constraints while preserving the rest of the conversation. The defect is security-relevant because system messages frequently define the controls that prevent dangerous tool use or disclosure. Compression changes the policy input subsequently presented to the model, allowing behavior that would have been prohibited by the removed message. ### Attack Path 1. The host constructs a context containing adjacent system messages, with a later message defining tool restrictions, confidentiality rules, or other safety requirements. 2. An attacker increases context usage through large prompts or tool outputs, or otherwise causes compression to run. 3. `_prune()` processes the context. 4. The later system safety message is ...[truncated 1098 chars]
Remediation
View remediation

T09 · Insecure Skill Coding Practices

Warning
Location
references/rw_scheduler_full.py:24
Finding

Untrusted Operation Type Can Bypass Write Serialization

Content
View full analysis
bool: return self.type == OpType.READ ``` The classification directly controls concurrent execution: ```python if all(op.is_readonly for op in group): await self._execute_read_group(group) else: await self._execute_write_group(group) ``` ### Technical Analysis The scheduler decides whether an operation is safe to run concurrently exclusively from the caller-supplied `Operation.type`. It does not derive the classification from a trusted handler registry, inspect the operation's registered capabilities, or prevent a write-capable handler from being packaged as `OpType.READ`. A caller can therefore associate an arbitrary side-effecting handler with `OpType.READ`. The scheduler will execute that handler in a concurrent read group without acquiring `_write_lock`. The `resource` value is also not used to detect conflicts. Despite the stated design goal of correctly handling dependencies on the same resource, synchronization depends only on the declared type and optional `depends_on` identifiers. This means two mislabeled operations that modify the same resource can run concurrently. ### Attack Path 1. The application allows a plugin, agent component, or request-processing layer to construct `Operation` objects or influence their fields. 2. The attacker supplies a handler that modifies a file, database record, shared state, or other protected resource. 3. The attacker sets ` ...[truncated 904 chars]
Remediation
View remediation
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 (8)

Tp4

High
Category
MCP Tool Poisoning
Confidence
90% confidence
Finding

声明描述的是高层次的 Agent 架构设计知识/模式沉淀,侧重安全门控、上下文压缩、任务编排等设计指导;而代码是一个具体的 Python 调度器实现,核心功能是执行 Operation 队列、按读写类型分组、并发/串行运行并记录结果。虽然“任务编排”与调度有轻微关联,但代码范围明显更窄且偏底层执行器,不是对所述 Agent 架构模式的提炼或说明,也没有实现安全门控、上下文压缩等声明中的关键方面,因此描述与实际行为存在实质不匹配。

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
70% confidence
Finding

Without declared permissions the skill's intent is opaque and cannot be validated.

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’s descriptive and instructional natural language is presented only in Chinese, including the main description and activation guidance. This can violate a language/locale policy when no opt-in, alternative language, or justification for a Chinese-only audience is provided.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

This is a natural-language policy issue because the skill content appears to force a specific language for documentation and user-facing understanding without any opt-in or justification. Users or maintainers who do not read Chinese may be unable to safely understand the skill's behavior or usage.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
89% confidence
Finding

The tool purpose, description, example context, and runtime messages are all presented in Chinese, which can constitute a language-policy violation when no user choice is offered. This may prevent users from understanding approval requirements or errors in their preferred language.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
94% confidence
Finding

This Python file is a code file, so only SQP-2 and SQP-3 apply. The natural-language docstring and inline descriptions are entirely in Chinese and present the skill behavior in a single enforced locale, with no indication that other languages are supported or that Chinese is a justified region-specific requirement.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
81% confidence
Finding

The file’s headings and explanatory text are entirely in Chinese, which imposes a specific language on readers without any visible opt-in or note that the document is intended only for a Chinese-speaking audience. Under the stated policy, language restrictions should either provide user choice or be clearly justified as region- or locale-specific.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

This code file contains its primary natural-language documentation entirely in Chinese, including the module docstring and design-principle comments, with no indication that language selection is optional or user-configurable. Under the policy rule for language/locale constraints, this is a natural-language policy issue because it imposes a specific language without documented opt-in.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.