Conversation
danog
force-pushed
the
twig-callable-taints
branch
2 times, most recently
from
October 3, 2026 13:20
8c2e7ef to
4bafd17
Compare
danog
force-pushed
the
twig-callable-taints
branch
from
October 5, 2026 08:44
4bafd17 to
8211de8
Compare
Member
Author
|
Merged into #392. |
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.
Builds on #390 (and #389), whose commits come first here.
A Twig filter is PHP code, but the taint analysis passed what it is given through to what it returns whatever it does. A custom escaping filter (
{{ name|esc|raw }}, withesccallinghtmlspecialchars()and declaring@psalm-taint-escape html) was reported like{{ name|raw }}, and so was a filter returning a number ({{ items|length|raw }}).What a filter returns now takes the taints of what it is given, but those its PHP callable removes: those its storage says it escapes (
@psalm-taint-escape), and those its native return type cannot hold (intforlength). The callable is found among the filters of the extensions given to the analysis (the last extension declaring a filter wins, as in Twig): a function, aClass::methodstring, a[class, method]array, or a first-class callable (self::escape(...)). A closure, or a callable Psalm does not know, removes nothing.TemplateFileScanner(#390) is also marked@psalm-api: only configurations use it, so--find-dead-codereported it.Tests: 2 new scenarios in
TwigTaintingWithAnalyzer.feature, a filter returning a number (fails without this change) and one returning what it is given, displayed raw. The feature passes, and so doespsalm --find-dead-code.