Skip to content

Adopt DataFlowNode::getForTaint() and require Psalm 7.0.0-beta21 - #1456

Merged
alies-dev merged 7 commits into
masterfrom
fix/psalm-beta21-getfortaint
Sep 15, 2026
Merged

alies-dev merged 7 commits into
masterfrom
fix/psalm-beta21-getfortaint

Conversation

@alies-dev

@alies-dev alies-dev commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Issue to Solve

Self-analysis and every taint run fail on Psalm 7.0.0-beta21:

ERROR: UndefinedMethod
at src/Handlers/Rules/TimingUnsafeComparisonHandler.php:288:17
Method Psalm\Internal\DataFlow\DataFlowNode::getfortaintsink does not exist

At runtime it is fatal, not just a reported issue, so the whole type suite aborts on the first === / strcmp() comparison that reaches the handler:

Uncaught Error: Call to undefined method Psalm\Internal\DataFlow\DataFlowNode::getForTaintSink()

The accompanying MixedAssignment and MixedArgument at the same call site are cascade from the unknown method's mixed return.

Related

No tracking issue.

Solution Description

Upstream timeline (probed against release tags):

tag make() getForTaintSink() getForTaint()
7.0.0-beta19 public absent absent
7.0.0-beta20 private added absent
7.0.0-beta21 private removed added

beta21 merged the source and sink factories into one getForTaint(). Direction is now decided by whether the node goes to TaintFlowGraph::addSource() or addSink(), and the location is always derived from $code_location instead of an independent fourth ?CodeLocation $specialization_location argument. Upstream's rationale: the independent location let one node id resolve to different locations per forked worker, so whichever worker registered the id first won the merge and taint findings shifted between runs.

The first three parameters are unchanged (string $taint_id, CodeLocation $code_location, int $taints), so the call site is a rename. The stale comment naming the old factory is updated with it.

DataFlowNode lives under Psalm\Internal\, outside the stable plugin API surface, so it changes without a deprecation cycle. Since getForTaintSink() existed only in beta20, there is no constraint that spans both: the floor moves to ^7.0.0-beta21 in composer.json, and docs/upgrade-v4.md follows.

Verified on 7.0.0-beta21:

  • composer psalm (with --find-dead-code --find-unused-psalm-suppress): No errors found, 100% type coverage.
  • composer test:unit: 1271 tests green.
  • composer test:type: 758 tests, 11 failures, all pre-existing under beta21 and unrelated to this change (see below).

Known issue: beta21 taint regressions, not introduced here

Pinning the same checkout back to 7.0.0-beta20 (this commit reverted, since the rename requires beta21) gives a fully green type suite. On beta21 the same suite fails 11 taint tests, deterministically:

  • 10 Safe* tests lose an expected TaintedSSRF on a PendingRequest::get() sink (false negatives).
  • TaintedShellWhereValueFlowPreserved reports its TaintedShell twice.

Near-identical sibling tests still pass, and running Psalm directly on one failing fixture's source does report the TaintedSSRF. The finding only disappears when the fixture is co-analyzed with the rest of its --ARGS-- group, which points at beta21's changed node id and specialization-key derivation altering cross-file node merging. That is the same upstream area this rename comes from.

Filed upstream as vimeo/psalm#11959. This PR is the prerequisite either way, since without it no taint run on beta21 completes at all.

Also here: holding laravel/framework below 13.32

