Skip to content

Commit

Permalink
Add a config setting for client exceptions (#51)
Browse files Browse the repository at this point in the history
Exceptions are good for a developer, but can hide errors for end users.

Example, user uploads a file that is too large for clamav (> 25Mb). ClamAV will close the
stream once it hits it's own configured limit. Throwing an exception in this case will show
the user a 500 internal error, instead of showing a useful message (the file size
validation error).

Resolves #50
  • Loading branch information
damyon authored Dec 28, 2021
1 parent 0aec00c commit e1494aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions config/clamav.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/ClamavValidator/ClamavValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e1494aa

Please sign in to comment.