Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request::getPayload(): Return value must be of type InputBag, ParameterBag returned #47834

Closed
Gummibeer opened this issue Jul 25, 2023 · 24 comments · Fixed by #47838
Closed

Request::getPayload(): Return value must be of type InputBag, ParameterBag returned #47834

Gummibeer opened this issue Jul 25, 2023 · 24 comments · Fixed by #47838

Comments

@Gummibeer
Copy link
Contributor

Laravel Version

10.16.0

PHP Version

8.1.19

Database Driver & Version

No response

Description

Symfony\Component\HttpFoundation\Request::getPayload(): Return value must be of type Symfony\Component\HttpFoundation\InputBag, Symfony\Component\HttpFoundation\ParameterBag returned

This error now occurs as soon as Laravel tries to handle any JSON request. This seems to be based on the new symfony/psr-http-message-bridge v2.3.0 release.

But originally it seems like a far longer problem just never detected. With Symfony 6 types were added - so also to the Symfony\Component\HttpFoundation\Request::getPayload() method. But for Laravel 9 the payload of JSON requests was filled into a ParameterBag. All places not checking for explicit type won't have any problem as these classes have nearly identical APIs.

Steps To Reproduce

Send a JSON request to the server with "symfony/psr-http-message-bridge": "2.3.0" installed.

@Gummibeer
Copy link
Contributor Author

PS: it could be that the sentry/sentry-laravel is needed as well as that resolves the PSR request.

@deonthomasgy
Copy link

this change break laravel, symfony/http-foundation@76002b1

@yusufalper
Copy link

same error here, after 10.16 update.

@deonthomasgy
Copy link

quick workaround. add to composer.json
under require:
"symfony/http-foundation": "6.2",

@looksystems
Copy link

same error, again, after 10.16 update.

@Ben-Gallienne
Copy link

Can confirm this is happening for us too.

@LeVadim
Copy link

LeVadim commented Jul 25, 2023

Same error, confirming that downgrading had helped
"symfony/http-foundation": "6.2",
Thank you

@wilsenhc
Copy link
Contributor

Same error here, the downgrade to "symfony/http-foundation": "6.2" fixed it

@ericksonlargura
Copy link

Same error, fixed with "symfony/http-foundation": "6.2"

@relaypilot
Copy link

relaypilot commented Jul 25, 2023

Temporary fix for me was to require "symfony/http-foundation": "^6.2.0",

But also downgrading the recent Laravel updates:

  - Downgrade laravel/framework (v10.16.0 => v10.15.0)
  - Downgrade laravel/horizon (v5.19.0 => v5.18.0)
  - Downgrade laravel/jetstream (v3.2.5 => v3.2.4)
  - Downgrade laravel/serializable-closure (v1.3.1 => v1.3.0)
  - Downgrade symfony/psr-http-message-bridge (v2.3.0 => v2.2.0)

I also had to delete the vendor folder on prod before deploying the new composer.lock

@timacdonald
Copy link
Member

timacdonald commented Jul 25, 2023

Could someone please provide the minimal steps to reproduce this?

I've created a fresh install with breeze, installed symfony/psr-http-message-bridge but been unable to reproduce this error.

Sending a request with Content-type: application/json and a JSON body and then calling request()->all() to have the JSON parsed.

Also, on first glace this looks like a Symfony issue rather than a Laravel issue?

@prattcmp
Copy link

prattcmp commented Jul 26, 2023

I don't have minimal steps, but here is a full stack trace:

Symfony\Component\HttpFoundation\Request::getPayload(): Return value must be of type Symfony\Component\HttpFoundation\InputBag, Symfony\Component\HttpFoundation\ParameterBag returned {"exception":"[object] (TypeError(code: 0): Symfony\\Component\\HttpFoundation\\Request::getPayload(): Return value must be of type Symfony\\Component\\HttpFoundation\\InputBag, Symfony\\Component\\HttpFoundation\\ParameterBag returned at /var/www/html/vendor/symfony/http-foundation/Request.php:1517)
[stacktrace]
#0 /var/www/html/vendor/symfony/psr-http-message-bridge/Factory/PsrHttpFactory.php(84): Symfony\\Component\\HttpFoundation\\Request->getPayload()
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php(141): Symfony\\Bridge\\PsrHttpMessage\\Factory\\PsrHttpFactory->createRequest(Object(Illuminate\\Http\\Request))
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(908): Illuminate\\Routing\\RoutingServiceProvider->Illuminate\\Routing\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\\Container\\Container->build(Object(Closure))
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(933): Illuminate\\Container\\Container->resolve('Psr\\\\Http\\\\Messag...', Array, true)
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\\Foundation\\Application->resolve('Psr\\\\Http\\\\Messag...', Array)
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(918): Illuminate\\Container\\Container->make('Psr\\\\Http\\\\Messag...', Array)
#7 /var/www/html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(36): Illuminate\\Foundation\\Application->make('Psr\\\\Http\\\\Messag...')
#8 /var/www/html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(23): Sentry\\Laravel\\Http\\SetRequestMiddleware->resolvePsrRequest(Object(Illuminate\\Foundation\\Application))
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Sentry\\Laravel\\Http\\SetRequestMiddleware->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Http\\Middleware\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#24 /var/www/html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Sentry\\Laravel\\Tracing\\Middleware->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#29 /var/www/html/vendor/laravel/octane/src/ApplicationGateway.php(37): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#30 /var/www/html/vendor/laravel/octane/src/Worker.php(92): Laravel\\Octane\\ApplicationGateway->handle(Object(Illuminate\\Http\\Request))
#31 /var/www/html/vendor/laravel/octane/bin/swoole-server(124): Laravel\\Octane\\Worker->handle(Object(Illuminate\\Http\\Request), Object(Laravel\\Octane\\RequestContext))
#32 [internal function]: {closure}(Object(Swoole\\Http\\Request), Object(Swoole\\Http\\Response))
#33 /var/www/html/vendor/laravel/octane/bin/swoole-server(170): Swoole\\Server->start()
#34 {main}
"} 

Key points:

  1. I'm using Octane (Swoole)
  2. Error does not occur with every request. For me, it only seems to be occurring with POST requests
  3. The only 3rd party middleware being resolved is sentry/sentry-laravel.

@prattcmp
Copy link

I can't repro when I use artisan serve. Is it related to Octane/Swoole?

@jkuster
Copy link

jkuster commented Jul 26, 2023

Could someone please provide the minimal steps to reproduce this?

I've created a fresh install with breeze, installed symfony/psr-http-message-bridge but been unable to reproduce this error.

Sending a request with Content-type: application/json and a JSON body and then calling request()->all() to have the JSON parsed.

Also, on first glace this looks like a Symfony issue rather than a Laravel issue?

I don't have minimal steps, but I noticed it on a POST request trying to authenticate with a YubiKey using laravel-webauthn. Also on Laravel 9.

@cosmastech
Copy link
Contributor

Also, on first glace this looks like a Symfony issue rather than a Laravel issue?

I looked at this earlier to submit a PR, and wasn't sure how this would be resolved. It seemed to me (with minimal digging) that Symfony should return the parent class from getPayload() like you have suggested.

The other thought I had was to override the getPayload() method in Illuminate's Request class.

@timacdonald
Copy link
Member

I've managed to replicate. Still investigating.

@timacdonald
Copy link
Member

I've found the issue. Putting together a PR to fix the issue.

@wilsenhc
Copy link
Contributor

Thanks for the hard work @timacdonald 👏🏼

@timacdonald
Copy link
Member

See: #47838

Would love someone to make this small change locally and confirm the fix gets you out of trouble.

@jkuster
Copy link

jkuster commented Jul 26, 2023

I made the change on 9.x and it fixed my issue with webauthn.

@timacdonald
Copy link
Member

Thank you, @jkuster

@vaites
Copy link
Contributor

vaites commented Jul 26, 2023

@timacdonald, @taylorotwell this bug will be fixed for 9.x branch?

@timacdonald
Copy link
Member

See: #47840

@emielmolenaar
Copy link

Thanks for the quick fixes! 👍🏻

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 a pull request may close this issue.