laravel/framework v13.32.0 (Collection.php#L1061, added by laravel/framework#61571) ships the first docblock of this shape:

@phpstan-this-out ($key is null ? static<TKey|int, TValue> : $this)

Psalm 7 cannot parse a this-out whose type is a conditional keyed on a parameter. It throws an uncaught TypeParseTreeException: Unrecognized template '$key' from TypeParser during the scan phase, before any issue is reported, so every job analysing a project that resolves laravel/framework >= 13.32 dies outright:

Uncaught Psalm\Exception\TypeParseTreeException: Unrecognized template '$key' in .../Internal/Type/TypeParser.php:342
(Psalm 7.0.0-beta21@5df32a9 crashed due to an uncaught Throwable)

$key is a declared parameter of prepend(), and the same conditional in @return parses, so the docblock is valid. Reproduced on 6.17.2 and 7.0.0-beta20 as well, with a 20-line plugin-free fixture, so it is neither a beta21 regression nor plugin-caused. Filed upstream as vimeo/psalm#11958.

composer.json is deliberately NOT pinned. Its require-dev is what contributors install locally, and holding the framework back there would hide the crash from anyone developing the plugin rather than only from CI. The hold lives in the workflows instead, temporary and commented inline with @see:

  • tests.yml, three cells, each reaching 13.32 by a different route: the type-test matrix constraint, the unit-test lockfile cells installing straight from composer.json, and both laravel/ai legs. Cells pinned to an exact framework version already resolve below 13.32 and are untouched. Type-test job names now carry the bounded constraint instead of ^13.3.
  • the fresh-app leg, via a new LARAVEL_FRAMEWORK_CONSTRAINT hook in laravel-test.sh, applied only to the dev-master cells. The 12.12.2 cells keep resolving exactly what laravel/laravel pins.

Taint fixtures gated on the broken Psalm release

With the crash held off, the remaining failures were vimeo/psalm#11959: 11 taint fixtures losing their finding in the co-analyzed batch (TaintedShellWhereValueFlowPreserved reports its own twice), plus 2 PromptInjection fixtures that join them once laravel/ai shifts the batch. Each still passes when analysed on its own.

They are gated through a new PsalmVersion::skipOnRange('7.0.0-beta21', '7.0.0-beta22'), not the one-sided LaravelVersion-style gate. Both bounds are required deliberately: the skip covers exactly beta21, so the next Psalm release re-enables all thirteen and they go red again if the bug survived. A one-sided skipFrom would go stale silently and cost the coverage for good. Every gate carries @todo-by 2026-10-01 and the issue link.

Measured locally on beta21 + laravel v13.31.0: type suite 758 tests, 0 failures, 64 skipped (53 pre-existing + the 13 gated); unit suite 1271 green; self-analysis clean at 100% type coverage; composer cs and composer rector no-ops.

Measured, on this checkout: psalm beta21 + laravel v13.31.0 green at 100% type coverage; psalm beta21 + v13.32.0 crashes; psalm beta20 + v13.32.0 crashes identically.

Checklist

  • Tests cover the change (existing tests/Type/tests/TaintAnalysis/TimingUnsafe*.phpt, 11 tests, exercise the rewritten call site and pass)
  • Documentation is updated (docs/upgrade-v4.md Psalm floor)

Psalm 7.0.0-beta21 renamed `DataFlowNode::getForTaintSink()` to
`getForTaint()` and dropped its fourth parameter: source and sink share one
factory now, and the direction is decided by whether the node is handed to
`TaintFlowGraph::addSource()` or `addSink()`. The location is always derived
from `$code_location`, so `id -> location` stays a pure function (an
independent specialization location let one node id resolve to different
locations per forked worker, making taint findings shift between runs).

`getForTaintSink()` only ever existed in beta20, so the floor moves to
beta21 rather than widening the constraint: the class lives under
`Psalm\Internal\`, outside the stable plugin API, and changes there ship
without a deprecation cycle.

The first three arguments are unchanged, so the call site is a rename.
@alies-dev alies-dev self-assigned this Sep 15, 2026
…locks

laravel/framework v13.32.0 added a `@phpstan-this-out` whose type is a
conditional keyed on a parameter, on `Collection::prepend()`:

    @phpstan-this-out ($key is null ? static<TKey|int, TValue> : $this)

Psalm 7 cannot parse that shape. It throws an uncaught
`TypeParseTreeException: Unrecognized template '$key'` from `TypeParser` during
the scan phase, before a single issue is reported, so every job that analyses a
project resolving laravel/framework >= 13.32 dies outright. `$key` is a declared
parameter of `prepend()`, and the same conditional in `@return` parses, so the
docblock is not at fault.

The crash reproduces on 7.0.0-beta20 as well, so it is neither a beta21
regression nor caused by this plugin: it is upstream, newly reachable because
Laravel shipped the first docblock of that shape.

Two places pin it:

- composer.json's require-dev constraint, which covers self-analysis and the
  unit and type suites. require/ is untouched, so nothing is imposed on users.
- the fresh-app leg, via a new LARAVEL_FRAMEWORK_CONSTRAINT hook in
  laravel-test.sh, applied only to the dev-master cells. The 12.12.2 cells keep
  resolving exactly what laravel/laravel pins.

Both are temporary and carry the rationale inline; drop them once Psalm parses
the tag.
Keeps the pin confined to the fresh-app workflow cells. composer.json's
require-dev is what contributors install locally, and holding the framework
back there hides the crash from anyone developing the plugin rather than only
from CI.

The fresh-app hook in laravel-test.sh stays: that leg builds its own app and is
not covered by this constraint either way.
The gate is temporary, so the thing a reader needs first is what has to happen
upstream before it can go. Linked at the variable and at the gate itself, since
either is a plausible entry point.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Laravel version workaround must also cover the regular Psalm and type-test jobs to prevent CI crashes.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates the plugin for Psalm 7 beta21 and adds a temporary Laravel compatibility workaround.

Changes:

  • Replaces getForTaintSink() with getForTaint().
  • Raises the Psalm requirement to beta21 and updates documentation.
  • Adds an optional Laravel framework constraint for fresh-app CI.
File summaries
File Summary
tests/Application/laravel-test.sh Supports framework version constraints.
src/Handlers/Rules/TimingUnsafeComparisonHandler.php Uses Psalm beta21’s taint factory.
docs/upgrade-v4.md Documents the updated Psalm requirement.
composer.json Raises the Psalm dependency floor.
.github/workflows/test-laravel-app.yml Pins fresh-app dev-master cells below Laravel 13.32; other Psalm/type-test jobs remain unprotected.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/test-laravel-app.yml Resolved
laravel/framework v13.32.0 added a `@phpstan-this-out` whose type is a
conditional keyed on a parameter, on `Collection::prepend()`. Psalm cannot
parse that shape and throws an uncaught TypeParseTreeException from TypeParser
during the scan phase, before a single issue is reported, so every cell
resolving 13.32 analyses nothing at all. Upstream: vimeo/psalm#11958. It
reproduces on Psalm 6.17.2 too, so it is neither a beta21 regression nor
plugin-caused.

Held in the workflow rather than in composer.json, so that a contributor
installing locally still meets the crash instead of having it papered over.
Three cells needed it, each reaching 13.32 by a different route:

- type tests, via the matrix constraint
- unit tests, in the lockfile cells that install straight from composer.json
- both laravel/ai legs, same plain install

The cells pinned to an exact framework version already resolve below 13.32 and
are untouched.

The type-test job names now carry the bounded constraint instead of ^13.3.
Restore the matrix to ^13.3 when the pin goes.
Missed in the previous commit. This job installs straight from composer.json,
so it reaches v13.32.0 and crashes in Psalm's scan phase before analysing
anything, same as the test cells. Upstream: vimeo/psalm#11958.

Placed ahead of the cache restore deliberately: the cache key hashes
composer.lock, which this step rewrites, so pinning afterwards would key the
snapshot on a resolution that never ran.

install-smoke.yml installs the same way and will hit the same crash, but it
runs weekly rather than per pull request, so it is left for the upstream fix.
beta21 drops one of two taint flows that reach the same sink method from two
different files in a co-analyzed batch. Eleven fixtures lose their finding that
way, and TaintedShellWhereValueFlowPreserved reports its finding twice; with
laravel/ai installed the batch shifts and two PromptInjection fixtures join
them. Each still passes when analysed on its own. Upstream: vimeo/psalm#11959.

Gated through a new PsalmVersion::skipOnRange(), not the existing
LaravelVersion-style one-sided gate. Both bounds are required on purpose: the
skip covers exactly 7.0.0-beta21, so the next Psalm release re-enables all
thirteen and they go red again if the bug survived. A one-sided skipFrom would
go stale silently and quietly cost the coverage for good.

Every gate carries a @todo-by 2026-10-01 and the issue link.

The PromptInjection pair keeps its existing laravel/ai guard first, now with an
explicit return so only one skip reason is printed.
@alies-dev
alies-dev merged commit bfc5fbe into master Sep 15, 2026
34 checks passed
@alies-dev
alies-dev deleted the fix/psalm-beta21-getfortaint branch September 15, 2026 21:43
@alies-dev alies-dev added release:fix for PRs only (used by release-drafter) release:internal for PRs only (used by release-drafter) labels Sep 15, 2026
@alies-dev alies-dev mentioned this pull request Sep 15, 2026
2 tasks done
@alies-dev

Copy link
Copy Markdown
Collaborator Author

Follow-up: #1457 removes every temporary guard added here, as a draft to merge once vimeo/psalm#11958 and vimeo/psalm#11959 are both fixed and released.

@alies-dev

Copy link
Copy Markdown
Collaborator Author

Correction to the follow-up note above: #1457 was split in two, so neither upstream fix waits on the other. #1458 removes the laravel/framework 13.32 pins (vimeo/psalm#11958); #1459 removes the taint fixture gates (vimeo/psalm#11959). Both are drafts.

alies-dev added a commit that referenced this pull request Sep 15, 2026
…locks (#1460)

laravel/framework v13.32.0 added a @phpstan-this-out docblock on
Collection::prepend() with a parameter conditional. Psalm cannot
parse that shape and throws an uncaught TypeParseTreeException from
TypeParser during the scan phase, before a single issue is reported,
so every job resolving that release analyses nothing at all.
Reproduces on Psalm 6.17.2, so it is not caused by this plugin.

Held in the workflows and in the fresh-app leg's
LARAVEL_FRAMEWORK_CONSTRAINT hook rather than in composer.json, so a
contributor installing locally still meets the crash instead of
having it papered over. Ports the CI-only portion of master's
bfc5fbe (#1456) to the 3.x/Psalm 6 line.

Upstream: vimeo/psalm#11958
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix for PRs only (used by release-drafter) release:internal for PRs only (used by release-drafter)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants