-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Don't rely on Request::getPayload()
to populate the parsed body
#122
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable. Let's keep it simple.
Please mind fabbot, btw. 😉 |
f47a20b
to
ef03b6d
Compare
fabbot 🍏 |
Thank you Nicolas. |
Request::getPayload()
to populate the parsed body
Could someone please explain what was the problem with using PR says "creates issues like #121", but I can't open #121, it shows 404 for me. |
It appears, Laravel overrides this method with a bad return type. This has been fixed on their side, but since the logic behind
The issue tracker of this repository has been disabled because we're using the one over at https://github.com/symfony/symfony now. |
Thanks for explaining @derrabus. |
Sadly this PR breaks solutions in Laravel where it was possible to add input data with a middleware. This PR makes it so that it always uses the raw input (which we cannot mutate) over the input that was already defined by the request. Seems pretty silly to me not to use the existing input that was already parsed. |
Seems like no matter what we do, we "break Laravel". 🤷🏻♂️
The For instance, let's say you have a piece of middleware that injects the current user ID as property That being said, feel free to decorate the
And that's a perfect example for data that should never be injected into the input bags. Use attributes for that.
I'd like to ask you to keep a respectful tone on this issue tracker. |
Thanks for the speedy reply.
This is not an issue since it only happens for 1 specific request which is actually an unauthenticated request.
I'll take a look at that. Thanks for the suggestion.
I don't think saying that I think something is silly is disrespectful but let's not continue down that avenue. |
Note that one of the big security benefits of using a framework/third party libraries is that they will prevent many vulnerable spots without you having to think about them. It's good to hear you've thought this through, but I'm happy to know that teams that didn't think this through are not vulnerable either because of the behavior of the library :) Anyway, it's a bit unfortunate that code somewhere was broken due to a change in the library, but this is nearly unavoidable. Especially with libraries used in 2 different frameworks, where the "best practices" of one aren't necessarily advocated in great detail in the docs of the other. I'm glad we could point you to an alternative way of achieving the expected behavior. |
So to give a small update, upon searching further the issue was not with Laravel but with oauth2-server. Our solution, adding the My fix in the end, for anyone who may encounter this issue, was to add the This made sure the |
@rdgout I've actually also located this pull request because we're doing the exact same thing in the project (using Laravel Passport, and injecting Here is a fix I came up with. Before: $request->request->add([
'client_id' => $client->id,
'client_secret' => $client->secret,
]); After: $request->request->add([
'client_id' => $client->id,
'client_secret' => $client->secret,
]);
// Laravel Passport stopped recognizing injected `client_id` and `client_secret`
// because of this change: https://github.com/symfony/psr-http-message-bridge/releases/tag/v2.3.1
// This is a workaround for that issue.
$contentProperty = (new \ReflectionClass($request))->getProperty('content');
if (\is_string($contentProperty->getValue($request)) && json_decode($contentProperty->getValue($request)) !== null) {
$contentProperty->setValue($request, json_encode($request->getPayload()->all()));
} I won't pretend it's a beautiful solution, but it works for us. Feature tests are highly recommended for such stuff haha. |
Have you ended up with something like this in the middleware? $request->headers->add([
'Authorization' => 'Basic '.base64_encode($client->id.':'.$client->secret),
]); I think it's much more elegant than my initial solution. I haven't thought about passing client id and secret as basic auth credentials. |
That's exactly what I did. My initial solution was to use the request attributes and use the attributes in my custom grant, however this did not work when the token was renewed with the Also to note regarding your earlier comment, I caught this issue because we actually do have feature tests that failed with this update 😄 |
That's just not needed and creates issues like #121