Skip to content

Releases

v4.23.2

Choose a tag to compare

@alies-dev alies-dev released this 22 Nov 13:37
0b50504

Supports Psalm 7.14 to 7.16 and keeps Psalm 7.16's star projections (Relation<*, *>) through relation calls.

Fixes

  • Keep * type arguments when a relation call is forwarded to its builder. With Psalm 7.16 a HasMany<*, User> stays HasMany<*, User> through where(), scopes and other builder methods, instead of becoming HasMany<Model, User> and passing where a concrete relation is required (#2378)
 /** @param HasMany<*, User> $posts */
 $active = $posts->where('active', true);
-// HasMany<Model, User>
+// HasMany<*, User>
  • Support Psalm 7.14 and 7.15: stubs follow their changes, and Enumerable::when()/unless() callbacks accept the value argument. Requires vimeo/psalm ^7.14.0 (#2377)

Full Changelog: v4.23.1...v4.23.2

v4.23.1

Choose a tag to compare

@danog danog released this 21 Nov 00:33
3349f83

Taint now flows through Stringable chains.

Fixes

  • Keep the taint of a Stringable through the methods whose result holds its string, such as trim(), upper(), after(), limit(), append() and toString(). Each Stringable keeps its own taint, so a tainted call doesn't taint the same method on other strings. hash(), encrypt(), toBase64() and numbers() drop the taint, and slug() and stripTags() remove HTML (#2374)
 $name = $request->str('name');
 echo $name->trim()->upper();
-// no issue
+// TaintedHtml
 echo Str::of('safe')->upper();
 // no issue

Full Changelog: v4.23.0...v4.23.1

v4.23.0

Choose a tag to compare

@danog danog released this 20 Nov 23:56
974ec42

This release targets Psalm 7.13. It reports open redirects and cookies without the secure flag, reads the session and raw database queries back from what the application stored, and trusts values Validator::make() checked against a regex.

Requirements

  • Require vimeo/psalm ^7.13.1 (#2373). Projects on Psalm 7.12 keep v4.22.7.

Features

  • Report a user-controlled redirect target as TaintedRedirect, and the URL syntax injected after a fixed server as TaintedUrlComponent/TaintedUrlPath, on redirect(), Redirector, ResponseFactory and its contract (#2357)
redirect('https://example.com/' . (string) $request->input('page'));
// TaintedUrlComponent
  • Report a cookie made with the secure flag explicitly off as InsecureCookie (#2357)
response()->json(['ok' => 1])->cookie('session', $token, 0, '/', null, false, true, false, 'Strict');
// InsecureCookie
  • Track what raw DB/Connection queries store in each column, and report it where a query reads that column back (#2359)
DB::insert('INSERT INTO comments (author, body) VALUES (?, ?)', ['admin', $request->input('body')]);

$comment = DB::selectOne('SELECT author, body FROM comments');
echo (string) $comment->body;
// TaintedHtml
echo (string) $comment->author;
// no issue
  • Trust a value that Validator::make() or validator() checked against a regex rule once the validator passes (#2358)
 $validator = Validator::make(['agent' => $agent], ['agent' => ['required', 'regex:#^[a-zA-Z0-9 _.\-]+$#']]);
 if ($validator->fails()) {
     return;
 }
 echo $agent;
-// TaintedHtml
+// no issue

Fixes

  • Read a session value back from what the application stored under its key instead of treating every session read as user input (#2357). getOldInput() and previousUrl() stay user input.
 $session->flash('status', 'saved');
 $session->put('name', $request->input('name'));

 echo (string) $session->get('status');
-// TaintedHtml
+// no issue
 echo (string) $session->get('name');
 // TaintedHtml
  • Keep the values of a where([...]) array, which Laravel binds as parameters, free of TaintedSql on Psalm 7.13 (#2373)

Full Changelog: v4.22.7...v4.23.0

v4.22.7

Choose a tag to compare

@orklah orklah released this 20 Nov 21:20
c815809

Compatibility with the upcoming Psalm 7 change to template argument keys.

Fixes

  • Sanctum's default TToken binding and the factory TModel binding keep working once Psalm keys template_type_extends_count and template_extended_offsets by the lowercase parent name (vimeo/psalm#14397); releases of Psalm before that change are still supported (#2372)

Full Changelog: v4.22.6...v4.22.7

v4.22.6

Choose a tag to compare

@alies-dev alies-dev released this 20 Nov 20:15
7613608

Console commands declared with the Laravel 13 #[Signature] attribute.

Features

  • Read the command signature from the Laravel 13 #[Signature] attribute, so argument()/option() narrowing, hasArgument()/hasOption() and the InvalidConsoleArgumentName/InvalidConsoleOptionName checks work for commands migrated from protected $signature (e.g. by Rector's Laravel set). As in Laravel, the attribute overrides a $signature property and is read from the concrete class only (#2371)
 #[Signature('app:demo {name} {--tag=*}')]
 final class Demo extends Command { /* ... */ }

 $this->argument('name');
-// array<array-key, mixed>|null|scalar
+// string
 foreach ($this->option('tag') as $tag) {}
-// PossiblyNullIterator, PossiblyInvalidIterator
+// array<int, string>

Full Changelog: v4.22.5...v4.22.6

v4.22.5

Choose a tag to compare

@alies-dev alies-dev released this 20 Nov 13:23
f1f5eb7

Requires vimeo/psalm ^7.12.0, and a nullable Request::route().

Fixes

  • Type Request::route() without arguments as Route|null: Laravel returns null when no route matched (error pages, console, queued code). Guards on it no longer report redundant checks, and an unguarded call reports PossiblyNullReference (#2367)
 $name = request()->route()?->getName();
-// RedundantConditionGivenDocblockType: Docblock-defined type Illuminate\Routing\Route for $__tmp_nullsafe__N is never null
+// string|null
  • Blade: stop reporting PossiblyUndefinedGlobalVariable on $__sessionPrevious/$__contextPrevious in templates with consecutive @session or @context blocks on Psalm 7.12 (#2369)

Full Changelog: v4.22.4...v4.22.5

v4.22.4

Choose a tag to compare

@danog danog released this 19 Nov 11:47
99712db

Psalm 7.11 and psalm/psalm-plugin-api 0.5.

Requirements

  • Require vimeo/psalm ^7.11.0. Upgrade Psalm together with the plugin: composer u vimeo/psalm -W (#2366)
  • Allow psalm/psalm-plugin-api ^0.5 (#2365)

Internal changes

  • The Blade file hashes, shadow files and cache directory use xxh3 instead of sha1()/md5(), so the Blade caches are rebuilt once after the upgrade (#2366)

Full Changelog: v4.22.3...v4.22.4

v4.22.3

Choose a tag to compare

@alies-dev alies-dev released this 18 Nov 01:00
0ff1258

Arrow function callbacks in migrations, on Psalm 7.10.

Requirements

  • Require vimeo/psalm ^7.10.0. Upgrade Psalm together with the plugin: composer u vimeo/psalm -W (#2355)

Fixes

  • Read migration columns declared in arrow function callbacks of Schema::create(), Schema::table() and Blueprint::after() (#2350)
 Schema::create('tags', fn (Blueprint $table) => $table->string('name'));

 $name = Tag::first()->name;
-// UndefinedMagicPropertyFetch: the `name` column was never read
+// string

Full Changelog: v4.22.2...v4.22.3

v4.22.2

Choose a tag to compare

@alies-dev alies-dev released this 18 Nov 00:17
bbaf615

Type precision for array helpers, higher-order collection grouping and the remember_token column.

Fixes

  • Type Arr::map() and Arr::mapWithKeys() results from the callback instead of array<array-key, mixed> (#2349)
 /** @var array<string, int> $prices */
 $cents = Arr::map($prices, fn (int $price, string $sku): float => $price / 100);
-// array<array-key, mixed>, then MixedReturnTypeCoercion / MixedArgumentTypeCoercion downstream
+// array<string, float>
  • Type the outer key of higher-order groupBy and keyBy ($users->groupBy->active) as int when the grouped value is a bool, int or int-backed enum, like the groupBy('active') form already does (#2344)
 $byActive = $users->groupBy->active; // active: bool
-// Collection<array-key, Collection<int, User>>
+// Collection<int, Collection<int, User>>
  • Type the remember_token column from $table->rememberToken() as string|null: Laravel always creates it nullable (#2343)
 $token = $user->remember_token;
-// string
+// string|null

Full Changelog: v4.22.1...v4.22.2

v4.22.1

Choose a tag to compare

@alies-dev alies-dev released this 17 Nov 15:23
2505648

Psalm 7.9 compatibility. Plugin v4.22.0 can crash with a TypeError on Psalm 7.9 when analyzing a nullsafe property fetch through a higher-order collection proxy ($c->map?->name), so this release requires Psalm 7.9.

Requirements

  • Require vimeo/psalm ^7.9.0 (was ^7.7.0). Upgrade Psalm together with the plugin: composer update vimeo/psalm psalm/plugin-laravel (#2333)

Features

  • Type the closure parameter of eager-load constraints in with(), withOnly(), load() and loadMissing() (#1955)
 Customer::query()->with(['vehicles' => fn ($query) => $query->where('year', '>', 2020)]);
-// MissingClosureParamType, MixedMethodCall: $query was untyped
+// $query is typed as the constrained relation

Fixes

  • 🛡️ Propagate closure return taint through value(), rescue(), retry(), once(), with() and DB::transaction() (#2280)
 echo DB::transaction(fn () => (string) $request->input('name'));
-// no issue
+// TaintedHtml, TaintedTextWithQuotes
  • Type a custom caster's get() by its native return type when it has no docblock (#2294)
 // MoneyCast::get(...): Money, no docblock
 return $payment->amount->format();
-// MixedReturnStatement, PossiblyNullReference, MixedMethodCall
+// no issue
  • Report a wrong @return on template-bound groupBy() and keyBy() receivers (@template C of Collection<...>) as InvalidReturnStatement instead of accepting it (#2332)
  • Stop narrowing getKey() to int for the non-final Illuminate\Foundation\Auth\User receiver, which can use string keys (#2293)
 $key = $user->getKey();
 if (\is_string($key)) { ... }
-// TypeDoesNotContainType: Type int for $key is never string
+// no issue
  • Type __() and trans() calls with a mixed key as string (#2289)
 return '"' . __($row['message']) . '"';
-// PossiblyNullOperand, PossiblyInvalidOperand
+// only MixedArgument for the mixed key remains
  • Stop flagging custom Eloquent builder methods returning self as PossiblyUnusedReturnValue (#1449)
  • Narrow non-empty-string to non-falsy-string in Collection::filter() without a callback, since it removes "0" (#2335)

Full Changelog: v4.22.0...v4.22.1