-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[9.x] Manually populate POST request body with JSON data only when required #37921
Conversation
This fixes a 6 year old bug introduced in #7026 where GET requests would have GET data populated in the POST body property leading to issues around Request::post() and $request->getParsedBody() returning GET values when called on GET requests. This is a resubmit of #17087 & #36708, and fixes #22805. Credit to @dan-har for the initial solution and @mixlion for updating it for >=6.x. The original PR was meant to support POST requests where their Content-type was set to application/json (instead of the typical application/x-www-form-urlencoded), but it introduced a subtle and dangerous bug because while $request->getInputSource() does return the JSON data for JSON requests, it also returns the GET data for GET requests. This commit solves the underlying issue without breaking compatibility with the original functionality.
Okay, I just went through the code and this indeed seems okay to me. There's one small concern though: Both @LukeTowers I'm afraid we cannot make this change on 6.x as I can definitely see apps break over this while expecting the current behavior. But it seems reasonable to do this on the next major release. Would be cool if you could add a test as well. |
@driesvints I'm not sure I can see how existing apps could break over this change in a negative way, could you provide me an example of what came to your mind? The whole reason I want this backported is because it "breaks" apps in that it fixes potential security issues (I don't think a single developer out there expects @driesvints Tests have been added |
@LukeTowers okay, I guess that the type thing is fine then. So, the reason I think this is a breaking change is because before this PR you could do the following for a GET request: $request->request->all(); And that would give back the params from the query string. I definitely agree with you that this needs fixing but there might be people relying on the current behavior. |
While a bit less obvious that it's a bad idea to use I am however seeing lots of usage of how it's intended to be used, for POST parameters; along with a few that could be impacted by not realizing that it's including GET params. |
@LukeTowers let's see what Taylor says. |
Why not just change the |
I still am not sure this fixes your "vulnerability" - can a malicious user not simply send a |
Already doing that in our projects as a stop gap.
The main concern is CSRF attacks triggered unintentionally. AFAIK you can't make a users browser send a different content type header for GET requests for things like regular links and img sources. |
@LukeTowers Can we make the change to have |
@taylorotwell while it could possibly solve my specific problem, I'm not sure that's all that helpful overall given the amount of people out there using |
@driesvints will we be able to get this backported to 6.x as well? |
Hey @LukeTowers. No we won't be backporting this one. We're not super confident that it won't break anything so this one will only target the next version. |
This fixes a 6 year old bug introduced in #7052 where GET requests would have GET data populated in the POST body property leading to issues around
Request::post()
and$request->getParsedBody()
returning GET values when called on GET requests.This is a resubmit of #17087 & #36708, and fixes #22805. Credit to @dan-har for the initial solution and @mixlion for updating it for >=6.x.
The original PR was meant to support POST requests where their
content-type
was set toapplication/json
(instead of the typicalapplication/x-www-form-urlencoded
), but it introduced a subtle and dangerous bug because while$request->getInputSource()
does return the JSON data for JSON requests, it also returns the GET data for GET requests. This commit solves the underlying issue without breaking compatibility with the original functionality.This PR is submitted as a direct result from a security issue reported to me by users of @wintercms & @octobercms and was submitted after a discussion with @taylorotwell via email.
I request that this fix also be backported to 6.x @driesvints