Back to skill

Security audit

财务归档

Security checks for vulnerabilities and agentic risk

Overview

The skill is a finance-archive helper, but it includes broad activation triggers and unsafe file-renaming guidance that could affect sensitive financial documents if used carelessly.

Review this skill before installing if your agent may handle non-financial files or real company records. Use it only with clearly scoped finance directories, require confirmation before renaming or archiving, and harden or avoid the sample batch_rename code unless it validates destination filenames, prevents path traversal, and refuses overwrites.

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
SKILL.md:274
Finding

Path Traversal and Destructive File Replacement in Bulk Rename Helper

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 274–281
Vulnerability Type: Unvalidated destination path construction and unsafe file rename
Risk Level: Medium

python
def batch_rename(directory, pattern, replacement):
    """批量重命名文件"""
    for filename in os.listdir(directory):
        new_filename = re.sub(pattern, replacement, filename)
        if new_filename != filename:
            old_path = os.path.join(directory, filename)
            new_path = os.path.join(directory, new_filename)
            os.rename(old_path, new_path)
            print(f"Renamed: {filename} -> {new_filename}")

Technical Analysis

The function accepts a regular-expression pattern and replacement value without validating the resulting filename. The value produced by re.sub() is passed directly to os.path.join() and then to os.rename().

A replacement containing .., path separators, or an absolute path can cause the destination to resolve outside the intended archive directory. The function also does not detect destination collisions or require confirmation before moving files. Depending on operating-system behavior, os.rename() may replace an existing destination.

The vulnerability is exploitable when an untrusted user or upstream Agent can influence pattern, replacement, or other rename-rule input passed to this helper.

Attack Path

  1. An attacker or untrusted workflow supplies a crafted replacement value, such as ../target.pdf.
  2. re.sub(pattern, replacement, filename) generates a destination containing traversal components.
  3. os.path.join(directory, new_filename) constructs a path outside the intended archive directory.
  4. os.rename(old_path, new_path) moves the financial document to that external location.
  5. If the destination already exists and the platform permits replacement, the operation may overwrite it without warning.

Impact Assessment

Exploitation occurs with the filesystem privileges of the process ...[truncated 516 chars]

Remediation
View remediation

Remediation Suggestions

  • Permit only a basename as the generated filename; reject absolute paths, .., /, \, empty names, and platform-specific reserved names.
  • Resolve the archive root and destination with pathlib.Path.resolve(), then verify that the destination remains beneath the resolved archive root.
  • Reject existing destinations rather than relying on platform-specific os.rename() replacement behavior.
  • Validate pattern and replacement before processing and catch invalid regular expressions.
  • Generate a complete rename plan first, detect duplicate destinations, and present a dry run for confirmation.
  • Use an atomic no-replace operation where supported.
  • Record successful and failed rename operations in an audit log.
  • Run the operation with filesystem permissions limited to the intended archive directory.

A hardened containment check should follow this model:

python
from pathlib import Path
import os
import re

def batch_rename(directory, pattern, replacement):
    root = Path(directory).resolve()
    rename_plan = []

    for entry in root.iterdir():
        if not entry.is_file():
            continue

        new_name = re.sub(pattern, replacement, entry.name)

        if (
            not new_name
            or Path(new_name).is_absolute()
            or new_name != Path(new_name).name
            or new_name in {".", ".."}
        ):
            raise ValueError(f"Unsafe destination filename: {new_name!r}")

        destination = (root / new_name).resolve()
        if destination.parent != root:
            raise ValueError("Destination escapes the archive directory")
        if destination.exists():
            raise FileExistsError(f"Destination already exists: {destination}")

        if entry != destination:
            rename_plan.append((entry, destination))

    for source, destination in rename_plan:
        os.rename(source, destination)
Vulnerability Patterns
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • 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)

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The trigger phrase "档案整理" is broad enough to match many generic document-organization requests, which can cause unintended skill activation outside the intended finance/archive domain. In agent systems, overbroad routing increases the chance that sensitive file-handling logic is invoked in the wrong context, potentially affecting unrelated user data or producing unsafe automation behavior.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The trigger "archive" is highly generic and language-agnostic, making accidental invocation very likely for unrelated requests involving archiving, storage, or backups. Because this skill performs file-organization operations, ambiguous activation could route arbitrary document tasks into a finance-oriented workflow and create confidentiality or integrity risks.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The phrase "附件整理" is not specific to financial records and could match common requests to organize email or document attachments in many non-financial settings. That broad match surface makes the skill easier to invoke unintentionally, which is risky because the skill includes batch file manipulation and archival guidance that may be applied to the wrong corpus.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

"文件归档" is a very broad phrase that applies to nearly any document-management task, so it lacks the contextual boundaries needed for safe skill routing. In this skill's context, broad invocation is more concerning because the package is aimed at listed-company financial records, a domain with sensitive and regulated data where misrouting can expose or mishandle important documents.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.