Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SecurityPolicy.php

function SecurityPolicy::checkSecurity

Overrides SecurityPolicyInterface::checkSecurity

File

vendor/twig/twig/src/Sandbox/SecurityPolicy.php, line 67

Class

SecurityPolicy
Represents a security policy which need to be enforced when sandbox mode is enabled.

Namespace

Twig\Sandbox

Code

public function checkSecurity($tags, $filters, $functions) : void {
    foreach ($tags as $tag) {
        if (!\in_array($tag, $this->allowedTags)) {
            if ('extends' === $tag) {
                trigger_deprecation('twig/twig', '3.12', 'The "extends" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitly in your sandbox policy if needed.');
            }
            elseif ('use' === $tag) {
                trigger_deprecation('twig/twig', '3.12', 'The "use" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitly in your sandbox policy if needed.');
            }
            else {
                throw new SecurityNotAllowedTagError(\sprintf('Tag "%s" is not allowed.', $tag), $tag);
            }
        }
    }
    foreach ($filters as $filter) {
        if (!\in_array($filter, $this->allowedFilters)) {
            throw new SecurityNotAllowedFilterError(\sprintf('Filter "%s" is not allowed.', $filter), $filter);
        }
    }
    foreach ($functions as $function) {
        if (!\in_array($function, $this->allowedFunctions)) {
            throw new SecurityNotAllowedFunctionError(\sprintf('Function "%s" is not allowed.', $function), $function);
        }
    }
}
RSS feed
Powered by Drupal