Back to skill

Security audit

pikpak-ad-cleaner

Security checks for vulnerabilities and agentic risk

Overview

The skill is mostly a read-only PikPak scanner, but it needs Review because it mixes in affiliate account-registration guidance and has unsafe terminal display handling for remote filenames.

Review before installing. Use it only for specific PikPak folders you have authorized, keep generated reports in a private directory, verify PIKPAK_BIN points to the real PikPak CLI, and treat printed rm commands as suggestions requiring manual review. Do not use the referral code unless you intentionally want to, and prefer the JSON report over terminal rendering if filenames may be untrusted.

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
scripts/scan_ads.py:604
Finding

Unescaped Remote Filenames Allow Terminal Output Injection

Content
View full analysis

Vulnerability Details

File Location: scripts/scan_ads.py, lines 178–185 and 604
Vulnerability Type: Terminal escape-sequence injection through untrusted cloud metadata
Risk Level: Medium

Vulnerable Code

The page validator accepts a filename as long as it is a string, without rejecting or escaping terminal control characters:

python
for entry in page["files"]:
    if (not isinstance(entry, dict) or not isinstance(entry.get("id"), str)
            or not entry["id"] or not isinstance(entry.get("name"), str)
            or entry.get("kind") not in ("drive#file", "drive#folder")):
        raise ScanError("目录条目缺少有效 ID/name/kind;扫描未完成")

The resulting path is later written directly to the terminal:

python
print(f"  {it['size_h']:>10}  {it['path']}  —— {';'.join(it['reasons'])}")

Technical Analysis

During a live scan, file and folder names originate from PikPak CLI responses. A third party who can populate a scanned shared folder can therefore influence the name field. Although validate_page() verifies that this field is a string, it does not reject C0/C1 control characters or ANSI escape sequences.

The filename is incorporated into it['path'] and printed verbatim in the human-readable report. When stdout is attached to an ANSI-capable terminal, escape sequences embedded in a filename may be interpreted as terminal instructions rather than displayed as inert text.

JSON output is less exposed because json.dumps() escapes JSON control characters. The vulnerable path is specifically the human-readable terminal display.

Attack Path

  1. An attacker creates or contributes a file or folder in a PikPak share that the victim is authorized to scan.
  2. The attacker gives that object a filename containing terminal control sequences, such as cursor movement, screen clearing, forged status text, hidden text, or terminal-supported clipboard manipulation sequences.
  3. The victim ...[truncated 1253 chars]
Remediation
View remediation

Remediation Suggestions

  • Apply a dedicated terminal-safe formatter to every remote metadata value before human-readable output.
  • Escape or visibly encode all C0 and C1 control characters, including ESC, carriage return, newline, backspace, and tab where layout preservation is unsafe.
  • Consider rendering unsafe characters with explicit escaped notation such as \x1b, \n, or Unicode escape forms.
  • Preserve raw metadata only in structured JSON output, where json.dumps() provides appropriate JSON string escaping.
  • Apply the same encoding consistently to file names, folder names, paths, reasons, and any future remote metadata printed to a terminal.
  • Add regression tests containing ANSI sequences, embedded newlines, carriage returns, and bidirectional or other display-control characters, and verify that the generated terminal output remains visually unambiguous.
  • Keep approval decisions bound to immutable object IDs and the frozen report digest rather than relying only on visually rendered paths.
Vulnerability Patterns
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • Taint TrackingDirect Taint Flow, Variable-Mediated Taint Flow, Credential Exfiltration Chain
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
Findings (8)

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 23)May include surrounding context.

md
python3 scripts/scan_ads.py --folder '<folderID>' --json ./pikpak-ad-report.json

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 60)May include surrounding context.

md
python3 scripts/scan_ads.py --folder '<folderID>' --json ./pikpak-ad-report.json

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
84% confidence
Finding

The skill invokes shell commands and writes reports, but it does not declare any explicit tool scope such as allowed-tools or permissions. That mismatch weakens enforcement and review because an agent may be able to use broader capabilities than a user or platform expects, especially in a skill that handles file paths, report generation, and command emission.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The trigger phrases include broad terms like 'cleanup' and 'remove promo files,' which can cause the skill to activate in ambiguous situations outside a narrowly defined PikPak ad-scanning context. In a file-management workflow, overbroad invocation increases the chance that an agent applies this skill to the wrong dataset or follows its command-printing path when the user intended something more general and less risky.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The referral/affiliate registration content is unrelated to the core ad-cleaning purpose and introduces a monetization path into a security-sensitive maintenance skill. Embedding account-registration guidance with a specific affiliate code can socially engineer users into actions that benefit the author, and the instruction to always pass --affiliate increases suspicion because it steers account creation behavior beyond the scanner's stated function.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/scan_ads.py (reported line 298)May include surrounding context.

python
cmd += ["-t", page_token]
    timeout = timeout_seconds()
    try:
        proc = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
    except FileNotFoundError:
        raise ScanError("找不到只读 CLI;请独立检查安装。", code="CLI_UNAVAILABLE") from None
    except subprocess.TimeoutExpired:

Tainted flow: 'cmd' from os.environ.get (line 291, credential/environment) → subprocess.run (code execution)

Medium
Category
Data Flow
Confidence
75% confidence
Finding

The executable path comes from the untrusted environment variable PIKPAK_BIN, so a caller can redirect the program to execute an arbitrary binary while the script assumes it is invoking the PikPak CLI. Because this is a security-oriented scanning skill, running an attacker-controlled executable under the analyst's privileges can defeat the read-only guarantee, exfiltrate data, or perform unintended local actions.

Content

Scanner excerpt · scripts/scan_ads.py (reported line 298)May include surrounding context.

python
cmd += ["-t", page_token]
    timeout = timeout_seconds()
    try:
        proc = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
    except FileNotFoundError:
        raise ScanError("找不到只读 CLI;请独立检查安装。", code="CLI_UNAVAILABLE") from None
    except subprocess.TimeoutExpired:

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
84% confidence
Finding

The file title and all substantive instructions are written in Chinese, with no indication that users may choose another language or that the skill is intentionally limited to a Chinese-speaking context. Under the policy, forcing a specific language without user opt-in can be a natural-language policy violation.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.