Skip to content

Taint the items destructured from a mixed value or an ArrayAccess object - #14225

Merged
danog merged 3 commits into
vimeo:masterfrom
danog:destructure-mixed-taint
Nov 23, 2026
Merged

danog merged 3 commits into
vimeo:masterfrom
danog:destructure-mixed-taint

Conversation

@danog

@danog danog commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

mixed values

Psalm misses taints in the items destructured from a mixed value, such as a row from PDOStatement::fetch().

Before

<?php
function get(): mixed {
    return ["safe", $_GET["x"]];
}

[$first, $second] = get();
echo (string) $second; // no issue

After

echo (string) $second; // TaintedHtml

ArrayAccess objects

Psalm misses taints in the items destructured from an ArrayAccess object.

Before

<?php
$values = new ArrayObject($_GET);
[$first] = $values;
echo (string) $first; // no issue

After

echo (string) $first; // TaintedHtml

@danog danog added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 19, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 9f8b011. Configure here.

$array_type,
$offset_value,
Type::getMixed(),
)->parent_nodes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mixed check ignores assigned type

Medium Severity

addDestructuredVariableDataFlow runs the mixed-only destructuring taint path when array_type->hasMixed() is true, but the method’s own docblock says this flow applies when the assigned variable’s type stays mixed. After a concrete item type is merged into new_assign_type, the variable may no longer be mixed while the RHS union still is, so an extra mixed destructuring fetch can attach incorrect taint parents.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9f8b011. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not a bug: the extra fetch takes the item at the same offset from the same value the array path fetches it from, so it adds no taint the item does not hold (and Psalm collapses a union with mixed to mixed, so in practice the value is mixed alone). The docblock read like a condition on the type; reworded in cf17644.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 768 75.2 $\color{gray}{\textsf{+0.6\%}}$ 25 691 52 994 682 0
✅ symfony 3 627 170.1 $\color{gray}{\textsf{-1.9\%}}$ 50 654 98 398 1 572 0
✅ doctrine-orm 380 15.6 $\color{gray}{\textsf{+1.0\%}}$ 3 476 6 143 0 0
✅ psl 617 20.4 $\color{gray}{\textsf{-1.0\%}}$ 1 375 5 597 1 0
✅ phpunit 455 18.7 $\color{gray}{\textsf{+0.8\%}}$ 1 731 3 410 18 0
✅ php-parser 226 12.4 $\color{gray}{\textsf{-0.4\%}}$ 17 118 21 193 0 0
✅ tempest 895 33.5 $\color{gray}{\textsf{-0.1\%}}$ 5 040 10 507 252 0
✅ amphp-amp 45 1.2 $\color{gray}{\textsf{+1.6\%}}$ re-run 29 49 0 0
✅ webmozarts-assert 272 3.7 $\color{gray}{\textsf{-0.8\%}}$ 575 2 714 0 0
✅ guzzle-promises 44 1.3 $\color{gray}{\textsf{-1.5\%}}$ 155 434 2 0
✅ monolog 135 4.7 $\color{gray}{\textsf{+2.2\%}}$ 913 2 479 10 0
✅ drupal 4 843 177.0 $\color{gray}{\textsf{-0.6\%}}$ 97 648 169 347 575 0
✅ wordpress 2 040 193.6 $\color{gray}{\textsf{+1.8\%}}$ 142 825 676 798 461 1
Total 15 348 727.6 347 230 1 050 063 3 573 1
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +10 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Its wall time warns above +5 % (±5 % is noise); the other thresholds apply per project.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head dd17078 · base dd17078 (merge-base) · workflow run

# Conflicts:
#	src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php
#	tests/TaintTest.php
@danog
danog merged commit 7baa8fc into vimeo:master Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant