Skip to content

Report a value after a literal URL start again once a builtin cuts the string - #15485

Merged
danog merged 12 commits into
vimeo:masterfrom
danog:url-start-cut-by-builtins
Dec 1, 2026
Merged

danog merged 12 commits into
vimeo:masterfrom
danog:url-start-cut-by-builtins

Conversation

@danog

@danog danog commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #15205: review and merge that one first.

Psalm misses a redirect or SSRF target chosen by a value after a literal URL start when a builtin cuts that start off.

Before

<?php
/** @psalm-taint-sink redirect $url */
function redirectTo(string $url): void {}

function after(string $url): string {
    return substr($url, 20);
}

$value = (string) $_GET["value"];
$url = "https://example.com/" . $value;
redirectTo(substr("/items/" . $value, 7)); // no issue
redirectTo(mb_substr($url, 20)); // no issue
redirectTo(explode("?", "/search?" . $value)[1]); // no issue
redirectTo(strtr($url, ["https://example.com/" => ""])); // no issue
preg_match("~\\?(.*)~", "https://example.com/?" . $value, $matches);
redirectTo($matches[1]); // no issue
redirectTo(after($url)); // no issue
foreach (new RegexIterator(new ArrayIterator([$url]), "~/~", RegexIterator::REPLACE) as $replaced) {
    redirectTo($replaced); // no issue
}
$file = new SplTempFileObject();
$file->fwrite($url);
redirectTo($file->fgets()); // no issue
$cut = substr(...);
redirectTo($cut($url, 20)); // no issue

After

redirectTo(substr("/items/" . $value, 7)); // TaintedRedirect
redirectTo(mb_substr($url, 20)); // TaintedRedirect
redirectTo(explode("?", "/search?" . $value)[1]); // TaintedRedirect
redirectTo(strtr($url, ["https://example.com/" => ""])); // TaintedRedirect
redirectTo($matches[1]); // TaintedRedirect
redirectTo(after($url)); // TaintedRedirect
    redirectTo($replaced); // TaintedRedirect
redirectTo($file->fgets()); // TaintedRedirect
redirectTo($cut($url, 20)); // TaintedRedirect

Unchanged, before and after

redirectTo($url); // no issue
redirectTo(strtolower($url)); // no issue
redirectTo(trim($url)); // no issue
redirectTo((new ArrayIterator([$url]))->current()); // no issue

A builtin, or a method or constructor of a builtin class, cuts the string unless it is listed as keeping its start (START_KEEPING_FLOWS, and keeps in InternalTaintObjectFlowMap.php).

@danog

danog commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot review

@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.

Stale Bugbot comment from a previous run.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged · Taint: +12 −17

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 805.0 $\color{gray}{\textsf{+0.3\%}}$ 114.4 $\color{gray}{\textsf{+1.0\%}}$ 25 775 $\color{red}{\textsf{+8}}$ $\color{gray}{\textsf{-0}}$ 52 296 814 $\color{orange}{\textsf{+8}}$ $\color{gray}{\textsf{-0}}$ 0
✅ symfony 3 622.8 $\color{gray}{\textsf{-0.4\%}}$ 229.6 $\color{gray}{\textsf{+2.2\%}}$ 52 302 $\color{red}{\textsf{+4}}$ $\color{green}{\textsf{-17}}$ 100 768 1 762 $\color{orange}{\textsf{+4}}$ $\color{orange}{\textsf{-17}}$ 0
✅ doctrine-orm 339.5 26.0 $\color{gray}{\textsf{-1.2\%}}$ 3 348 5 766 0 0
✅ psl 624.4 33.4 $\color{gray}{\textsf{+0.1\%}}$ 1 296 5 125 2 0
✅ phpunit 434.9 19.1 $\color{gray}{\textsf{-1.0\%}}$ 1 575 2 363 18 0
✅ php-parser 229.1 12.9 $\color{gray}{\textsf{+1.3\%}}$ 17 032 21 091 0 0
✅ tempest 917.3 $\color{gray}{\textsf{+0.1\%}}$ 33.9 $\color{gray}{\textsf{-0.4\%}}$ 5 494 11 032 271 0
✅ amphp-amp 48.7 1.7 30 57 0 0
✅ webmozarts-assert 282.9 5.4 $\color{gray}{\textsf{-0.7\%}}$ 576 2 740 0 0
✅ guzzle-promises 47.4 1.9 $\color{gray}{\textsf{+0.5\%}}$ 148 403 2 0
✅ monolog 140.5 $\color{gray}{\textsf{+0.2\%}}$ 6.6 937 2 483 31 0
✅ drupal 5 102.4 $\color{gray}{\textsf{+0.2\%}}$ 248.0 $\color{gray}{\textsf{+0.6\%}}$ 97 797 168 839 686 0
✅ wordpress 2 034.8 $\color{gray}{\textsf{+0.3\%}}$ 136.7 $\color{gray}{\textsf{-0.1\%}}$ 143 514 678 442 491 1
Total 15 629.7 $\color{gray}{\textsf{+0.1\%}}$ 869.6 $\color{gray}{\textsf{+0.8\%}}$ 349 824 $\color{red}{\textsf{+12}}$ $\color{green}{\textsf{-17}}$ 1 051 405 4 077 $\color{orange}{\textsf{+12}}$ $\color{orange}{\textsf{-17}}$ 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 side by side on the same runner; ±10 % is noise. Above +10 % warns, never fails. re-run: a second round was taken and the faster run of each side 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.
  • Profiling: when both sides support it, the measured runs use --debug-performance=PATH for the hot-files block, which adds the same small CPU and memory cost to both sides.
  • 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.
✅ laravel: issues +8 −0

Memory 1 799.1 → 1 805.0 MB (+0.3 %) · Wall 113.2 → 114.4 s (+1.0 %)

Taint 806 → 814 (+8 −0)

Issue type added removed
TaintedSSRF 8 0

Added (8)

✅ symfony: issues +4 −17

Memory 3 635.5 → 3 622.8 MB (−0.4 %) · Wall 224.5 → 229.6 s (+2.2 %)

Taint 1 775 → 1 762 (+4 −17)

Issue type added removed
TaintedCallable 4 9
TaintedFile 0 1
TaintedHtml 0 3
TaintedSSRF 0 1
TaintedTextWithQuotes 0 3

Added (4)

Removed (17)

head bb1e475 · base 0c62562 (merge-base) · workflow run

@danog

danog commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot review

@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.

Stale Bugbot comment from a previous run.

string $label,
CodeLocation $call_location,
): array {
$parent_nodes = $statements_analyzer->node_data->getType($expr)->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.

Null type dereference in callable flow

Medium Severity

In getNodesChangedByCallables, the code reads parent_nodes via getType($expr)->parent_nodes while the null-coalescing operator only applies to parent_nodes, not getType. When node_data->getType($expr) is null, taint analysis can throw before shadow restoration is wired for by-reference callable flows.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 33fe00d. 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.

False positive: ?? also covers a null to the left of -> (php -r '$x = null; var_dump($x->a ?? []);' gives array(0) {}, no warning), and Psalm accepts it.

@danog

danog commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot review

@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.

Stale Bugbot comment from a previous run.

@danog

danog commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot review

@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.

✅ Bugbot reviewed your changes and found no new issues!

1 issue from previous review remains unresolved.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit bb1e475. Configure here.

@danog
danog merged commit 51a9ffe into vimeo:master Dec 1, 2026
71 checks passed
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