‪TYPO3CMS  9.5
PharStreamWrapperInterceptor.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 namespace ‪TYPO3\CMS\Core\IO;
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 
20 use TYPO3\PharStreamWrapper\Assertable;
21 use TYPO3\PharStreamWrapper\Exception;
22 use TYPO3\PharStreamWrapper\Manager;
23 use TYPO3\PharStreamWrapper\Resolver\PharInvocationResolver;
24 
25 class ‪PharStreamWrapperInterceptor implements Assertable
26 {
36  public function ‪assert(string $path, string $command): bool
37  {
38  if ($this->‪isAllowed($path) === true) {
39  return true;
40  }
41  throw new Exception(
42  sprintf('Executing %s is denied', $path),
43  1530103998
44  );
45  }
46 
51  protected function ‪isAllowed(string $path): bool
52  {
53  $invocation = Manager::instance()->resolve($path, PharInvocationResolver::RESOLVE_ALIAS);
54  if ($invocation === null) {
55  return false;
56  }
57  $baseName = $invocation->getBaseName();
58  return GeneralUtility::validPathStr($baseName)
59  && GeneralUtility::isFirstPartOfStr($baseName, ‪Environment::getExtensionsPath());
60  }
61 }
‪TYPO3\CMS\Core\IO\PharStreamWrapperInterceptor
Definition: PharStreamWrapperInterceptor.php:26
‪TYPO3\CMS\Core\IO\PharStreamWrapperInterceptor\assert
‪bool assert(string $path, string $command)
Definition: PharStreamWrapperInterceptor.php:36
‪TYPO3\CMS\Core\IO
Definition: CsvStreamFilter.php:18
‪TYPO3\CMS\Core\IO\PharStreamWrapperInterceptor\isAllowed
‪bool isAllowed(string $path)
Definition: PharStreamWrapperInterceptor.php:51
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Core\Environment\getExtensionsPath
‪static string getExtensionsPath()
Definition: Environment.php:245