[3.x, 4.x, 5.x]: Template::attribute()
bypasses Twig SandboxExtension's SecurityPolicy
#15278
Labels
Template::attribute()
bypasses Twig SandboxExtension's SecurityPolicy
#15278
What happened?
Description
The
Template::attribute()
method (which is what is called whenever accessing an object property in the PHP compiled from Twig) does the following:This bypasses the call later in that function to
twig_get_attribute()
, which means that if the Twig SandboxExtension is used with a SecurityPolicy, theSecurityPolicy::checkPropertyAllowed()
method is never called.This makes it impossible to implement a SecurityPolicy that restricts access to properties on any object that is an instance of
BaseObject
(which just about everything in Craft is)For instance, if you wanted to restrict access to:
...you can't do it, because the Twig layer that implements sandbox security checks is never called, because the
DbConfig
object inherits fromBaseObject
, so the property value is just returned.Steps to reproduce
::checkPropertyAllowed()
entry.title
on anyBaseObject
objectExpected behavior
It would be possible to use the SandboxExtension with a SecurityPolicy that restricts access to object properties.
This fixes the issue, allowing the SandboxExtension to optionally throw an exception before the property is returned:
This mirrors what
twig_get_attribute()
does.Actual behavior
It's not possible :)
Craft CMS version
3.x, 4.x, 5.x
PHP version
n/a
Operating system and version
n/a
Database type and version
n/a
Image driver and version
n/a
Installed plugins and versions
n/a
The text was updated successfully, but these errors were encountered: