Back to skill

Security audit

Tool结果大小控制器

Security checks for vulnerabilities and agentic risk

Overview

The skill has a coherent purpose, but its file-handling code can read or write outside the documented result directory if given unsafe paths.

Review before installing. This skill should not be used with untrusted tool names or user-supplied result paths until it validates filenames, confines reads and writes to its managed results directory, and documents how sensitive spilled results are retained and cleaned up.

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 (2)

T09 · Insecure Skill Coding Practices

Error
Location
tool_result_size_controller.py:31
Finding

Path Traversal Enables Writes Outside the Results Directory

Content
View full analysis

Vulnerability Details

File Location: tool_result_size_controller.py, lines 31-34 and 51-81
Vulnerability Type: Path traversal and unsafe file creation
Risk Level: High

Vulnerable Code

python
def get_result_path(tool_name: str, content_hash: str) -> Path:
    """生成结果文件路径"""
    date_str = datetime.now().strftime("%Y%m%d")
    return RESULTS_DIR / f"{tool_name}-{date_str}-{content_hash[:8]}.json.gz"

The resulting path is subsequently opened for writing:

python
def spill_to_disk(tool_name: str, content: Union[str, dict, list], compress: bool = True) -> dict:
    """
    将大结果写入磁盘
    """
    ensure_results_dir()
    
    # 序列化内容
    if isinstance(content, str):
        content_str = content
    else:
        content_str = json.dumps(content, ensure_ascii=False, indent=2)
    
    # 计算hash和路径
    content_hash = hashlib.md5(content_str.encode()).hexdigest()
    result_path = get_result_path(tool_name, content_hash)
    
    # 写入文件
    if compress:
        with gzip.open(result_path, 'wt', encoding='utf-8') as f:
            f.write(content_str)
    else:
        result_path = result_path.with_suffix('.json')
        with open(result_path, 'w', encoding='utf-8') as f:
            f.write(content_str)

Technical Analysis

The caller-controlled tool_name is inserted directly into a filesystem path without validating path separators, absolute paths, or parent-directory components such as ../.

Python's pathlib path composition does not guarantee that the resulting path remains under RESULTS_DIR. In particular, an absolute path in the right-hand operand can replace the intended base directory. Relative traversal sequences can similarly escape the directory when the path is resolved by the operating system.

The code then opens the calculated path in write mode. This operation truncates an existing destination and follows symbolic links. No ca ...[truncated 1730 chars]

Remediation
View remediation

Remediation Suggestions

  • Restrict tool_name to a conservative identifier format such as ^[A-Za-z0-9_.-]+$.

  • Explicitly reject absolute paths, path separators, . components, and .. components.

  • Resolve the destination and verify that it remains beneath the canonical results directory before opening it:

    python
    base = RESULTS_DIR.resolve()
    destination = (base / generated_name).resolve()
    
    if not destination.is_relative_to(base):
        raise ValueError("Result path escapes the configured results directory")
    
  • Avoid using caller-controlled text as a filename. Generate an opaque random identifier and retain the tool name only as metadata.

  • Open new files atomically and exclusively so existing files cannot be silently truncated.

  • Use operating-system facilities that prevent following symbolic links where available.

  • Create the results directory with restrictive permissions and verify that it is not a symbolic link before use.

  • Add tests covering absolute paths, nested separators, ../ traversal, symbolic links, and concurrent creation.

T05 · Unauthorized Access and Privilege Escalation

Warning
Location
tool_result_size_controller.py:96
Finding

Arbitrary Local File Read Through Unrestricted Result Path

Content
View full analysis

Vulnerability Details

File Location: tool_result_size_controller.py, lines 96-108
Vulnerability Type: Missing filesystem authorization and path validation
Risk Level: Medium

Vulnerable Code

python
def load_spilled_result(file_path: str) -> Union[str, dict, list]:
    """从磁盘加载结果"""
    path = Path(file_path)
    
    if not path.exists():
        raise FileNotFoundError(f"Result file not found: {file_path}")
    
    if path.suffix == '.gz':
        with gzip.open(path, 'rt', encoding='utf-8') as f:
            content = f.read()
    else:
        with open(path, 'r', encoding='utf-8') as f:
            content = f.read()

Technical Analysis

load_spilled_result() treats its file_path argument as an unrestricted local path. It does not establish that the requested file was created by this component or that its canonical path is located beneath RESULTS_DIR.

Absolute paths, relative traversal paths, and symbolic links are consequently accepted. Files with a .gz suffix are decompressed, while all other files are read directly as UTF-8 text. The subsequent JSON parsing does not provide an access-control boundary because non-JSON data is returned as a string.

This behavior exceeds the documented permission scope, which describes reading spilled results from the tool-results directory rather than arbitrary process-readable files.

Attack Path

  1. An attacker obtains control over a value passed to load_spilled_result().
  2. The attacker supplies an absolute path, a path containing ../, or a path to a symbolic link.
  3. The function checks only whether the target exists.
  4. The function opens and reads the target using the privileges of the hosting process.
  5. The content is parsed as JSON when possible or returned as a string to the caller.

Impact Assessment

An attacker can disclose local text or gzip-compressed files readable by the hosting process. Dep ...[truncated 440 chars]

Remediation
View remediation

Remediation Suggestions

  • Resolve the requested path and require it to remain under the canonical RESULTS_DIR:

    python
    base = RESULTS_DIR.resolve()
    path = Path(file_path).resolve(strict=True)
    
    if not path.is_relative_to(base):
        raise PermissionError("Result file is outside the managed results directory")
    
  • Reject symbolic links and require the destination to be a regular file.

  • Do not expose an API that accepts arbitrary filesystem paths. Return an opaque result identifier and resolve it internally against trusted metadata.

  • Maintain a registry or signed metadata record of files created by spill_to_disk() and load only registered results.

  • Apply restrictive directory and file permissions so spilled data is accessible only to the intended service account.

  • Impose maximum decompressed-size limits to prevent oversized gzip files from causing excessive memory consumption.

  • Add tests for absolute paths, traversal sequences, symbolic links, files outside the managed directory, malformed gzip data, and unauthorized result identifiers.

Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
Findings (3)

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill explicitly describes automatically writing oversized tool outputs to disk and retaining them for up to 7 days, but it does not clearly warn users that their data may be persisted outside the conversation context. This creates a confidentiality and data-retention risk, especially if tool results include sensitive content, credentials, personal data, or proprietary material that users assume remains transient.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The module docstring, comments, and example user-facing output are written exclusively in Chinese, and there is no indication that the skill is region-specific or that users can choose another language. The policy requires flagging language or locale constraints when they are imposed without opt-in or clear justification.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
94% confidence
Finding

The natural-language instructions and descriptions are presented exclusively in Chinese, which effectively forces a specific language for users of the skill. The file does not indicate that this is an opt-in locale-specific skill or offer an alternative language choice.

Content

No source excerpt is available for this finding.