From 5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 6 Nov 2024 19:39:38 +0100 Subject: [PATCH] Fix code --- src/Extension/CoreExtension.php | 2 +- src/Node/Expression/GetAttrExpression.php | 2 +- tests/Extension/CoreTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 1e769c6a2b6..b077e796304 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -1571,7 +1571,7 @@ public static function getAttribute(Environment $env, Source $source, $object, $ if (/* Template::METHOD_CALL */ 'method' !== $type) { $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; - if ($sandboxed && $object instanceof \ArrayAccess && !\in_array($object::class, self::ARRAY_LIKE_CLASSES, true)) { + if ($sandboxed && $object instanceof \ArrayAccess && !\in_array(get_class($object), self::ARRAY_LIKE_CLASSES, true)) { try { $env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $arrayItem, $lineno, $source); } catch (SecurityNotAllowedPropertyError $propertyNotAllowedError) { diff --git a/src/Node/Expression/GetAttrExpression.php b/src/Node/Expression/GetAttrExpression.php index 2181b0f7862..f54f2f09d54 100644 --- a/src/Node/Expression/GetAttrExpression.php +++ b/src/Node/Expression/GetAttrExpression.php @@ -67,7 +67,7 @@ public function compile(Compiler $compiler): void ->raw(') || ') ->raw($var) ->raw(' instanceof ArrayAccess && in_array(') - ->raw($var.'::class') + ->raw('get_class('.$var.')') ->raw(', CoreExtension::ARRAY_LIKE_CLASSES, true) ? (') ->raw($var) ->raw('[') diff --git a/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index 5b8268492a2..0c397b6ec88 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -325,7 +325,7 @@ public function testSandboxedInclude() 'index' => '{{ include("included", sandboxed=true) }}', 'included' => '{{ "included"|e }}', ])); - $policy = new SecurityPolicy(allowedFunctions: ['include']); + $policy = new SecurityPolicy([], [], [], [], ['include']); $sandbox = new SandboxExtension($policy, false); $twig->addExtension($sandbox); @@ -340,7 +340,7 @@ public function testSandboxedIncludeWithPreloadedTemplate() 'index' => '{{ include("included", sandboxed=true) }}', 'included' => '{{ "included"|e }}', ])); - $policy = new SecurityPolicy(allowedFunctions: ['include']); + $policy = new SecurityPolicy([], [], [], [], ['include']); $sandbox = new SandboxExtension($policy, false); $twig->addExtension($sandbox);