T09 · Insecure Skill Coding Practices
- Location
scripts/classify_document.py:157- Finding
Arbitrary Command Execution Through an Unquoted Generated Command and eval
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
The skill mostly matches its accounting OCR purpose, but it includes unsafe command-running guidance and writes untrusted document text into Excel files.
Review before installing. Avoid the README batch workflow that uses eval; run extractor scripts directly with quoted paths or a safe dispatcher. Store outputs only in protected directories, be cautious opening generated spreadsheets from untrusted documents, and prefer pinned dependencies or a locked environment.
scripts/classify_document.py:157Arbitrary Command Execution Through an Unquoted Generated Command and eval
scripts/extract_statement.py:255Spreadsheet Formula Injection Through OCR-Controlled Excel Cell Values
scripts/ocr_utils.py:1Runtime Installation of Unpinned Third-Party Dependency Versions
scripts/ocr_utils.py:138Sensitive OCR Temporary Images Are Not Reliably Deleted After Exceptions
The code accurately supports part of the description: extracting invoice data from PDF/JPG/PNG with OCR, producing Excel and JSON outputs, and handling Vietnamese/international invoice patterns. However, the declared purpose presents a broader multi-document system covering invoices, purchase orders, and bank statements, plus classification and routing of unknown documents. This code chunk only implements invoice extraction and related tracking/validation. Because key declared capabilities are absent from the actual behavior, the description does not accurately represent this specific supplied code chunk.
This code aligns with part of the description: it extracts structured data from PDF/image files using OCR-related utilities, writes Excel tracking data, saves JSON backups, and supports Vietnamese/English-style PO field labels. However, the declared description is materially broader than the code shown. The actual primary purpose of this chunk is specifically purchase-order extraction and tracking, not general accounting document processing. There is no evidence here of invoice handling, bank statement handling, unknown-document classification, or routing to other extractors. Duplicate detection and delivery-date urgency checks are extra PO-tracking features, but they are related supporting behavior rather than problematic undeclared capabilities. Therefore the description does not accurately represent this code chunk as written.
The supplied code is a focused bank-statement extractor. It parses bank/account metadata and transactions from OCR text/tables, writes a bank statement Excel workbook, and saves JSON backups. This aligns with only one subset of the declared description: bank statement extraction from PDF/JPG/PNG with OCR and structured outputs. However, the description materially overstates the skill’s scope by claiming support for invoices, purchase orders, unknown-document classification, and routing to different extractors. Those capabilities are absent from this code chunk. No undeclared dangerous behavior is evident; the mismatch is that the declared purpose is broader than the implemented behavior.
There is a clear description-behavior mismatch. The declared purpose describes a full document ingestion and extraction pipeline for accounting records, including OCR, classification, and structured output. The actual code chunk is limited to spreadsheet template generation. While Excel tracking sheets are tangentially related to the declared domain, this code does not implement the core advertised capabilities and instead has a much narrower primary purpose: creating blank accounting Excel templates.
The code generally aligns with a narrow subset of the description: it supports OCR/text extraction from digital/scanned PDFs and image files, includes Vietnamese language preference, and has minor utilities for cleaning amounts and parsing dates. However, the declared purpose claims a broader end-to-end accounting document processor that handles invoices, purchase orders, and bank statements, extracts structured data, classifies unknown documents, routes them to the correct extractor, and outputs Excel tracking sheets and JSON backups. None of those higher-level document-specific processing, classification, routing, or Excel-generation behaviors are present in this code chunk. The code is best described as an OCR helper module, not the full described skill. Therefore this is a material description-behavior mismatch.
The README encourages writing Excel tracking sheets and JSON backups containing invoice, vendor, tax, and bank data but does not clearly warn that these outputs contain sensitive financial information. This can lead to insecure storage, accidental sharing, or retention of regulated business data, especially because JSON backups duplicate the extracted contents.
The batch-processing example parses a command string from classifier output and executes it with eval, which allows arbitrary shell execution if the classifier output is ever influenced by untrusted document content or modified script behavior. In this skill, documents are untrusted inputs and the classifier is explicitly routing based on those inputs, so turning its output into shell code materially increases risk beyond normal document extraction.
The batch example not only uses eval on generated commands, but does so without any warning that the generated string must be treated as untrusted. This normalizes unsafe execution patterns and makes command injection more likely in real deployments.
The skill documents shell execution and file-writing behavior but does not declare an explicit tool scope such as allowed tools or permissions. That omission weakens governance and increases the chance an agent can invoke shell commands or write files without clear user-visible constraints, especially in a skill that processes sensitive accounting data.
The skill processes invoices, purchase orders, and bank statements and writes Excel and JSON outputs, but it does not prominently warn that these artifacts may contain highly sensitive financial and personal data. In an agent setting, this increases the risk of accidental persistence of confidential data in insecure locations or unintended sharing of backups.
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
sudo apt install tesseract-ocr tesseract-ocr-vie poppler-utils
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
sudo apt install tesseract-ocr tesseract-ocr-vie poppler-utils
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
sudo apt install tesseract-ocr tesseract-ocr-vie poppler-utils
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
sudo apt install tesseract-ocr tesseract-ocr-vie poppler-utils
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
sudo apt install tesseract-ocr tesseract-ocr-vie poppler-utils
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
sudo apt install tesseract-ocr tesseract-ocr-vie poppler-utils
The guide marks the Vietnamese language pack as "critical for hóa đơn," which imposes a locale-specific assumption in natural language. The file does not indicate that Vietnamese is optional, user-selected, or that this skill is explicitly limited to a Vietnam-specific accounting context.
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
| Problem | Solution |
|---------|----------|
| "tesseract is not installed" | `sudo apt install tesseract-ocr` |
| Vietnamese text garbled | `sudo apt install tesseract-ocr-vie` |
| "poppler-utils not installed" | `sudo apt install poppler-utils` |
| Low confidence on clean PDF | Likely a digital PDF — pdfplumber should work fine |
No suspicious patterns detected.