‪TYPO3CMS  10.4
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 
70  public function ‪customFileDenyPatternConfigured(): bool
71  {
72  return $this->fileDenyPattern !== ‪self::DEFAULT_FILE_DENY_PATTERN;
73  }
74 
81  public function ‪missingImportantPatterns(): bool
82  {
83  $defaultParts = explode('|', self::DEFAULT_FILE_DENY_PATTERN);
84  $givenParts = explode('|', $this->fileDenyPattern);
85  $missingParts = array_diff($defaultParts, $givenParts);
86  return !empty($missingParts);
87  }
88 }
‪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\$fileDenyPattern
‪string $fileDenyPattern
Definition: FileNameValidator.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\missingImportantPatterns
‪bool missingImportantPatterns()
Definition: FileNameValidator.php:80
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\customFileDenyPatternConfigured
‪bool customFileDenyPatternConfigured()
Definition: FileNameValidator.php:69
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator\__construct
‪__construct(string $fileDenyPattern=null)
Definition: FileNameValidator.php:35