Skip to content

Declare that assertions return their checked value to Psalm's taint analysis - #371

Open
danog wants to merge 1 commit into
webmozarts:masterfrom
danog:assert-taint-flow
Open

danog wants to merge 1 commit into
webmozarts:masterfrom
danog:assert-taint-flow

Conversation

@danog

@danog danog commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Since 2.0 every assertion returns the value it checked, but Psalm's taint analysis doesn't analyse library code, so a tainted input passed through e.g. $id = Assert::stringNotEmpty($_GET['id']) comes out clean and the taint is lost.

This adds @psalm-flow ($value) -> return (or the checked parameter: $array, $classOrObject, $values, $callable, $expression) to every assertion in Assert, and @psalm-taint-specialize to the assertions that aren't @psalm-pure (pure ones are specialized already), so the taint of one call doesn't leak into the others.

Mixin is regenerated with composer generate-mixin: the generator copies the annotations to the nullOr*, all* and allNullOr* variants, which also return their first argument. The generator change only adds a blank line after @psalm-flow to keep the generated docblocks tidy.

https://claude.ai/code/session_016B9dWRw6Lako9sXAWMtWAx

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant