Optional defaults for SecurityPolicy #3902
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an implementation of Defaults for the Twig Security Policy.
The idea is that there should be a set of known safe values that a user can whitelist. The goals for the pull request were:
I've implemented this via a special value or "token", meant to be referred to as SecurityPolicyDefaults::INCLUDE_DEFAULTS, which, if included as a value in any of the whitelist config arguments, will be replaced and merged with the actual hardcoded default values.
So for instance if you want to trust all of the default filters, plus your own custom filters
format_number
andformat_currency
and 'format_currency', you can initialize your SecurityPolicy with$allowedFilters = ['format_number', 'format_currency', SecurityPolicyDefaults::INCLUDE_DEFAULTS]
, and the actual allowedFilters will end up as['format_number', 'format_currency','abs','batch','capitalize', 'date', 'date_modify', ...]
.Note that I haven't done extensive research for the present list of defaults. They are intended as a proof-of-concept sample for the purpose of the pull request, and should definitely be reviewed thoroughly before actually accepting and merging.