function PharExtensionInterceptor::assert

Same name in other branches
  1. 7.x misc/typo3/phar-stream-wrapper/src/Interceptor/PharExtensionInterceptor.php \TYPO3\PharStreamWrapper\Interceptor\PharExtensionInterceptor::assert()
  2. 7.x misc/typo3/drupal-security/PharExtensionInterceptor.php \Drupal\Core\Security\PharExtensionInterceptor::assert()
  3. 8.9.x core/lib/Drupal/Core/Security/PharExtensionInterceptor.php \Drupal\Core\Security\PharExtensionInterceptor::assert()

Determines whether phar file is allowed to execute.

The phar file is allowed to execute if:

  • the base file name has a ".phar" suffix.
  • it is the CLI tool that has invoked the interceptor.

Parameters

string $path: The path of the phar file to check.

string $command: The command being carried out.

Return value

bool TRUE if the phar file is allowed to execute.

Throws

\TYPO3\PharStreamWrapper\Exception Thrown when the file is not allowed to execute.

File

core/lib/Drupal/Core/Security/PharExtensionInterceptor.php, line 40

Class

PharExtensionInterceptor
An alternate PharExtensionInterceptor to support phar-based CLI tools.

Namespace

Drupal\Core\Security

Code

public function assert(string $path, string $command) : bool {
    if ($this->baseFileContainsPharExtension($path)) {
        return TRUE;
    }
    throw new Exception(sprintf('Unexpected file extension in "%s"', $path), 1535198703);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.