Skip to content

Commit

Permalink
On-upload: Tag files immediately #38
Browse files Browse the repository at this point in the history
On-upload: If file is too big, tag uploaded file as "Won't scan"

# Test cases

## Small files
Clean -> Clean
Pup -> Pup
Malicious -> blocks upload

## Large files
Any -> Won't scan

## VaaS error (e.g. wrong credentials)
Any -> Unscanned
  • Loading branch information
Philip Stadermann committed Jun 12, 2024
1 parent 19bca77 commit c0da548
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/Service/VerdictService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(LoggerInterface $logger, IConfig $appConfig, FileSer
public function scanFileById(int $fileId): VaasVerdict {
$node = $this->fileService->getNodeFromFileId($fileId);
$filePath = $node->getStorage()->getLocalFile($node->getInternalPath());
if ($node->getSize() > self::MAX_FILE_SIZE) {
if (self::isFileTooLargeToScan($filePath)) {
$this->tagService->removeAllTagsFromFile($fileId);
$this->tagService->setTag($fileId, TagService::WONT_SCAN);
throw new EntityTooLargeException("File is too large");
Expand Down Expand Up @@ -112,9 +112,6 @@ private function tagFile(int $fileId, string $tagName) {
$this->tagService->removeAllTagsFromFile($fileId);

switch ($tagName) {
case TagService::CLEAN:
$this->tagService->setTag($fileId, TagService::CLEAN);
break;
case TagService::MALICIOUS:
$this->tagService->setTag($fileId, TagService::MALICIOUS);
try {
Expand All @@ -123,15 +120,20 @@ private function tagFile(int $fileId, string $tagName) {
} catch (Exception) {
}
break;
case TagService::CLEAN:
case TagService::PUP:
$this->tagService->setTag($fileId, TagService::PUP);
break;
case TagService::WONT_SCAN:
default:
$this->tagService->setTag($fileId, TagService::UNSCANNED);
$this->tagService->setTag($fileId, $tagName);
break;
}
}

public static function isFileTooLargeToScan($path) {
$size = filesize($path);
return !$size || $size > self::MAX_FILE_SIZE;
}

public function scan(string $filePath): VaasVerdict {
$this->lastLocalPath = $filePath;
$this->lastVaasVerdict = null;
Expand Down Expand Up @@ -161,6 +163,10 @@ public function onRename(string $localSource, string $localTarget)
}

public function tagLastScannedFile(string $localPath, int $fileId) {
if (self::isFileTooLargeToScan($localPath)) {
$this->tagFile($fileId, TagService::WONT_SCAN);
return;
}
if ($localPath === $this->lastLocalPath) {
if ($this->lastVaasVerdict !== null) {
$this->tagFile($fileId, $this->lastVaasVerdict->Verdict->value);
Expand Down

0 comments on commit c0da548

Please sign in to comment.