Twig icon indicating copy to clipboard operation
Twig copied to clipboard

Security policy wildcard support for methods/properties

Open YSaxon opened this issue 2 years ago • 2 comments

Allows for flexible wildcard support in allowedMethods and allowedProperties in SecurityPolicy.

  • Class can be specified as wildcard, * => ['foo',...] in order to allow those methods/properties for all classes.
  • Method/property can be specified as wildcard eg. \Foo\Bar\Baz => '*' in order to allow all methods/properties for that class.
  • Method/property can also be specified with a trailing wildcard to allow all methods/properties with a certain prefix, eg. \Foo\Bar\Baz => ['get*', ...] in order to allow all Baz methods/properties that start with get.

Here are some real examples of security policy items that previously had to be hardcoded that can now be expressed with wildcards:

'Twig\Template' => '*',
'Twig\Markup' => '*'
Drupal\Core\Template\Attribute => '*'
'*' => ['get*', 'has*', 'is*', '__toString', 'toString', 'id', 'label', 'bundle']

YSaxon avatar Oct 27 '23 18:10 YSaxon

I forgot to mention that overall I'm not sold yet this is something I want in core. I very much prefer white-listing explicitly what is allowed. With *, future methods/properties/classes will be automatically "accepted", which can be problematic.

fabpot avatar Dec 19 '23 07:12 fabpot

Or maybe that's fine but we need to make it very clear in the docs that this should be used with caution (can you some docs for this new feature?).

fabpot avatar Dec 19 '23 10:12 fabpot