Repository navigation
Fix a variable not being escaped when it has the name of a macro import alias of another scope - #5039
Open
jack-worman wants to merge 2 commits into
Open
jack-worman wants to merge 2 commits into
jack-worman wants to merge 2 commits into
Conversation
…rt alias of another scope Since 3.0, calls on an import alias compile to macro references, which are always safe, so the import alias "safe variables" rule only ever matched ordinary variables sharing the alias name, such as a loop variable or macro argument in another block or macro.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The escaper treats
x.attr,x['key']andx.method()as safe whenever{% import … as x %}appears anywhere in the template. That rule (8832b66) dates from when macro calls compiled to attribute reads on the alias. Since 3.0 they compile to macro references (MacroReferenceExpressiontoday), which are already safe, so the rule only matches ordinary variables that share the alias name in another block or macro, and prints them unescaped:{% block header %}{% import _self as item %}{{ item.hello() }}{% endblock %} {% block content %}{% for item in items %}{{ item.body }}{% endfor %}{% endblock %}item.bodyis output raw. The same happens with an import in one macro and an argument of that name in a later macro, and with a top-level import placed after the block that uses the name.This removes the rule. Macro calls through an alias stay safe through
MacroReferenceExpression, andattribute(alias, 'name')can't reach macros, since aliases live in$macros, not in the context.