Skip to content

Treat what filter_input(), getallheaders() and other request functions return as user input - #15488

Open
danog wants to merge 3 commits into
vimeo:masterfrom
danog:request-input-sources
Open

danog wants to merge 3 commits into
vimeo:masterfrom
danog:request-input-sources

Conversation

@danog

@danog danog commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Psalm doesn't treat what filter_input(), filter_input_array(), getallheaders(), apache_request_headers(), request_parse_body() and readline() return as user input.

Request functions

Before

<?php
shell_exec(getallheaders()["X-A"]);                                     // no issue
shell_exec((string) filter_input(INPUT_GET, "a"));                      // no issue
shell_exec((string) filter_input(INPUT_GET, "a", FILTER_VALIDATE_INT)); // no issue
shell_exec((string) filter_input(INPUT_SERVER, "HTTP_X_A"));            // no issue
shell_exec((string) filter_input(INPUT_SERVER, "DOCUMENT_ROOT"));       // no issue

After

shell_exec(getallheaders()["X-A"]);                                     // TaintedShell
shell_exec((string) filter_input(INPUT_GET, "a"));                      // TaintedShell
shell_exec((string) filter_input(INPUT_SERVER, "HTTP_X_A"));            // TaintedShell

Defaults of filters

Psalm treats the default value filter_var() gives instead of an invalid one as if it was filtered.

Before

<?php
$given = (string) $_GET["a"];
$default = (string) $_GET["b"];
$options = ["options" => ["default" => $default]];
shell_exec((string) filter_var($given, FILTER_VALIDATE_INT, $options)); // no issue

After

shell_exec((string) filter_var($given, FILTER_VALIDATE_INT, $options)); // TaintedShell

Sanitizing filters

Psalm reports what filter_var() encodes.

Before

<?php
$given = (string) $_GET["a"];
echo (string) filter_var($given, FILTER_SANITIZE_FULL_SPECIAL_CHARS); // TaintedHtml, TaintedTextWithQuotes
echo (string) filter_var($given, FILTER_VALIDATE_IP);                 // TaintedHtml, TaintedTextWithQuotes

After

echo (string) filter_var($given, FILTER_SANITIZE_FULL_SPECIAL_CHARS); // no issue
echo (string) filter_var($given, FILTER_VALIDATE_IP);                 // no issue

Unpacked arguments

Psalm infers never for filter_input() with unpacked arguments, and doesn't analyze the code after it.

Before

<?php
$input = filter_input(...[INPUT_GET, "a", FILTER_VALIDATE_INT]); // never
$var = filter_var(...["1", FILTER_VALIDATE_INT]);                // false

After

$input = filter_input(...[INPUT_GET, "a", FILTER_VALIDATE_INT]); // false|mixed|null
$var = filter_var(...["1", FILTER_VALIDATE_INT]);                // mixed

@danog danog added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 30, 2026
@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.

$input_taints & ~self::getRemovedTaints($codebase, $args['options'] ?? null, null),
$context,
$type,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Server key skip missing array path

Medium Severity

When filter_input_array() is called with INPUT_SERVER and no per-field definition map, the branch that treats the whole return as request taint never skips server-controlled keys. That diverges from single-key filter_input() and from the per-key array loop, which both honor ServerVariableTaints::isUserControlled() for entries like DOCUMENT_ROOT.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0fe6361. Configure here.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 796.4 73.4 $\color{gray}{\textsf{+0.5\%}}$ 25 828 52 365 833 0
✅ symfony 3 596.7 197.9 $\color{gray}{\textsf{+0.3\%}}$ 52 447 100 811 1 891 0
✅ doctrine-orm 339.3 23.9 $\color{gray}{\textsf{+1.1\%}}$ 3 352 5 800 0 0
✅ psl 624.3 29.8 $\color{gray}{\textsf{+0.5\%}}$ 1 296 5 125 2 0
✅ phpunit 433.6 13.4 $\color{gray}{\textsf{+1.1\%}}$ 1 575 2 363 18 0
✅ php-parser 228.7 8.9 $\color{gray}{\textsf{+0.6\%}}$ 17 032 21 091 0 0
✅ tempest 914.3 24.9 $\color{gray}{\textsf{+1.0\%}}$ 5 511 11 032 288 0
✅ amphp-amp 48.8 $\color{gray}{\textsf{+0.1\%}}$ 1.4 $\color{gray}{\textsf{+0.7\%}}$ 30 57 0 0
✅ webmozarts-assert 282.5 4.2 $\color{gray}{\textsf{+1.0\%}}$ 576 2 740 0 0
✅ guzzle-promises 47.4 $\color{gray}{\textsf{+0.3\%}}$ 1.4 148 403 2 0
✅ monolog 140.2 5.0 $\color{gray}{\textsf{-2.1\%}}$ 937 2 483 31 0
✅ drupal 5 087.1 214.5 $\color{gray}{\textsf{+0.1\%}}$ 97 865 168 986 684 0
✅ wordpress 2 031.3 168.4 $\color{gray}{\textsf{-1.8\%}}$ 143 503 678 445 479 1
Total 15 570.5 767.2 $\color{gray}{\textsf{-0.1\%}}$ 350 100 1 051 701 4 228 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.

head 33bdae0 · base ab8c4e5 (merge-base) · workflow run

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

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

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

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 33bdae0. Configure here.


return $arrays === 0
? self::MAX_KEY_DEPTH
: max(1, min(self::MAX_KEY_DEPTH, intdiv(self::MAX_FLOWS - count($filters), $arrays)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Skipped server filters shrink depth

Medium Severity

getKeyDepth() uses count($filters) against MAX_FLOWS, but taintInputArray() skips non-user-controlled INPUT_SERVER entries without creating a per-field source. Those skipped names still lower the computed key depth, so nested array keys can lose taint under large INPUT_SERVER filter maps.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 33bdae0. Configure here.

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