T09 · Insecure Skill Coding Practices
- Location
scripts/generate.py:143- Finding
Unbounded ZIP Archive Extraction Enables Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate.py, lines 143–150
Vulnerability Type: Unbounded archive extraction
Risk Level: MediumVulnerable Code
python temp_dir = tempfile.mkdtemp(prefix="skill-test-gen-") try: with zipfile.ZipFile(str(target_path), "r") as zf: zf.extractall(temp_dir)Technical Analysis
The
prepareworkflow accepts a user-specified ZIP archive and extracts every member withZipFile.extractall()without first enforcing limits on:- The number of archive members
- Individual uncompressed file size
- Aggregate uncompressed size
- Compression ratio
- Available disk space or extraction time
A malicious archive can contain highly compressible data that occupies little space in the ZIP but expands to a very large size. Because extraction happens before the code searches for
SKILL.md, merely processing the archive is sufficient to trigger resource consumption.Attack Path
- An attacker creates a ZIP bomb or another archive containing an excessive number or total size of compressed files.
- The archive is supplied as the target Skill, either directly or through an untrusted source.
- The user or Agent invokes:
bash python scripts/generate.py prepare --skill /path/to/untrusted-skill.zip resolve_skill_path()creates a temporary directory and callsextractall()without resource limits.- The archive expands until disk space, I/O capacity, or processing time is exhausted.
- The Skill process and other applications sharing the filesystem may fail or become unavailable.
Impact Assessment
Successful exploitation does not grant additional system privileges or arbitrary code execution based on the reviewed code. Its primary impact is local denial of service within the permissions of the account running the Skill.
An attacker may:
- Exhaust temporary or root filesystem capacity
- Degrade CPU and disk I/O availability
- Cause the preparation workflow to ha ...[truncated 317 chars]
- Remediation
View remediation
Remediation Suggestions
Replace unrestricted
extractall()usage with a validated, member-by-member extraction routine:- Inspect all
ZipInfoentries before writing any files. - Enforce conservative limits on:
- Total member count
- Maximum uncompressed size per member
- Maximum aggregate uncompressed size
- Maximum compression ratio
- Reject encrypted archives and unsupported or abnormal entry types.
- Confirm sufficient free disk space before extraction.
- Extract each approved member individually while tracking bytes written, aborting immediately if a limit is exceeded.
- Ensure temporary directories are deleted on every error path and after the caller no longer needs them.
- Consider applying execution-time and filesystem quotas when processing untrusted archives.
Example defensive preflight logic:
python MAX_FILES = 1000 MAX_FILE_SIZE = 50 * 1024 * 1024 MAX_TOTAL_SIZE = 250 * 1024 * 1024 MAX_COMPRESSION_RATIO = 100 with zipfile.ZipFile(str(target_path), "r") as zf: members = zf.infolist() if len(members) > MAX_FILES: raise ValueError("Archive contains too many files") total_size = 0 for member in members: if member.file_size > MAX_FILE_SIZE: raise ValueError("Archive member exceeds the size limit") total_size += member.file_size if total_size > MAX_TOTAL_SIZE: raise ValueError("Archive exceeds the total extraction limit") compressed = max(member.compress_size, 1) if member.file_size / compressed > MAX_COMPRESSION_RATIO: raise ValueError("Suspicious archive compression ratio") for member in members: zf.extract(member, temp_dir)The extraction routine should also retain or add canonical-path containment checks as defense in depth.
- Inspect all
