diff --git a/config/clamav.php b/config/clamav.php index 3e42bb8..3d98e75 100644 --- a/config/clamav.php +++ b/config/clamav.php @@ -38,6 +38,16 @@ */ 'socket_read_timeout' => env('CLAMAV_SOCKET_READ_TIMEOUT', 30), + /* + |-------------------------------------------------------------------------- + | Throw exceptions instead of returning failures when scan fails. + |-------------------------------------------------------------------------- + | This makes it easier for a developer to find the source of a clamav + | failure, but an end user may only see a 500 error for the user + | if exceptions are not displayed. + */ + 'client_exceptions' => env('CLAMAV_CLIENT_EXCEPTIONS', false), + /* |-------------------------------------------------------------------------- | Skip validation diff --git a/src/ClamavValidator/ClamavValidator.php b/src/ClamavValidator/ClamavValidator.php index d982e3e..7193705 100755 --- a/src/ClamavValidator/ClamavValidator.php +++ b/src/ClamavValidator/ClamavValidator.php @@ -80,11 +80,17 @@ protected function validateFileWithClamAv($value) $scanner = $this->createQuahogScannerClient($socket); $result = $scanner->scanResourceStream(fopen($file, 'rb')); } catch (\Exception $exception) { - throw ClamavValidatorException::forClientException($exception); + if (Config::get('clamav.client_exceptions')) { + throw ClamavValidatorException::forClientException($exception); + } + return false; } if (QuahogClient::RESULT_ERROR === $result['status']) { - throw ClamavValidatorException::forScanResult($result); + if (Config::get('clamav.client_exceptions')) { + throw ClamavValidatorException::forScanResult($result); + } + return false; } // Check if scan result is clean