Skip to content

Commit a22ad95

Browse files
committed
New flag and minor refactoring.
Changelog excerpt: - Added a flag for successful hits against blacklisted filetypes (needed by the upload handler for a newly added configuration directive). - Also did some very minor refactoring.
1 parent 31f5200 commit a22ad95

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
5151
[2021.05.28; Maikuolan]: Performed some minor refactoring.
5252

5353
[2021.05.28; Bug-fix; Maikuolan]: Wrong casing used for some variables would cause undefined variable errors to occur; Fixed (#3).
54+
55+
### v3.2.2
56+
57+
[2021.06.10; Maikuolan]: Added a flag for successful hits against blacklisted filetypes (needed by the upload handler for a newly added configuration directive). Also did some very minor refactoring.

src/Scanner.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The scanner (last modified: 2021.05.28).
11+
* This file: The scanner (last modified: 2021.06.10).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -497,6 +497,7 @@ private function recursor($Files = '', int $Depth = -1): void
497497
$this->Loader->Configuration['files']['filetype_greylist']
498498
], [$xt, $xts, $gzxt, $gzxts]))
499499
) {
500+
$this->Loader->InstanceCache['blacklist_triggered'] = true;
500501
$this->Loader->InstanceCache['ThisScanDone']++;
501502
$this->Loader->Events->fireEvent('countersChanged');
502503
$this->Loader->atHit('', $fS, $OriginalFilenameClean, sprintf(
@@ -2362,7 +2363,6 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
23622363

23632364
/** Check whether Crx, and convert if necessary. */
23642365
if ($this->convertCrx($Data)) {
2365-
23662366
/** Reset the file pointer (because the content has been modified anyway). */
23672367
$File = '';
23682368
}
@@ -2433,7 +2433,6 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
24332433

24342434
/** Handle zip files. */
24352435
if ($Handler === 'ZipHandler') {
2436-
24372436
/**
24382437
* Encryption guard.
24392438
* @link https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
@@ -2463,7 +2462,6 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
24632462

24642463
/** ZipHandler needs a file pointer. */
24652464
if (!$File || !is_readable($File)) {
2466-
24672465
/**
24682466
* File pointer not available. Probably already inside an
24692467
* archive. Let's create a temporary file for this.
@@ -2472,7 +2470,6 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
24722470
$Pointer = &$PointerObject->Filename;
24732471
$this->Loader->InstanceCache['tempfilesToDelete'][] = $Pointer;
24742472
} else {
2475-
24762473
/** File pointer available. Let's reference it. */
24772474
$Pointer = &$File;
24782475
}
@@ -2485,14 +2482,12 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
24852482

24862483
/** Handle tar files. */
24872484
if ($Handler === 'TarHandler') {
2488-
24892485
/** TarHandler can work with data directly. */
24902486
$ArchiveObject = new TarHandler($Data);
24912487
}
24922488

24932489
/** Handle rar files. */
24942490
if ($Handler === 'RarHandler') {
2495-
24962491
/** Guard. */
24972492
if (!class_exists('\RarArchive') || !class_exists('\RarEntry')) {
24982493
if (!$this->Loader->Configuration['signatures']['fail_extensions_silently']) {
@@ -2503,7 +2498,6 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
25032498

25042499
/** RarHandler needs a file pointer. */
25052500
if (!$File || !is_readable($File)) {
2506-
25072501
/**
25082502
* File pointer not available. Probably already inside an
25092503
* archive. Let's create a temporary file for this.
@@ -2512,7 +2506,6 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
25122506
$Pointer = &$PointerObject->Filename;
25132507
$this->Loader->InstanceCache['tempfilesToDelete'][] = $Pointer;
25142508
} else {
2515-
25162509
/** File pointer available. Let's reference it. */
25172510
$Pointer = &$File;
25182511
}
@@ -2525,7 +2518,6 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
25252518

25262519
/** Handle PDF files. */
25272520
if ($Handler === 'PdfHandler') {
2528-
25292521
/** Encryption guard. */
25302522
if ($this->Loader->Configuration['files']['block_encrypted_archives']) {
25312523
if (($XPos = strrpos($Data, "\nxref")) !== false && strpos($Data, "\n/Encrypt", $XPos + 5) !== false) {
@@ -2547,16 +2539,13 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
25472539

25482540
/** Archive object has been instantiated. Let's proceed. */
25492541
if (isset($ArchiveObject) && is_object($ArchiveObject)) {
2550-
25512542
/** No errors reported. Let's try checking its contents. */
25522543
if ($ArchiveObject->ErrorState === 0) {
2553-
25542544
/** Used to count the number of entries processed. */
25552545
$Processed = 0;
25562546

25572547
/** Iterate through the archive's contents. */
25582548
while ($ArchiveObject->EntryNext()) {
2559-
25602549
/** Skip directories (useless for scanning here). */
25612550
if ($ArchiveObject->EntryIsDirectory()) {
25622551
continue;
@@ -2983,11 +2972,10 @@ public function quarantine(string $In, string $Key, string $IP, string $ID): boo
29832972
}
29842973
}
29852974
$Out =
2986-
"\x2f\x3d\x3d\x20phpMussel\x20Quarantined\x20File\x20Upload\x20\x3d" .
2987-
"\x3d\x5c\n\x7c\x20Time\x2fDate\x20Uploaded\x3a\x20" .
2975+
"\x2f\x3d\x3d phpMussel Quarantined File Upload \x3d\x3d\x5c\n\x7c Time\x2fDate Uploaded\x3a " .
29882976
str_pad($this->Loader->Time, 18, ' ') .
2989-
"\x7c\n\x7c\x20Uploaded\x20From\x3a\x20" . str_pad($IP, 22, ' ') .
2990-
"\x20\x7c\n\x5c" . str_repeat("\x3d", 39) . "\x2f\n\n\n" . $Head . $Out;
2977+
"\x7c\n\x7c Uploaded From\x3a " . str_pad($IP, 22, ' ') .
2978+
" \x7c\n\x5c" . str_repeat("\x3d", 39) . "\x2f\n\n\n" . $Head . $Out;
29912979
$UsedMemory = $this->memoryUse($this->Loader->QuarantinePath);
29922980
$UsedMemory['Size'] += strlen($Out);
29932981
$UsedMemory['Count']++;
@@ -3785,6 +3773,7 @@ private function metaDataScan(string $ItemRef, string $Filename, string &$Data,
37853773
!empty($this->Loader->Configuration['files']['filetype_greylist']) &&
37863774
$this->containsMustAssert([$this->Loader->Configuration['files']['filetype_greylist']], [$xt, $xts])
37873775
)) {
3776+
$this->Loader->InstanceCache['blacklist_triggered'] = true;
37883777
$this->Loader->atHit($Checksum, $Filesize, $ItemRef, sprintf(
37893778
$this->Loader->L10N->getString('grammar_exclamation_mark'),
37903779
sprintf(

0 commit comments

Comments
 (0)