microweber-packages / microweber-zip
Standalone Laravel zip package: create and extract ZIP archives with zip-bomb protection, path traversal guards, and optional file-allowance checks
Package info
github.com/microweber-packages/microweber-zip
pkg:composer/microweber-packages/microweber-zip
v1.0.0
2026-11-03 11:21 UTC
Requires
- php: ^8.2
- ext-zip: *
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- microweber-packages/microweber-package: *
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
- microweber-packages/zip: *
This package is auto-updated.
Last update: 2026-11-03 17:07:55 UTC
README
Standalone Laravel package for creating and extracting ZIP archives with:
- Zip-bomb protection (file count, total uncompressed size, per-file size, compression ratio)
- Path traversal guards (no
.., absolute paths, null bytes, forbidden characters) - Optional file-allowance checks (CMS-friendly, or standalone dangerous-extension denylist)
- Clean public API usable in any Laravel 10/11/12 app
Install
composer require microweber-packages/microweber-zip
When used as a path repository inside the Microweber monorepo:
{
"type": "path",
"url": "packages/microweber-zip",
"options": { "symlink": true }
}
Usage
Extract (Unzip)
use MicroweberPackages\Zip\Unzip; $unzip = new Unzip(); $files = $unzip->extract('/path/to/archive.zip', '/path/to/target'); if (is_array($files) && isset($files['error'])) { // handle error } elseif ($files === false) { // empty archive } else { // $files is list of absolute extracted paths }
Extract with ZipArchiveExtractor
use MicroweberPackages\Zip\ZipArchiveExtractor; $extractor = new ZipArchiveExtractor('/path/to/archive.zip'); $extractor->setAllowedFilesCheck(true); // optional extension filter $ok = $extractor->extractTo('/path/to/target/');
Create a zip
use MicroweberPackages\Zip\Zip; $zip = new Zip(); $zip->addFile('hello world', 'hello.txt'); $zip->addDirectoryContent('/path/to/dir', 'dir'); $zip->saveTo('/tmp/out.zip');
Zip-bomb limits
Publish config:
php artisan vendor:publish --tag=zip-config
Or set env vars:
ZIP_MAX_FILES=10000
ZIP_MAX_TOTAL_UNCOMPRESSED=1073741824
ZIP_MAX_SINGLE_FILE=536870912
ZIP_MAX_COMPRESSION_RATIO=100
Testing
cd packages/microweber-zip
composer install
vendor/bin/phpunit
From the CMS root:
php artisan test --filter=Zip
composer analyse -- packages/microweber-zip/src