-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement clamav scan on upload #782
- Loading branch information
Showing
19 changed files
with
177 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
https://github.com/Scalingo/php-buildpack | ||
https://github.com/Scalingo/clamav-buildpack | ||
https://github.com/Scalingo/php-buildpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ docker-compose.yml | |
.github | ||
tools | ||
cypress | ||
cypress.config.js | ||
cypress.config.js | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sineflow_clam_av: | ||
strategy: '%env(CLAMAV_STRATEGY)%' | ||
host: '%env(CLAMAV_HOST)%' | ||
socket: "/app/run/clamd.sock" | ||
port: 3310 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Exception\File; | ||
|
||
class MalwareDetectedException extends \Exception | ||
{ | ||
public function __construct(string $filename) | ||
{ | ||
parent::__construct(\sprintf('Le fichier %s est infecté ', $filename)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Security; | ||
|
||
use Sineflow\ClamAV\Exception\FileScanException; | ||
use Sineflow\ClamAV\Exception\SocketException; | ||
use Sineflow\ClamAV\Scanner; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
readonly class FileScanner | ||
{ | ||
public function __construct( | ||
private Scanner $scanner, | ||
private ParameterBagInterface $parameterBag, | ||
#[Autowire(env: 'CLAMAV_SCAN_ENABLE')] | ||
private bool $clamavScanEnable, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws FileScanException | ||
* @throws SocketException | ||
*/ | ||
public function isClean(string $filePath, ?bool $copy = true): bool | ||
{ | ||
if (!$this->clamavScanEnable) { | ||
return true; | ||
} | ||
if ($copy) { | ||
$copiedFilepath = $this->parameterBag->get('uploads_tmp_dir').'clamav_'.Uuid::v4(); | ||
file_put_contents($copiedFilepath, file_get_contents($filePath)); | ||
} else { | ||
$copiedFilepath = $filePath; | ||
} | ||
|
||
$scannedFile = $this->scanner->scan($copiedFilepath); | ||
|
||
return $scannedFile->isClean(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.