Skip to content

Add the redirect taint kind, and connect session stores to their reads - #14158

Merged
danog merged 10 commits into
vimeo:masterfrom
danog:redirect-session-taint-kinds
Nov 20, 2026
Merged

danog merged 10 commits into
vimeo:masterfrom
danog:redirect-session-taint-kinds

Conversation

@danog

@danog danog commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Open redirects

Psalm reports a user-chosen Location header as a header injection, even when the server of the URL is fixed.

Before

<?php
$next = (string) $_GET["next"];
header("Location: " . $next); // TaintedHeader
header("Location: https://example.com/" . $next); // TaintedHeader

After

header("Location: " . $next); // TaintedRedirect
header("Location: https://example.com/" . $next); // TaintedUrlComponent

Session

Psalm doesn't connect what is stored in $_SESSION to what reads it back.

Before

<?php
function remember(): void {
    $_SESSION["user"] = (string) $_GET["user"];
}

function show(): void {
    echo (string) ($_SESSION["user"] ?? ""); // no issue
}

After

    echo (string) ($_SESSION["user"] ?? ""); // TaintedHtml

@psalm-taint-sink redirect lets plugins mark the redirects of frameworks.

@danog danog added the release:feature The PR will be included in 'Features' section of the release notes label Nov 18, 2026
@danog

danog commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Plugin API changelog: psalm/psalm-plugin-api#10

@danog
danog force-pushed the redirect-session-taint-kinds branch from f9a7e29 to c813fa0 Compare November 18, 2026 10:11

@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 c813fa0. Configure here.

