T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/auto_update_final.py:38
- Finding
- Unbounded ZIP Extraction Enables Resource Exhaustion## Vulnerability Details **File Location**: `scripts/auto_update_final.py`, lines 38-55 **Vulnerability Type**: Unrestricted archive extraction and resource exhaustion **Risk Level**: Medium **Vulnerable Code:** ```python temp_dir = tempfile.mkdtemp() try: with zipfile.ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(temp_dir) excel_files = [ f for f in Path(temp_dir).rglob('*.xlsx') if not f.name.startswith('._') ] if not excel_files: return None, "Excel file not found" excel_path = excel_files[0] pdf_files = [ f for f in Path(temp_dir).rglob('*.pdf') if not f.name.startswith('._') ] if not pdf_files: return None, "PDF file not found" ``` ### Technical Analysis The Skill extracts every member of a user-controlled ZIP archive before validating the archive's entry count, expanded size, compression ratio, member type, or available storage. The subsequent recursive scans also traverse the entire extracted directory. A highly compressed archive can contain a very large expanded payload while remaining small enough to upload. Extraction can consume all available disk space, and recursive scanning or later parsing can consume substantial CPU and memory. Temporary-directory cleanup in the `finally` block only occurs after extraction terminates or raises an exception; it does not prevent resource exhaustion while extraction is underway. This behavior is not necessary for the declared functionality. The Skill only needs an Excel workbook and PDF reports, so it should reject unrelated entries and enforce strict archive quotas before writing files. ### Attack Path 1. An attacker creates a ZIP archive containing a very large number of entries or files with an extreme compressed-to-uncompressed size ratio. 2. The attacker submits the archive through the Skill's supported ZIP-processing workflow. 3. `zip_ref.extrac ...[truncated 817 chars]
- Remediation
- ## Remediation Suggestions 1. Inspect every `ZipInfo` member before extraction. 2. Reject archives exceeding a conservative maximum entry count, total declared uncompressed size, individual file size, or compression ratio. 3. Allow only the required `.xlsx` and `.pdf` file types and reject links, devices, encrypted entries, and unexpected archive members. 4. Resolve each destination path and verify that it remains inside the temporary extraction directory before writing. 5. Extract members incrementally while tracking the actual number of bytes written; stop immediately when a quota is exceeded. 6. Apply process-level limits for disk usage, memory, CPU time, file count, and execution time. 7. Parse PDFs and workbooks in an isolated, non-privileged worker or container. 8. Return a clear validation error when an archive violates any configured limit.
