‪TYPO3CMS  10.4
PharStreamWrapperInterceptor.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 
18 namespace ‪TYPO3\CMS\Core\IO;
19 
22 use TYPO3\PharStreamWrapper\Assertable;
23 use TYPO3\PharStreamWrapper\Exception;
24 use TYPO3\PharStreamWrapper\Manager;
25 use TYPO3\PharStreamWrapper\Resolver\PharInvocationResolver;
26 
27 class ‪PharStreamWrapperInterceptor implements Assertable
28 {
38  public function ‪assert(string $path, string $command): bool
39  {
40  if ($this->‪isAllowed($path) === true) {
41  return true;
42  }
43  throw new Exception(
44  sprintf('Executing %s is denied', $path),
45  1530103998
46  );
47  }
48 
53  protected function ‪isAllowed(string $path): bool
54  {
55  $invocation = Manager::instance()->resolve($path, PharInvocationResolver::RESOLVE_ALIAS);
56  if ($invocation === null) {
57  return false;
58  }
59  $baseName = $invocation->getBaseName();
60  return GeneralUtility::validPathStr($baseName)
61  && GeneralUtility::isFirstPartOfStr($baseName, ‪Environment::getExtensionsPath());
62  }
63 }
‪TYPO3\CMS\Core\IO\PharStreamWrapperInterceptor
Definition: PharStreamWrapperInterceptor.php:28
‪TYPO3\CMS\Core\IO\PharStreamWrapperInterceptor\assert
‪bool assert(string $path, string $command)
Definition: PharStreamWrapperInterceptor.php:38
‪TYPO3\CMS\Core\IO
Definition: CsvStreamFilter.php:18
‪TYPO3\CMS\Core\IO\PharStreamWrapperInterceptor\isAllowed
‪bool isAllowed(string $path)
Definition: PharStreamWrapperInterceptor.php:53
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Core\Environment\getExtensionsPath
‪static string getExtensionsPath()
Definition: Environment.php:271