Search by

microweber-packages / microweber-zip

boksiora

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

Homepage

pkg:composer/microweber-packages/microweber-zip

Statistics

Installs: 34

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-03 11:21 UTC

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