Back to skill

Security audit

epub-eink-optimizer

Security checks for vulnerabilities and agentic risk

Overview

This skill is a straightforward EPUB image optimizer, but users should back up files because the main script overwrites the chosen EPUB by default.

Install only in a normal user or virtual-environment Python setup, avoid sudo, and keep a backup of any EPUB before running the default optimizer. Use --dry-run first, and be cautious with EPUBs from untrusted sources because very large or crafted archives/images could consume significant memory or CPU.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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)

T08 · Insecure Dependencies

Warning
Location
SKILL.md:104
Finding
Unpinned Third-Party Dependency Installation<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 104-107 **Vulnerability Type**: Unpinned and unverifiable third-party dependency **Risk Level**: Medium ### Vulnerable Code ```bash pip install Pillow ``` ### Technical Analysis The documented installation command retrieves the latest version of Pillow available from the package index at installation time. It does not specify an audited version, validate package hashes, or use a reproducible lock file. Consequently, the dependency resolved during installation may differ from the version originally reviewed. A compromised upstream release, package-index account, configured package mirror, or dependency resolution environment could introduce malicious installation or runtime code. This finding does not establish that Pillow itself is malicious. The issue is the absence of controls that guarantee which dependency artifact will be installed. ### Attack Path 1. An attacker compromises an upstream release channel, package-index account, or package mirror used by the environment. 2. The attacker publishes or substitutes a malicious dependency artifact that satisfies the unrestricted `Pillow` requirement. 3. A user follows the documented `pip install Pillow` command. 4. The package manager retrieves and installs the attacker-controlled artifact. 5. Malicious installation or imported runtime code executes with the privileges of the user running `pip`. ### Impact Assessment Successful exploitation could execute arbitrary code in the installation environment with the invoking user's privileges. Potential impact includes: - Reading or modifying files accessible to the user. - Accessing environment variables and credentials available to the process. - Modifying the Python environment or installed packages. - Establishing additional persistence if the invoking account has sufficient permissions. - Full system compromise if installation is performed by an administrator or through `sudo`. The S ...[truncated 128 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Pin Pillow to a specifically reviewed version in a requirements file: ```text Pillow==<reviewed-version> ``` 2. Generate and verify cryptographic hashes for the approved distribution files: ```text Pillow==<reviewed-version> \ --hash=sha256:<approved-wheel-hash> ``` 3. Install with hash enforcement: ```bash python -m pip install --require-hashes -r requirements.txt ``` 4. Use a virtual environment and avoid installing dependencies with administrator privileges. 5. Periodically review and update the pinned version to incorporate security patches. 6. Obtain packages only from an explicitly trusted package index or internal mirror. 7. Add the lock file or hashed requirements file to the project so installations are reproducible. ]]>

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/optimize_epub.py:25
Finding
Unbounded EPUB Decompression and Image Processing Can Exhaust Resources<![CDATA[ ## Vulnerability Details **File Location**: `scripts/optimize_epub.py`, lines 25-29; related image processing at lines 151-177 and 185-202 **Vulnerability Type**: Uncontrolled resource consumption from untrusted archives and images **Risk Level**: Medium ### Vulnerable Code The entire expanded archive is loaded into memory without limits: ```python def read_epub(path): files = {} with zipfile.ZipFile(path, 'r') as z: for name in z.namelist(): files[name] = z.read(name) return files ``` The resulting image data is subsequently decoded and resized without application-level limits on dimensions, decoded memory consumption, or processing time: ```python for name in sorted(img_names): data = files[name] try: img = Image.open(io.BytesIO(data)) w, h = img.size if w <= max_width: continue new_h = int(h * max_width / w) img = img.resize((max_width, new_h), Image.LANCZOS) buf = io.BytesIO() fmt = 'JPEG' if is_jpeg(name) else 'PNG' if fmt == 'JPEG': img.convert('RGB').save(buf, format='JPEG', quality=quality, optimize=True) else: img.save(buf, format='PNG', optimize=True) new_data = buf.getvalue() print(f" [缩放] {os.path.basename(name)}: {w}x{h} -> {max_width}x{new_h} {len(data)//1024}KB -> {len(new_data)//1024}KB") if not dry_run: files[name] = new_data count += 1 except Exception as e: print(f" [缩放] 跳过 {name}: {e}") ``` JPEG recompression also forces complete image decoding: ```python if not dry_run: for name in sorted(jpg_names): try: img = Image.open(io.BytesIO(files[name])).convert('RGB') buf = io.BytesIO() img.save(buf, format='JPEG', quality=quality, optimize=True) files[name] = buf.getvalue() except Exception as e: print(f" [重压] 跳过 {name}: {e}") ``` ### Technical A ...[truncated 2369 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Validate the input as a ZIP-based EPUB before processing and reject malformed or encrypted entries. 2. Inspect `ZipInfo` metadata before extraction and enforce conservative limits on: - Archive member count. - Individual uncompressed member size. - Total uncompressed size. - Compression ratio. - Maximum input archive size. 3. Avoid loading the entire EPUB into one in-memory dictionary. Process entries incrementally or spool bounded data to a securely created temporary directory. 4. Before decoding an image, validate its encoded size, dimensions, pixel count, and estimated decoded memory requirement. 5. Retain and explicitly configure Pillow decompression-bomb protections rather than disabling them. Treat decompression-bomb warnings as hard failures. 6. Establish cumulative limits for the number of images, total decoded pixels, processing time, and output size. 7. Run EPUB processing in an isolated, unprivileged worker with operating-system memory, CPU, and execution-time limits. 8. Apply the same validation in dry-run mode because that path also reads archives and opens images. 9. Add regression tests using ZIP bombs, excessive member counts, oversized images, malformed images, and extreme aspect ratios. ]]>
Vulnerability Patterns
  • 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
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (3)

Tp4

High
Category
MCP Tool Poisoning
Confidence
99% confidence
Finding
There is a clear description-behavior mismatch. The declared description promises a functional EPUB optimization skill for e-ink devices with multiple concrete image-processing capabilities. The actual code does not implement any of these behaviors and instead acts solely as a stub/example script. While it does not appear to perform any harmful undeclared actions, its primary purpose is materially different from the declared functionality because it provides no optimization behavior at all.

Missing User Warnings

Medium
Confidence
91% confidence
Finding
The script rewrites the input EPUB in place via a temporary file and os.replace(), which can overwrite the user's only copy without an explicit confirmation step, backup, or default output path. In the context of a file-modifying optimization skill, this is a real safety issue because malformed processing, user error, or partial logic mistakes can cause irreversible data loss or content corruption.

Natural-Language Policy Violations

Low
Confidence
95% confidence
Finding
All user-facing natural-language text in the docstring is presented only in Chinese, and the runtime CLI messages are also Chinese-only. Under the stated policy, forcing a specific language without user opt-in is a natural-language policy issue unless a locale restriction is clearly documented and justified.

Static analysis

No suspicious patterns detected.