ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor Class Reference

Class InsecureFilenameSanitizerPreProcessor. More...

+ Inheritance diagram for ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor:
+ Collaboration diagram for ILIAS\MetaData\Repository\Validation\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...
 

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\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor::checkPath ( string  $path)
abstractprotected
Parameters
string$pathto a file
Returns
bool false leads to rejection, true to accept

Referenced by ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor\process().

+ Here is the caller graph for this function:

◆ getOKMessage()

ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor::getOKMessage ( )
abstractprotected

Referenced by ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor\process().

+ Here is the caller graph for this function:

◆ getRejectionMessage()

ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor::getRejectionMessage ( )
abstractprotected

Referenced by ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor\process().

+ Here is the caller graph for this function:

◆ isFileAZip()

ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor::isFileAZip ( Metadata  $metadata)
private

Definition at line 72 of file AbstractRecursiveZipPreProcessor.php.

Referenced by ILIAS\MetaData\Repository\Validation\Processor\AbstractRecursiveZipPreProcessor\process().

72  : bool
73  {
74  return $this->isMimeTypeOrExtension(
75  $metadata,
76  'zip',
77  ['application/zip', 'application/x-zip-compressed']
78  );
79  }
+ Here is the caller graph for this function:

◆ process()

ILIAS\MetaData\Repository\Validation\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\MetaData\Repository\Validation\Processor\PreProcessor.

Definition at line 45 of file AbstractRecursiveZipPreProcessor.php.

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

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  }
+ Here is the call graph for this function:

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