-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Documented how to configure Symfony correctly with regards to the Forwarded header #6526
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,21 @@ Remember to configure :ref:`framework.trusted_proxies <reference-framework-trust | |
in the Symfony configuration so that Varnish is seen as a trusted proxy and the | ||
:ref:`X-Forwarded <varnish-x-forwarded-headers>` headers are used. | ||
|
||
Varnish, in its' default configuration, sends the ``X-Forwarded-For`` header but | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
does not filter out the ``Forwarded``. If you have access to the Varnish | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
configuration file, you can configure Varnish to remove the ``Forwarded`` | ||
header:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the colons needs to be removed to make the build happy. :) |
||
|
||
.. code-block:: varnish4 | ||
|
||
sub vcl_recv { | ||
remove req.http.Forwarded; | ||
} | ||
|
||
If you do not have access to your Varnish configuration, you can instead | ||
configure Symfony to distrust the ``Forwarded`` header as detailed in | ||
:doc:`/cookbook/request/load_balancer_reverse_proxy`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you add |
||
|
||
.. _varnish-x-forwarded-headers: | ||
|
||
Routing and X-FORWARDED Headers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ via HTTPS, the client's port and the hostname being requested. | |
Solution: trusted_proxies | ||
------------------------- | ||
|
||
This is no problem, but you *do* need to tell Symfony that this is happening | ||
This is no problem, but you *do* need to tell Symfony what is happening | ||
and which reverse proxy IP addresses will be doing this type of thing: | ||
|
||
.. configuration-block:: | ||
|
@@ -62,6 +62,9 @@ the IP address ``192.0.0.1`` or matches the range of IP addresses that use | |
the CIDR notation ``10.0.0.0/8``. For more details, see the | ||
:ref:`framework.trusted_proxies <reference-framework-trusted-proxies>` option. | ||
|
||
You are also saying that you trust that the proxy does not send conflicting | ||
headers, e.g. sending both X-Forwarded-For and Forwarded in the same request. | ||
|
||
That's it! Symfony will now look for the correct headers to get information | ||
like the client's IP address, host, port and whether the request is | ||
using HTTPS. | ||
|
@@ -95,6 +98,27 @@ That's it! It's critical that you prevent traffic from all non-trusted sources. | |
If you allow outside traffic, they could "spoof" their true IP address and | ||
other information. | ||
|
||
My Reverse Proxy sends X-Forwarded-For but does not filter the Forwarded header | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use title case in the Symfony docs. This means that this headline has to be capitialized like |
||
------------------------------------------------------------------------------- | ||
|
||
Many popular proxy implementations do not yet support the Forwarded header and | ||
does not filter it by default configuration. Ideally, you would configure this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "proxy implementations" is plural, so this needs to be "do not filter it by default." (I would skip configuration here as well) |
||
in your proxy, but if this is not possible, you can tell Symfony to distrust | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a long sentence, you might want to split it up here: "in your proxy. If this is not possible, you can [...]" |
||
the Forwarded header, while still trusting your proxy's X-Forwarded-For header. | ||
|
||
This is done inside of your front controller:: | ||
|
||
// web/app.php | ||
|
||
// ... | ||
Request::setTrustedHeaderName(Request::HEADER_FORWARDED, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously, we set it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed |
||
|
||
$response = $kernel->handle($request); | ||
// ... | ||
|
||
Configuring the proxy server trust is very important, as not doing so will | ||
malicious users to "spoof" their IP address. | ||
|
||
My Reverse Proxy Uses Non-Standard (not X-Forwarded) Headers | ||
------------------------------------------------------------ | ||
|
||
|
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.
Maybe replace "true host" with "actual host" here? (my dev. mind strongly binds true to a boolean value)