mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-17 11:41:37 +00:00
Add regression tests that always-allowed callables still enforce the sandbox __toString policy on arguments
This commit is contained in:
@@ -2112,6 +2112,26 @@ EOF
|
||||
$twig->load('index')->render([]);
|
||||
}
|
||||
|
||||
public function testAlwaysAllowedInSandboxFilterStillEnforcesToStringPolicyOnArguments()
|
||||
{
|
||||
$twig = $this->getEnvironment(true, [], ['index' => '{{ obj|safe_upper }}']);
|
||||
$twig->addFilter(new TwigFilter('safe_upper', static fn (string $s) => strtoupper($s), ['always_allowed_in_sandbox' => true]));
|
||||
|
||||
$this->expectException(SecurityNotAllowedMethodError::class);
|
||||
$this->expectExceptionMessage('Calling "__tostring" method on a "'.FooObject::class.'" object is not allowed');
|
||||
$twig->load('index')->render(['obj' => new FooObject()]);
|
||||
}
|
||||
|
||||
public function testAlwaysAllowedInSandboxFunctionStillEnforcesToStringPolicyOnArguments()
|
||||
{
|
||||
$twig = $this->getEnvironment(true, [], ['index' => '{{ safe_greet(obj) }}']);
|
||||
$twig->addFunction(new TwigFunction('safe_greet', static fn (string $s) => "hi $s", ['always_allowed_in_sandbox' => true]));
|
||||
|
||||
$this->expectException(SecurityNotAllowedMethodError::class);
|
||||
$this->expectExceptionMessage('Calling "__tostring" method on a "'.FooObject::class.'" object is not allowed');
|
||||
$twig->load('index')->render(['obj' => new FooObject()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user