A Laravel package for secure file scanning and validation
hosametm/file-scanning is a Laravel package for a laravel package for secure file scanning and validation.
It currently has 1 GitHub stars and 1 downloads on Packagist (latest version v1.0.1).
Install it with composer require hosametm/file-scanning.
Discover more Laravel packages by hosametm
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package for secure file scanning and validation. This package helps you validate files based on their MIME types and provides protection against potentially malicious file uploads.
You can install the package via composer:
composer require hosametm/file-scanning
After installing the package, publish the configuration file:
php artisan vendor:publish --tag=file-scanning-config
The configuration file (config/file-scanning.php) contains three main sections:
temp_directory: The directory where temporary files will be stored when downloading files from URLs (defaults to system temp directory)mime_types: A list of allowed file extensions and their corresponding MIME typesmalicious_mime_types: A list of MIME types that are considered potentially maliciousYou can customize these settings according to your needs.
use Hosametm\FileScanning\FileScanner;
class YourController extends Controller
{
protected $fileScanner;
public function __construct(FileScanner $fileScanner)
{
$this->fileScanner = $fileScanner;
}
public function upload(Request $request)
{
$file = $request->file('file');
if ($this->fileScanner->validateUpload($file)) {
// File is valid, proceed with upload
} else {
// File is invalid or potentially malicious
}
}
}
use Hosametm\FileScanning\FileScanner;
class YourController extends Controller
{
protected $fileScanner;
public function __construct(FileScanner $fileScanner)
{
$this->fileScanner = $fileScanner;
}
public function validateUrl(Request $request)
{
$url = $request->input('file_url');
if ($this->fileScanner->validateUrl($url)) {
// File from URL is valid, proceed with processing
} else {
// File is invalid or potentially malicious
}
}
}
$fileScanner->validate(string $filePath): bool
$fileScanner->validateUpload(\Illuminate\Http\UploadedFile $file): bool
$fileScanner->validateUrl(string $url): bool
$fileScanner->getMimeType(string $filePath): ?string
$fileScanner->isMalicious(string $filePath): bool
$fileScanner->getExtensionsFromMimeType(string $mimeType): array
This package helps protect your application by:
Please see CONTRIBUTING.md for details.
The MIT License (MIT). Please see License File for more information.