divineomega/laravel-malware-validation-rule

Scans uploaded files for viruses and other malware

v1.0.0 2020-03-14 18:20 UTC

This package is auto-updated.

Last update: 2024-03-29 04:32:36 UTC


README

Build Status

The Laravel Malware Validation Rule package provides a validation rule that scans uploaded files for viruses and other malware.

Installation

To install the Laravel Malware Validation Rule package, run the following command

composer require divineomega/laravel-malware-validation-rule

This package makes use of the ClamAV daemon to perform virus/malware scanning. You can install ClamAV in Ubuntu/Debian with the following command.

sudo apt install clamav-daemon

Your ClamAV installation should automatically update virus defintions. However, you can update your ClamAV virus definitions manually using the freshclam command. It is recommended to restart the ClamAV daemon after the virus definitions have been updated to ensure they take effect.

sudo freshclam
sudo service clamav-daemon restart

Usage

See the following basic usage example, which demonstrates how to validate a basic file upload does not contain contain a known virus/malware.

use \DivineOmega\LaravelMalwareValidationRule\Rules\Malware;

// ...

public function rules()
{
    return [
        'my_file' => ['required', 'file', new Malware()],
    ];
}

By default the validation rule message will include the name of the detected virus/malware. If you do not wish the malware name to be shown in the validation message you can turn this off as shown below.

public function rules()
{
    $showMalwareName = false;

    return [
        'my_file' => ['required', 'file', new Malware($showMalwareName)],
    ];
}