ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor Class Reference

Class InsecureFilenameSanitizerPreProcessor. More...

+ Inheritance diagram for ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor:
+ Collaboration diagram for ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor:

Public Member Functions

 process (FileStream $stream, Metadata $metadata)
 This method gets invoked by the file upload service to process the file with the help of the processor. More...
 
 process (FileStream $stream, Metadata $metadata)
 This method gets invoked by the file upload service to process the file with the help of the processor. More...
 

Protected Member Functions

 checkPath (string $path)
 
 getRejectionMessage ()
 
 getOKMessage ()
 

Private Member Functions

 isFileAZip (Metadata $metadata)
 

Detailed Description

Class InsecureFilenameSanitizerPreProcessor.

PreProcessor which checks for file with potentially dangerous names

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 32 of file AbstractRecursiveZipPreProcessor.php.

Member Function Documentation

◆ checkPath()

ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor::checkPath ( string  $path)
abstractprotected
Parameters
string$pathto a file
Returns
bool false leads to rejection, true to accept

Reimplemented in ILIAS\FileUpload\Processor\BlacklistExtensionPreProcessor, and ILIAS\FileUpload\Processor\InsecureFilenameSanitizerPreProcessor.

Referenced by ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor\process().

+ Here is the caller graph for this function:

◆ getOKMessage()

ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor::getOKMessage ( )
abstractprotected

◆ getRejectionMessage()

ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor::getRejectionMessage ( )
abstractprotected

◆ isFileAZip()

ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor::isFileAZip ( Metadata  $metadata)
private

Definition at line 72 of file AbstractRecursiveZipPreProcessor.php.

72 : bool
73 {
74 return $this->isMimeTypeOrExtension(
75 $metadata,
76 'zip',
77 ['application/zip', 'application/x-zip-compressed']
78 );
79 }

Referenced by ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor\process().

+ Here is the caller graph for this function:

◆ process()

ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor::process ( FileStream  $stream,
Metadata  $metadata 
)

This method gets invoked by the file upload service to process the file with the help of the processor.

If the return value is REJECTED, no further invocations of processors are done for the rejected file.

If the processor fails or returns an unexpected value, the file gets automatically rejected because the file could be dangerous to ILIAS.

Parameters
FileStream$streamThe stream of the file.
Metadata$metadataThe meta data of the uploaded file.
Returns
ProcessingStatus The new status of the file.

Implements ILIAS\FileUpload\Processor\PreProcessor.

Reimplemented in ilFileServicesPreProcessor.

Definition at line 45 of file AbstractRecursiveZipPreProcessor.php.

45 : ProcessingStatus
46 {
47 if ($this->isFileAZip($metadata)) {
48 try {
49 $zip_file_path = $stream->getMetadata('uri');
50 $zip = new \ZipArchive();
51 $zip->open($zip_file_path);
52
53 for ($i = 0; $i < $zip->numFiles; $i++) {
54 $original_path = $zip->getNameIndex($i);
55 if (!$this->checkPath($original_path)) {
56 return new ProcessingStatus(ProcessingStatus::REJECTED, $this->getRejectionMessage());
57 }
58 }
59 $zip->close();
60 } catch (\Throwable) {
61 return new ProcessingStatus(ProcessingStatus::PENDING, '');
62 }
63 }
64
65 if (!$this->checkPath($metadata->getFilename())) {
66 return new ProcessingStatus(ProcessingStatus::REJECTED, $this->getRejectionMessage());
67 }
68
69 return new ProcessingStatus(ProcessingStatus::OK, $this->getOKMessage());
70 }

References ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor\checkPath(), ILIAS\FileUpload\DTO\Metadata\getFilename(), ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor\getOKMessage(), ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor\getRejectionMessage(), ILIAS\FileUpload\Processor\AbstractRecursiveZipPreProcessor\isFileAZip(), ILIAS\FileUpload\DTO\ProcessingStatus\OK, ILIAS\FileUpload\DTO\ProcessingStatus\PENDING, and ILIAS\FileUpload\DTO\ProcessingStatus\REJECTED.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: