Skip to content

[HttpFoundation] Request->getRequestFormat should only rely on the request attributes #8967

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

Closed
wants to merge 2 commits into from

Conversation

pvandommelen
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? possibly
Deprecations? no
Tests pass? yes
Fixed tickets #8966
License MIT
Doc PR

Added test case and fix for #8966. Is this functionality relied on somewhere?

@fabpot
Copy link
Member

fabpot commented Sep 30, 2013

Doing it that way is a BC break. I think it would be better to introduce a way to active the old behavior (off by default) and immediately deprecate this setting that would be removed in 3.0.

@pvandommelen
Copy link
Contributor Author

In a similar way to enableHttpMethodParameterOverride? @fieg, since you had actual problems here, what is your opinion?

@fieg
Copy link
Contributor

fieg commented Oct 1, 2013

Handling it similar as the httpMethodParameterOverride method sounds like a great plan to me.

I'm not sure if it should be deprecated tho, as the method parameter override isn't deprecated either? Perhaps they would both need to be deprecated then? Also, should a getRealRequestFormat method to be introduced, similar as getRealMethod?

@stof
Copy link
Member

stof commented Oct 1, 2013

@fieg the HTTP method override is needed in case you design your app to work with Restful methods, because browsers don't support all HTTP methods but only GET and POST for form submission.
On the other hand, looking at the query string and the POST params to select the response format is not something mandated by a limitation of the client. It is only a mistake when implementing the method a few years ago. If BC was not a concern, we would simply fix the issue. But as some devs may have written code relying on this bug, we need to provide a BC layer for them (but mark them as deprecated because the good choice would be to fix their app)

Implementing getRealRequestFormat does not make sense as there is no concept of "real" request format compared to an overriden one. This setting is not about overriding the request format but about determining it.

@fieg
Copy link
Contributor

fieg commented Oct 1, 2013

Thank you for the clarification. I totally agree with you.

@stof
Copy link
Member

stof commented Oct 28, 2013

@fabpot This is even worse than I thought. The GET parameter is winning over the request attribute. So even if you put a requirement on the _format placeholder, the format can be anything in a forged request adding a GET parameter.

@pvandommelen
Copy link
Contributor Author

Yes, it is probably a security problem if you have different access rules for different formats in your app. I suppose this is not a common pattern though.

@Tobion
Copy link
Contributor

Tobion commented Sep 11, 2014

I agree this is a big and possibly security-related issue.

Users can simply overwrite the format with whatever they want even when your route does not even support this format, e.g. /foo.json?_format=html

The proposed change fixed it indeed.

@fabpot
Copy link
Member

fabpot commented Oct 2, 2015

I'm going to merge this one on master for Symfony 3.0.

@fabpot
Copy link
Member

fabpot commented Oct 2, 2015

ping @symfony/deciders

@weaverryan
Copy link
Member

@fabpot so this would just need to be a documented BC break for 3.0? Or will we do more work to try to trigger deprecation warnings?

Anyways, I agree with the change. The trick is not breaking existing apps and giving an upgrade path - and that part doesn't seem to be here yet.

@fabpot
Copy link
Member

fabpot commented Oct 2, 2015

I think documenting that this should be avoided in pre-2.8 is enough. People using the feature the wrong can easily fix their code as this is probably almost always a mis-configuration. Triggering a deprecation notice is also possible but then any end user will be able to trigger it which is probably not a good idea.

@Tobion
Copy link
Contributor

Tobion commented Oct 2, 2015

👍

The preview error route also has a _format placeholder, so it is still possible to test errors in different formats: https://github.com/symfony/symfony/blob/2.8/src/Symfony/Bundle/TwigBundle/Resources/config/routing/errors.xml#L7

@fabpot
Copy link
Member

fabpot commented Oct 2, 2015

Thank you @pvandommelen.

fabpot added a commit that referenced this pull request Oct 2, 2015
…rely on the request attributes (pvandommelen)

This PR was squashed before being merged into the 3.0-dev branch (closes #8967).

Discussion
----------

[HttpFoundation] Request->getRequestFormat should only rely on the request attributes

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | possibly
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8966
| License       | MIT
| Doc PR        |

Added test case and fix for #8966. Is this functionality relied on somewhere?

Commits
-------

7115c1e [HttpFoundation] Request->getRequestFormat should only rely on the request attributes
@fabpot fabpot closed this Oct 2, 2015
@fabpot fabpot mentioned this pull request Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants