T09 · Insecure Skill Coding Practices
- Location
risk_report.py:511- Finding
Unbounded DOCX Archive Extraction Enables Resource-Exhaustion Attacks
- Content
View full analysis
Vulnerability Details
File Location:
risk_report.py:511-517
Vulnerability Type: Unrestricted archive extraction and decompression bomb exposure
Risk Level: Mediumpython tmpdir = tempfile.mkdtemp(prefix="risk_") all_issues = [] sections_count = 0 try: with zipfile.ZipFile(src, "r") as z: z.extractall(tmpdir) _, body = parse_document(tmpdir)Related unbounded ZIP-entry reads also occur at
reader.py:624-632andtemplate_reader.py:477-485.Technical Analysis
A DOCX file is a ZIP archive containing OOXML resources. The code extracts every archive member without first enforcing limits on:
- The number of archive members
- Individual or aggregate expanded sizes
- Compression ratios
- Available temporary-disk capacity
- XML input size
- Processing time
An attacker can construct a small, highly compressed DOCX whose expanded contents consume a large amount of disk space. Alternatively, oversized XML entries can exhaust memory when subsequently loaded and parsed.
The temporary directory is eventually removed in a
finallyblock, but cleanup only occurs after extraction returns or raises an exception. It does not prevent resource exhaustion while decompression is in progress.Attack Path
- An attacker creates a ZIP bomb or otherwise oversized archive with a
.docxextension. - The attacker supplies it as a thesis document for analysis.
- A user or Agent invokes the documented
risk_report.pycommand. ZipFile.extractall()expands all entries into the system temporary directory without resource limits.- Disk space, memory, or CPU is exhausted before analysis completes.
- The audit process, other processes sharing the host, or the host itself may become unavailable.
Impact Assessment
Exploitation does not grant elevated privileges or arbitrary code execution. The attacker obtains a denial-of-service capability within the privileges ...[truncated 397 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not call
extractall()on an untrusted DOCX archive. - Read only the OOXML entries required by the analysis, such as
word/document.xml, selected header and footer files, styles, and theme data. - Inspect every
ZipInfobefore processing and reject archives that exceed defined limits for:- Total entry count
- Maximum compressed and expanded size per entry
- Maximum aggregate expanded size
- Maximum compression ratio
- Reject encrypted entries, unsupported compression methods, duplicate critical OOXML entries, and malformed member names.
- Normalize and validate member paths before any extraction, ensuring that each destination remains under the temporary directory.
- Check available disk capacity before extraction if extraction remains necessary.
- Apply execution timeouts and memory limits when processing documents from untrusted users.
- Handle limit violations with a controlled error and ensure temporary resources are deleted.
- Do not call