// what is stored in the session is trusted by the requests that read it back
if ($expr->var instanceof Variable
&& $expr->var->name === '_SESSION'
&& ($taint_flow_graph = $statements_analyzer->taint_flow_graph)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Session taint ignores suppression

Medium Severity

New $_SESSION assignment logic wires sinks through taint_flow_graph instead of getTaintFlowGraphWithSuppressed(). When TaintedInput is suppressed, sibling GLOBALS taint is skipped but session sinks and paths are still recorded, so TaintedSession can appear despite the intended suppression.

Fix in Cursor Fix in Web

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

Fixed: the session sink now uses getTaintFlowGraphWithSuppressed(), with a test where a tainted argument reaches $_SESSION inside a function suppressing TaintedInput.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged · Taint: +1 −1

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 765 98.0 $\color{gray}{\textsf{-0.5\%}}$ 26 015 53 212 673
✅ symfony 3 605 260.8 $\color{gray}{\textsf{-0.5\%}}$ 50 699 $\color{red}{\textsf{+1}}$ $\color{green}{\textsf{-1}}$ 98 716 1 491 $\color{orange}{\textsf{+1}}$ $\color{orange}{\textsf{-1}}$
✅ doctrine-orm 393 21.9 $\color{gray}{\textsf{-1.5\%}}$ 3 480 6 161 0
✅ psl 632 26.4 $\color{gray}{\textsf{-0.8\%}}$ 1 300 5 456 1
✅ phpunit 471 12.1 $\color{gray}{\textsf{+1.6\%}}$ 1 744 3 459 18
✅ php-parser 236 8.6 $\color{gray}{\textsf{+2.5\%}}$ 17 133 21 035 0
✅ tempest 903 23.4 $\color{gray}{\textsf{+2.0\%}}$ 5 042 10 514 242
✅ amphp-amp 61 2.2 $\color{gray}{\textsf{-0.9\%}}$ 29 49 0
✅ webmozarts-assert 286 5.4 $\color{gray}{\textsf{-1.6\%}}$ 577 2 722 0
✅ guzzle-promises 56 $\color{gray}{\textsf{+0.1\%}}$ 2.2 158 435 2
✅ monolog 153 6.3 $\color{gray}{\textsf{-0.2\%}}$ 903 2 403 10
✅ drupal 4 850 186.5 $\color{gray}{\textsf{-1.2\%}}$ 97 578 169 327 568
Total 13 413 653.8 $\color{gray}{\textsf{-0.6\%}}$ 204 658 $\color{red}{\textsf{+1}}$ $\color{green}{\textsf{-1}}$ 373 489 3 005 $\color{orange}{\textsf{+1}}$ $\color{orange}{\textsf{-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 +20 % 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. Thresholds apply per project, not to the total.
  • 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.
✅ symfony: issues +1 −1

Memory 3 605 → 3 605 MB (<0.1 %) · Wall 262.1 → 260.8 s (−0.5 %)

Taint 1 491 → 1 491 (+1 −1)

Issue type added removed
TaintedHeader 0 1
TaintedRedirect 1 0

Added (1)

  • src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php:105 TaintedRedirect (error): Detected tainted redirect target

Removed (1)

  • src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php:105 TaintedHeader (error): Detected tainted header

composer.json changed in this PR, so head dependencies were re-resolved; memory and time deltas are informational.

head 6346a0d · base 805b192 (merge-base) · workflow run

A Location header given to header() is a redirect sink (TaintedRedirect,
CWE-601) rather than a header one, unless what follows Location: fixes the
server. What is stored in $_SESSION is a session sink (TaintedSession,
CWE-501).
@danog
danog force-pushed the redirect-session-taint-kinds branch from bb824c0 to 2b1b56b Compare November 19, 2026 11:11
…eader

A Location header sinks url_component and url_path besides redirect, and a start fixing the server removes redirect as it removes ssrf, so a value after it is reported as TaintedUrlComponent or TaintedUrlPath instead of nothing. A path from the root followed by a query or fragment also removes url_path.
# Conflicts:
#	tests/TaintTest.php
…reporting every store

The session taint kind and TaintedSession are removed: a value stored under a key flows into the reads of that key, wherever they are, and is reported by the sink that consumes it, which decides the escaping it needs.
@danog danog changed the title Add the redirect and session taint kinds Add the redirect taint kind, and connect session stores to their reads Nov 20, 2026
danog added a commit to psalm/psalm-plugin-api that referenced this pull request Nov 20, 2026
…es, MatchesPattern (#10)

* 0.4.8: CodeIssue::CWE_IDS and the redirect and session taint kinds (vimeo/psalm#14156, vimeo/psalm#14158)

* Add the new security issues and MatchesPattern
danog added a commit to danog/psalm that referenced this pull request Nov 20, 2026
The commits of this branch, applied again on top of redirect-session-taint-kinds, which replaced the session sink by a store of the session and reports URL syntax after the fixed server of a Location header.
danog added a commit to danog/psalm that referenced this pull request Nov 20, 2026
The commits of this branch, applied again on top of url-host-allowlist and redirect-session-taint-kinds. A restricting pattern no longer validates a value for the session: what is read back from it is checked against what reads it.
danog added a commit to danog/psalm-plugin-symfony that referenced this pull request Nov 20, 2026
…yntax a redirect to a fixed server takes

Under the session store of vimeo/psalm#14158, SessionInterface::set() stores into the attributes that get(), all() and remove() read back, so a stored value is reported where it is used, not where it is stored. Redirect sinks also take url_component and url_path.
danog added a commit to danog/psalm-plugin-laravel that referenced this pull request Nov 20, 2026
…he session to its reads

Session reads are already sources, so what is stored in the session is reported where it is read and used: the session sinks are dropped, as vimeo/psalm#14158 dropped the session taint. Redirect sinks also take url_component and url_path.
danog added a commit to danog/psalm-plugin-laravel that referenced this pull request Nov 20, 2026
Under vimeo/psalm#14158 a value stored in the session is reported where it is read back, not where it is stored.
@danog
danog merged commit 0995fb4 into vimeo:master Nov 20, 2026
70 checks passed
danog added a commit to psalm/psalm-plugin-symfony that referenced this pull request Nov 20, 2026
…t the secure flag

RedirectResponse and AbstractController::redirect() take redirect sinks
(TaintedRedirect), the values SessionInterface::set() stores session sinks
(TaintedSession), and Cookie::create(), new Cookie() and withSecure() with
secure: false are reported as InsecureCookie. Needs the Psalm release with
vimeo/psalm#14158 and #14160.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:feature The PR will be included in 'Features' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant