Skip to content

[13.x] Ensure _error_bag input is a string in Handler::invalid() - #62147

Merged
taylorotwell merged 2 commits into
laravel:13.xfrom
manavu:fix-invalid-error-bag-type
Oct 22, 2026
Merged

taylorotwell merged 2 commits into
laravel:13.xfrom
manavu:fix-invalid-error-bag-type

Conversation

@manavu

@manavu manavu commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Description

In Illuminate\Foundation\Exceptions\Handler::invalid(), the request's _error_bag input is passed directly to RedirectResponse::withErrors() as the error bag key without verifying that it is a string:

->withErrors($exception->errors(), $request->input('_error_bag', $exception->errorBag));

If a non-JSON request fails validation and includes an array value for _error_bag (e.g., POST /form with _error_bag[]=x), $request->input('_error_bag', $exception->errorBag) returns an array (['x']). When RedirectResponse::withErrors() passes this key to ViewErrorBag::put($key, $value), PHP throws an unhandled TypeError (Cannot access offset of type array on array at $this->bags[$key] = $bag;), resulting in a 500 Internal Server Error and triggering exception reporting instead of redirecting back with validation errors.

Fix

Ensure $request->input('_error_bag') is a string before using it as the error bag name, falling back to $exception->errorBag otherwise (matching the is_string() guards used for request input in VerifyCsrfToken::tokensMatch() and Cursor::fromEncoded()).

@taylorotwell
taylorotwell merged commit f1c1066 into laravel:13.x Oct 22, 2026
62 checks passed
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 26, 2026
Apply laravel/framework#62147 (f1c10664f4). Use the submitted error bag only when it is a string; otherwise retain the exception default. Preserve sessionless response handling. Port both upstream cases using an initialized redirect response for Hypervel response finalization, and align the existing input mock. The regression reproduces the array TypeError without the fix. Handler tests, formatting and full analysis pass.
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.

2 participants