‪TYPO3CMS  ‪main
FileNameValidator.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 {
29  public const ‪DEFAULT_FILE_DENY_PATTERN = '\\.(php[3-8]?|phpsh|phtml|pht|phar|shtml|cgi)(\\..*)?$|\\.pl$|^\\.htaccess$';
30 
34  protected ‪$fileDenyPattern;
35 
36  public function ‪__construct(string ‪$fileDenyPattern = null)
37  {
38  if (‪$fileDenyPattern !== null) {
39  $this->fileDenyPattern = ‪$fileDenyPattern;
40  } elseif (isset(‪$GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'])) {
41  $this->fileDenyPattern = (string)‪$GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'];
42  } else {
43  $this->fileDenyPattern = static::DEFAULT_FILE_DENY_PATTERN;
44  }
45  }
46 
56  public function ‪isValid(string $fileName): bool
57  {
58  $pattern = '/[[:cntrl:]]/';
59  if ($fileName !== '' && $this->fileDenyPattern !== '') {
60  $pattern = '/(?:[[:cntrl:]]|' . $this->fileDenyPattern . ')/iu';
61  }
62  return preg_match($pattern, $fileName) === 0;
63  }
64 
68  public function ‪customFileDenyPatternConfigured(): bool
69  {
70  return $this->fileDenyPattern !== ‪self::DEFAULT_FILE_DENY_PATTERN;
71  }
72 
77  public function ‪missingImportantPatterns(): bool
78  {
79  $defaultParts = explode('|', self::DEFAULT_FILE_DENY_PATTERN);
80  $givenParts = explode('|', $this->fileDenyPattern);
81  $missingParts = array_diff($defaultParts, $givenParts);
82  return !empty($missingParts);
83  }
84 }
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\DEFAULT_FILE_DENY_PATTERN
‪const DEFAULT_FILE_DENY_PATTERN
Definition: FileNameValidator.php:29
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator
Definition: FileNameValidator.php:25
‪TYPO3\CMS\Core\Resource\Security
Definition: FileMetadataPermissionsAspect.php:16
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\isValid
‪bool isValid(string $fileName)
Definition: FileNameValidator.php:55
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\customFileDenyPatternConfigured
‪customFileDenyPatternConfigured()
Definition: FileNameValidator.php:67
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\$fileDenyPattern
‪string $fileDenyPattern
Definition: FileNameValidator.php:33
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\missingImportantPatterns
‪missingImportantPatterns()
Definition: FileNameValidator.php:76
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\__construct
‪__construct(string $fileDenyPattern=null)
Definition: FileNameValidator.php:35