- How do I integrate this package into my Laravel app’s upload flow?
- Use the package’s `Sanitizer` class directly in your controller or middleware. For example, after validating a file, pass it to `$sanitizer->sanitize($filePath)` before saving. It also supports a custom validation rule (`sanitized`) for form requests.
- Which Laravel versions are officially supported?
- The package is designed for Laravel 10+ and leverages its service container and validation system. Check the package’s `composer.json` for the exact version range, as minor updates may align with Laravel releases.
- Does this package work with cloud storage like S3?
- Yes, the package operates on the file data before it’s stored, so it works seamlessly with Laravel’s `Storage` facade, including S3, GCS, and local storage. Just ensure your storage backend supports temporary file handling during sanitization.
- Can I configure which metadata fields are removed?
- The package removes all EXIF, IPTC, and XMP metadata by default, but you can customize the sanitization depth via configuration. For example, you might allow basic ICC profiles while stripping geolocation data.
- What happens if an image fails sanitization (e.g., corrupt file)?
- The package throws an exception if sanitization fails, which you can catch and handle gracefully. For production, consider logging failures and implementing a fallback (e.g., rejecting the upload or notifying admins).
- Is there a performance impact when sanitizing large batches of images?
- Sanitization adds CPU overhead, especially for high-resolution images. For bulk uploads, offload the process to a queue (e.g., Laravel queues) or use a dedicated microservice to avoid blocking requests.
- Does this package support SVG or other non-traditional image formats?
- The package focuses on traditional raster formats (JPEG, PNG, GIF, WEBP) and removes metadata from them. SVG sanitization requires additional libraries (e.g., `svg-sanitizer`), so handle SVGs separately if needed.
- How can I test this package in my CI pipeline?
- Include test images with embedded metadata (e.g., EXIF geotags) and malicious payloads (e.g., shellcode in PNG comments) in your test suite. Verify the package removes metadata and rejects unsafe files while preserving valid ones.
- Are there alternatives to this package for Laravel image sanitization?
- Alternatives include custom scripts using PHP’s `exif_read_data()` or libraries like `imagick`, but they lack Laravel integration. Other packages like `spatie/laravel-medialibrary` offer some sanitization but aren’t as focused on security.
- Can I use this package without Laravel’s validation system?
- Yes, the core `Sanitizer` class is framework-agnostic and can be used in vanilla PHP. However, Laravel-specific features (e.g., validation rules, middleware) require the full Laravel ecosystem.