Back to skill

Security audit

发票提取统计系统

Security checks for vulnerabilities and agentic risk

Overview

This is a coherent local invoice extractor, but its OCR path can place sensitive document images in predictable temporary files on disk.

Install only if you are comfortable processing invoice and travel documents locally with these dependencies. Prefer a patched version that uses secure temporary files or in-memory OCR, and avoid running it on shared machines until that is fixed.

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/paddle_ocr.py:98
Finding

Predictable Temporary File Exposes Sensitive Invoice Images

Content
View full analysis

Vulnerability Details

File Location: scripts/paddle_ocr.py, lines 98-109
Vulnerability Type: Predictable temporary file and unsafe shared temporary-directory usage
Risk Level: Medium

python
# Write to a temporary file
tmp_path = f"/tmp/paddle_ocr_page_{os.getpid()}.jpg"
pix.save(tmp_path)
doc.close()

try:
    result = ocr_image(tmp_path)
finally:
    try:
        os.remove(tmp_path)
    except OSError:
        pass

Technical Analysis

The OCR adapter renders invoice or train-ticket pages to a predictable filename in the shared /tmp directory. The filename contains only the process ID, which can often be observed or estimated by another local process.

The destination is not created and reserved atomically through Python's tempfile facilities. The code also does not verify that the path is not an existing file or symbolic link and does not explicitly enforce owner-only permissions.

Rendered pages can contain sensitive information, including company names, tax identifiers, invoice numbers, financial values, travel records, and partially masked identity information. Depending on the process umask and image library behavior, another local user may be able to read the temporary image or pre-position a symbolic link at the expected path. If pix.save() follows that link, the victim process could overwrite a file writable under its own privileges.

Although the file is normally deleted in a finally block after OCR, it remains present while OCR is running. Abrupt process termination before cleanup may also leave the rendered image on disk.

Attack Path

  1. An attacker obtains local access to the same multi-user system or container namespace.
  2. The attacker monitors process identifiers or predicts the path /tmp/paddle_ocr_page_<PID>.jpg.
  3. The attacker watches for the file to appear and attempts to read or copy it while OCR processing is active.
  4. A ...[truncated 951 chars]
Remediation
View remediation

Remediation Suggestions

  • Replace the predictable path with tempfile.NamedTemporaryFile or a private tempfile.TemporaryDirectory.
  • Create temporary files atomically and use owner-only permissions.
  • Keep rendering, OCR, document closure, and deletion inside structured try/finally blocks.
  • Avoid shared deterministic paths derived from process IDs, page numbers, or input names.
  • Ensure cleanup executes for OCR errors as well as successful processing.
  • Consider processing image bytes in memory if the OCR library supports byte arrays or image objects.

Example hardening pattern:

python
import os
import tempfile

doc = pymupdf.open(pdf_path)
tmp_path = None

try:
    page = doc[page_num]
    pix = page.get_pixmap(matrix=pymupdf.Matrix(scale, scale))

    with tempfile.NamedTemporaryFile(
        prefix="paddle_ocr_",
        suffix=".jpg",
        delete=False
    ) as tmp:
        tmp_path = tmp.name

    os.chmod(tmp_path, 0o600)
    pix.save(tmp_path)
    result = ocr_image(tmp_path)
finally:
    doc.close()
    if tmp_path:
        try:
            os.remove(tmp_path)
        except FileNotFoundError:
            pass

A private temporary directory created with tempfile.TemporaryDirectory() is preferable when multiple intermediate files are required.

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

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The top-level natural-language description is entirely in Chinese and presents the skill as a Chinese-only interface/description, with no indication that users may choose another language or that the locale restriction is intentional for a region-specific compliance context. Under the policy, forcing a specific language without opt-in is a natural-language policy concern.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The docstring for extract_train_ticket_info says it extracts train-ticket fields from pdfplumber text, suggesting a text-only parsing routine. However, elsewhere in the same skill the train-ticket handling path falls back to PaddleOCR and PP-Structure, converts PDF pages to images, and processes temporary files, which materially exceeds that documented behavior.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
87% confidence
Finding

The code creates and saves an Excel workbook containing invoice numbers, buyer/seller names, and tax identifiers, which are sensitive business data. Although the file is the apparent output of the tool, there is no explicit warning in code comments, docstring, or user-facing messaging that running the script will persist this data to disk.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The OCR engine defaults to lang='ch', which imposes a specific language/locale behavior. The file does not expose a user opt-in, configuration choice, or clear justification that the skill is intentionally limited to Chinese-language documents only.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The code renders a PDF page to a predictable file in /tmp using only the process ID in the filename, which can expose sensitive document contents such as invoices, train tickets, names, tax IDs, and partially masked identity numbers. On multi-user systems this creates confidentiality and integrity risks because temporary files may be readable by other users depending on umask, and the predictable path also increases the chance of symlink or race-condition abuse.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
86% confidence
Finding

The top-level docstring and subsequent function/docstring text specify the skill behavior entirely in Chinese, including invoice field names and usage descriptions, with no indication that language is selectable or intentionally region-scoped for users. The policy requires flagging language or locale constraints unless they are clearly justified or offered as an opt-in choice.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

This markdown file contains user-facing changelog text entirely in Chinese, including the version heading and key release notes, without indicating that language selection is optional. Under the policy criteria, forcing a specific language without user opt-in can constitute a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
83% confidence
Finding

The natural-language instructions and usage guidance are entirely presented in Chinese, and the document does not offer users a language or locale choice. Under the policy, forcing a specific language without user opt-in can be a locale-policy issue unless clearly documented as region-specific.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
76% confidence
Finding

The comments around the train-ticket and PP-Structure logic describe these components as integrated fallback extraction paths, but the implementation wraps them in broad except Exception: pass blocks. This creates a mismatch between the documented intent of robust fallback handling and the actual behavior of silently ignoring failures, which can materially affect extraction outcomes.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.