Skip to content

[HttpFoundation] Add $trustedHeaderSet arg to Request::setTrustedProxies() - deprecate not setting it #21830

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

Merged
merged 1 commit into from
Mar 22, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Mar 1, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? no tests yet
Fixed tickets -
License MIT
Doc PR -

Follow up of #18688

PR adds a second $trustedHeaderSet argument to Request::setTrustedProxies(), can be either Request::HEADER_FORWARDED or Request::HEADER_X_FORWARDED_ALL to set which header to trust from your proxies - the idea being that without this info, one will get some ConflictingHeadersException, but those may be lost in the logs.

@nicolas-grekas
Copy link
Member Author

PR scope now focused on adding the second argument only. Ready.

Status: needs review

*/
public static function setTrustedProxies(array $proxies)
public static function setTrustedProxies(array $proxies/*, string $trustedHeader*/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the comment is a mistake ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a reminder, for it to be uncommented in 4.0, as done in such cases usually already

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Mar 11, 2017

I'm working on adding a new kernel.trusted_header_set config option in fwb, and deprecate not setting it when kernel.trusted_proxies is set.
I'm also wondering if we shouldn't plan for renaming all the Request::HEADER_CLIENT_* to Request::HEADER_X_FORWARDED_* to make them less critic.
Please advise @symfony/deciders, I'd appreciate some feedback on this PR.

@nicolas-grekas nicolas-grekas force-pushed the request-forward branch 2 times, most recently from 724fb7a to 1539245 Compare March 18, 2017 17:12
@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] Add $trustedHeader arg to Request::setTrustedProxies() - deprecate not setting it [HttpFoundation] Add $trustedHeaderSet arg to Request::setTrustedProxies() - deprecate not setting it Mar 18, 2017
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Mar 18, 2017

Status: needs review

PR ready, with more deprecations, namely:

  • Request::CLIENT_*
  • Request::get/setTrustedHeaderName()
  • framework.trusted_proxies config and kernel.trusted_proxies param

or to `Request::HEADER_X_FORWARDED_ALL` if it is using `X-Forwarded-*` headers instead.

* The `Request::setTrustedHeaderName()` and `Request::getTrustedHeaderName()` methods are deprecated,
use the RFC7239 `Forwarded` header, or the `X-Forwarded-*` headers instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but IIRC, it was introduced because some proxies/setups use non-standard headers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at Express, the values are hardcoded:
http://expressjs.com/en/guide/behind-proxies.html
https://github.com/expressjs/express/blob/master/lib/request.js
I guess we're safe not supporting any fancy names.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default names are non-standard, but widely used by popular reverse proxies (like Apache mod_proxy or Amazon EC2).. So, I think we should check if this is still the case or not.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Mar 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I looked correctly, I'd rephrase this to "The default names are non-standardized" - because they are the defacto standard in fact. Can anyone find any other name in use in place of X-Forwarded-*, with the same semantic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, Apache mod_proxy and Amazon EC2 use different names.

@@ -548,11 +571,26 @@ public function overrideGlobals()
*
* You should only list the reverse proxies that you manage directly.
*
* @param array $proxies A list of trusted proxies
* @param array $proxies A list of trusted proxies
* @param int $trustedHeaderSet A bit field of Request::HEADER_*, usually either Request::HEADER_FORWARDED or Request::HEADER_X_FORWARDED_ALL, to set which headers to trust from your proxies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I means that you can trust the Forwarded and the X-Forwarded-For headers at the same time. I don't think that this is desirable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's still legitimate to support that, at least for BC.
This would be really opt-in anyway, low chance anyone will do it be mistake to me.

UPGRADE-3.3.md Outdated
@@ -126,6 +126,9 @@ FrameworkBundle
* The `cache:clear` command should always be called with the `--no-warmup` option.
Warmup should be done via the `cache:warmup` command.

* The "framework.trusted_proxies configuration option and the corresponding "kernel.trusted_proxies" parameter have been deprecated and will be removed in 4.0. Use the Request::setTrustedProxies() method in your front controller instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing '"' after 'framework.trusted_proxies'

@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

👍

@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit d3c9604 into symfony:master Mar 22, 2017
fabpot added a commit that referenced this pull request Mar 22, 2017
…:setTrustedProxies() - deprecate not setting it (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[HttpFoundation] Add $trustedHeaderSet arg to Request::setTrustedProxies() - deprecate not setting it

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | no tests yet
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Follow up of #18688

PR adds a second `$trustedHeaderSet` argument to `Request::setTrustedProxies()`, can be either `Request::HEADER_FORWARDED` or `Request::HEADER_X_FORWARDED_ALL` to set which header to trust from your proxies - the idea being that without this info, one will get some `ConflictingHeadersException`, but those may be lost in the logs.

Commits
-------

d3c9604 [HttpFoundation] Add $trustedHeaderSet arg to Request::setTrustedProxies() - deprecate not setting it
@nicolas-grekas nicolas-grekas deleted the request-forward branch March 22, 2017 22:37
@weaverryan
Copy link
Member

Don't forget about the docs please! I just opened an issue on the docs about this - our system of always making sure at least a docs issue is opened for changes is really important! It doesn't need to be a PR - we can take care of it :)

@dzuelke
Copy link
Contributor

dzuelke commented Mar 30, 2017

Bit late to the game, but I'd like to point out #20178, which is related, and should maybe be addressed together with this.

TL;DR: out of the box, Symfony should not trust any headers, even when setting a trusted proxy; the list should always be opt-in, as people are vulnerable to header forgery otherwise. AWS ELBs do not set an X-Forwarded-Host header!

Poking @fabpot and @nicolas-grekas :)

@dzuelke
Copy link
Contributor

dzuelke commented Mar 30, 2017

Also see symfony/symfony-docs#7045

fabpot added a commit that referenced this pull request Apr 3, 2017
…) takes a new required $trustedHeaderSet argument (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[BC BREAK][HttpFoundation] Request::setTrustedProxies() takes a new required $trustedHeaderSet argument

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #20178
| License       | MIT
| Doc PR        | -

As discussed in linked issue, and already deprecated by #21830

Commits
-------

72e2895 [BC BREAK][HttpFoundation] Request::setTrustedProxies() takes a new required $trustedHeaderSet argument
@fabpot fabpot mentioned this pull request May 1, 2017
ogizanagi added a commit to ogizanagi/recipes that referenced this pull request May 3, 2017
fabpot added a commit to symfony/recipes that referenced this pull request May 3, 2017
This PR was merged into the master branch.

Discussion
----------

Remove framework.trusted_proxies option

As deprecated and "removed" in symfony/symfony#21830 and symfony/symfony#22238 (BC break)

Commits
-------

2507e41 Remove framework.trusted_proxies option
markovlatkovic pushed a commit to markovlatkovic/recipes that referenced this pull request May 24, 2024
markovlatkovic pushed a commit to markovlatkovic/recipes that referenced this pull request May 24, 2024
This PR was merged into the master branch.

Discussion
----------

Remove framework.trusted_proxies option

As deprecated and "removed" in symfony/symfony#21830 and symfony/symfony#22238 (BC break)

Commits
-------

2507e41 Remove framework.trusted_proxies option
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