Securing .ipa and .apk Ingestion Pipelines Against ZIP Bombs and Path Traversal
Defensive engineering checklist for parsing untrusted mobile ZIP archives (.ipa, .apk, .aab): magic-byte checks, decompression ratio ceilings, entry caps, and zero-buffer S3 uploads.
Key Takeaway
Both .ipa and .apk files are ZIP containers. Never buffer them through API server memory and always enforce magic-byte checks, entry-count caps, uncompressed byte budgets, compression-ratio limits, and path-traversal guards before reading entries.
Never upload multi-hundred-megabyte binaries through web server RAM
Mobile binaries routinely reach 200 MB to 2 GB. Proxying multipart uploads through Next.js API routes exhausts heap limits, stalls event loops, and exposes servers to slow-loris denial of service.
Using client-to-S3 presigned PUT and multipart URLs keeps the web tier lightweight: the API validates file extension, quota caps, and metadata, then hands signed upload URLs directly to the browser or CI runner.
Central directory inspection before inflating any entry
Before reading Info.plist, embedded.mobileprovision, or AndroidManifest.xml inside a background worker, central directory headers must pass deterministic safety bounds:
- ZIP Magic Bytes: Reject payloads not beginning with PK\x03\x04 (or valid empty/spanned ZIP signatures) before invoking parsers.
- Entry Count Ceiling: Reject archives exceeding safe entry counts (preventing 100k-tiny-file inode/CPU exhaustion).
- Uncompressed Byte & Compression Ratio Bounds: Reject individual entries or aggregate totals whose uncompressed size exceeds safe ceilings or suspicious ratios (e.g., 100:1 nested deflate bombs).
- Zip-Slip Path Validation: Normalize every archive entry path and refuse '..' traversal, absolute paths, or null bytes; parse metadata in memory buffers rather than blindly extracting full archives to arbitrary paths.
Frequently Asked Questions
- Why check both compressed size and uncompressed size?
- A malicious 50 KB archive can claim 5 GB of uncompressed XML or PNG payload inside ZIP central directory headers or deflate streams, crashing naive parsers with Out-Of-Memory errors.
Related Guides
Ready to distribute a build?
Upload an .ipa, .apk, or .aab archive or inspect your iPhone UDID directly in Safari.