Inconsistency with variable evaluation when autoescaping is enabled
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 8.4k
- Forks
- 1.3k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 37
Description
Consider the following template:
{{ (br == "<br/>") ? "true" : "false" }}
{{ (include("partial.twig") == "<br/>") ? "true" : "false" }}
With partial.twig being:
{{ br }}
Executing this template with "<br/>" as value for the br variable outputs:
true
false
In both conditions, we test that the value of the variable br is equal to "<br/>". But in the second case only, it is considered as false.
Why is a variable considered as safe for evaluation in one case and not the other? I understand the technical reason - "in the second case what is evaluated is the result of the inclusion", I'm more interested in the philosophical reasons: why is a template inclusion considered as less safe than a variable inclusion even though a variable value is more likely to be provided at runtime (and thus to be unsafe) than a template inclusion?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two expressions with the provided template and twigfiddle example, then trace autoescaping and include evaluation in the implementation. No repository files or tests are named; done would require an agreed explanation of the differing safety behavior and a clearly defined follow-up change or documentation update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- security, web-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100