Skip to content

Trust a value Validator::make() checked against a regex rule once the validator passes - #2358

Merged
danog merged 8 commits into
psalm:4.xfrom
danog:validator-make-taints
Nov 20, 2026
Merged

danog merged 8 commits into
psalm:4.xfrom
danog:validator-make-taints

Conversation

@danog

@danog danog commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

A value Validator::make() checked against a regex: rule is still reported once the validator doesn't fail.

Before

<?php
function showAgent(\Illuminate\Http\Request $request): void {
    $agent = trim($request->header('User-Agent', ''));
    $validator = \Illuminate\Support\Facades\Validator::make(
        ['agent' => $agent],
        ['agent' => ['required', 'regex:#^[a-zA-Z0-9 _.\-]+$#']],
    );
    if ($validator->fails()) {
        return;
    }
    echo $agent; // TaintedHtml
}

After

    echo $agent; // no issue

validator($data, $rules) too. A rule of another key, of a nested attribute or of a field the validator may exclude, or none restricting the characters, still leaves it tainted.

Needs Psalm 7.13, with vimeo/psalm#14176 (Codebase::addTaintValidation()), and #2370.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpsalm-plugin-laravel
Branchpr-2358
Testbedintel-v1
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
seconds (s)
(Result Δ%)
Upper Boundary
seconds (s)
(Limit %)
Peak MemoryBenchmark Result
megabytes (MB) x 1e3
(Result Δ%)
Upper Boundary
megabytes (MB) x 1e3
(Limit %)
monica📈 view plot
🚷 view threshold
44.69 s
(+2.66%)Baseline: 43.53 s
46.05 s
(97.04%)
📈 view plot
🚷 view threshold
1.17 MB x 1e3
(+0.06%)Baseline: 1.17 MB x 1e3
1.23 MB x 1e3
(95.30%)
🐰 View full continuous benchmarking report in Bencher

…acade and validator() too

Facade calls are @method pseudo-methods, for which Psalm dispatches no
AfterMethodCallAnalysis. Skip keys a spread or an unknown key can override, the
last item of a key wins, and rules of nested or wildcard attributes and of
fields the validator may exclude don't validate the value.
@alies-dev alies-dev changed the title Trust a value Validator::make() checked against a regex rule once the validator passes Trust a value Validator::make() checked against a regex rule once the validator passes Nov 19, 2026
@danog
danog marked this pull request as ready for review November 20, 2026 22:58
@danog
danog requested a review from alies-dev as a code owner November 20, 2026 22:58
@danog
danog merged commit 9b6f20c into psalm:4.x Nov 20, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant