Back to skill

Security audit

File Sorter

Security checks for vulnerabilities and agentic risk

Overview

This is a coherent local file-sorting skill, but its undo and overwrite behavior can cause unexpected file loss or movement beyond what the safety wording explains.

Review before installing. Use preview first, avoid sorting into directories that already contain valuable files with overlapping names, and do not run undo in an output directory where the hidden backup file may have been modified by other users or untrusted processes. Do not run it with elevated privileges.

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

T09 · Insecure Skill Coding Practices

Error
Location
scripts/file_sorter.py:145
Finding
Untrusted Undo Log Enables Arbitrary File Deletion or Relocation## Vulnerability Details **File Location**: `scripts/file_sorter.py:39-42` and `scripts/file_sorter.py:145-175` **Vulnerability Type**: Unvalidated file operations based on an editable operation log **Risk Level**: High ### Vulnerable Code ```python def load_backup(self): if self.backup_file.exists(): with open(self.backup_file, 'r', encoding='utf-8') as f: self.backup_data = json.load(f) return self.backup_data ``` ```python def undo(self): backup = self.load_backup() if not backup: print("没有找到备份文件,无法撤销") return False count = 0 # 反向操作,从后往前 for op in reversed(backup): source = Path(op["source"]) target = Path(op["target"]) if op["action"] == "move": if target.exists() and not source.exists(): source.parent.mkdir(parents=True, exist_ok=True) shutil.move(str(target), str(source)) print(f"撤销移动: {target.name} -> {source.parent.name}/{target.name}") count += 1 elif op["action"] == "copy": if target.exists(): target.unlink() print(f"撤销复制: 删除 {target.name}") count += 1 elif op["action"] == "link": if target.exists() and target.is_symlink(): target.unlink() print(f"撤销链接: 删除 {target.name}") count += 1 ``` ### Technical Analysis The undo operation treats `.file-sorter-backup.json` as a trusted source of file paths and actions. The JSON document is loaded without schema validation, integrity verification, file-identity checks, or path-containment enforcement. Each record can supply arbitrary `source`, `target`, and `action` values: - A forged `copy` operation causes `target.unlink()` to delete the specified file. - A forged `move` operation causes the specified target file to be relo ...[truncated 2031 chars]
Remediation
## Remediation Suggestions 1. Define and enforce a strict schema for every operation record, including an allowlist of supported actions and required string fields. 2. Record the canonical input and output roots in the backup metadata. Resolve all operation paths with `Path.resolve()` and reject any path outside those roots. 3. Do not permit undo records to create arbitrary parent directories outside the approved input root. 4. Store file identity metadata, such as device and inode values where supported, and verify that the current target matches the originally processed file before modifying it. 5. Create the backup file with restrictive permissions and reject backup files owned by an unexpected user or writable by untrusted users. 6. Protect the operation log with authenticated integrity, such as an HMAC using a key stored outside the output directory, if hostile local modification is within the threat model. 7. Reject symbolic-link traversal in parent path components and use race-resistant, descriptor-relative filesystem operations where available. 8. Display the exact paths that undo will modify and require explicit confirmation before destructive operations. 9. Handle malformed records and partial failures without continuing with unsafe operations.

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/file_sorter.py:111
Finding
Destination Collisions Can Irrecoverably Overwrite Existing Files## Vulnerability Details **File Location**: `scripts/file_sorter.py:111-140` **Vulnerability Type**: Unsafe destination overwrite and incomplete rollback **Risk Level**: Medium ### Vulnerable Code ```python if target_category: target_dir = self.output_dir / target_category target_path = target_dir / file_path.name operations.append({ "source": str(file_path), "target": str(target_path), "action": action }) if preview: print(f"预览: {file_path.name} -> {target_category}/{file_path.name} [{action}]") if preview: return operations if not operations: print("没有需要整理的文件") return [] confirm = input(f"即将整理 {len(operations)} 个文件,确认吗?(y/N): ") if confirm.lower() != 'y': print("操作已取消") return [] # 保存备份 self.save_backup(operations) # 执行操作 for op in operations: source = Path(op["source"]) target = Path(op["target"]) target.parent.mkdir(parents=True, exist_ok=True) if op["action"] == "move": shutil.move(str(source), str(target)) print(f"移动: {source.name} -> {target.parent.name}/{source.name}") elif op["action"] == "copy": shutil.copy2(str(source), str(target)) print(f"复制: {source.name} -> {target.parent.name}/{source.name}") elif op["action"] == "link": target.symlink_to(source) print(f"链接: {source.name} -> {target.parent.name}/{source.name}") ``` ### Technical Analysis Destination paths are derived solely from the category directory and original filename. The code does not test whether `target_path` already exists before executing a move or copy. `shutil.copy2()` overwrites an existing regular destination file. Depending on operating-system semantics and destination type, `shutil.move()` can also replace an existing destination file. The user only confirms the total operation count and is not warned about individual collisions. The bac ...[truncated 1795 chars]
Remediation
## Remediation Suggestions 1. Refuse to process destination collisions by default and report every conflicting path before confirmation. 2. Provide an explicit `--overwrite` option if replacement is required; never make overwrite behavior implicit. 3. Support safe alternatives such as generating unique filenames, skipping conflicting files, or allowing the user to select a conflict policy. 4. If overwrite is enabled, move the existing destination into a protected rollback area before replacing it and record that backup in the transaction log. 5. Preflight all operations before modifying the filesystem, including duplicate targets generated within the same batch. 6. Implement transactional behavior: if any operation fails, roll back all completed operations and restore displaced destination files. 7. Write the backup transaction atomically and include operation status so undo does not assume that every planned operation completed. 8. Show collision and overwrite details in preview output and in the final confirmation prompt. 9. Add automated tests covering copy, move, link, duplicate filenames, existing destination files, interrupted execution, and rollback failure.
Vulnerability Patterns
  • 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
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (4)

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding
The skill documentation does not accurately align with its described and implied behavior: it claims keyword-based classification without implementation clarity, while also exposing higher-risk capabilities such as copy, symbolic link creation, and undo. This mismatch can mislead users and agent frameworks about what the skill actually does, making unsafe file operations more likely to be approved or executed under incorrect assumptions.

Lp3

Medium
Category
MCP Least Privilege
Confidence
92% confidence
Finding
The skill describes file-organizing operations that inherently read and write files, but it does not declare any explicit tool scope such as permissions or allowed-tools. This creates an authorization ambiguity where an agent may be granted broader filesystem access than users expect, increasing the risk of unintended modification, movement, copying, or linking of files.

Natural-Language Policy Violations

Medium
Confidence
96% confidence
Finding
The manifest description and the entire markdown guidance are presented in Chinese, and the file does not indicate that users may choose another language. Under the language/locale policy, forcing a specific language without user opt-in is a natural-language policy violation.

Natural-Language Policy Violations

Medium
Confidence
95% confidence
Finding
This code file contains natural-language strings such as the title, CLI description, help text, prompts, and status messages in Chinese only. That enforces a specific language experience without user opt-in, which matches the language/locale policy-violation category.

Static analysis

No suspicious patterns detected.