@@ -11,9 +11,9 @@ Trusting Proxies
1111
1212If you find yourself behind some sort of proxy - like a load balancer - then
1313certain header information may be sent to you using special ``X-Forwarded-* ``
14- headers. For example, the ``Host `` HTTP header is usually used to return
15- the requested host. But when you're behind a proxy, the true host may be
16- stored in a ``X-Forwarded-Host `` header.
14+ headers or the `` Forwarded `` header . For example, the ``Host `` HTTP header is
15+ usually used to return the requested host. But when you're behind a proxy,
16+ the actual host may be stored in a ``X-Forwarded-Host `` header.
1717
1818Since HTTP headers can be spoofed, Symfony does *not * trust these proxy
1919headers by default. If you are behind a proxy, you should manually whitelist
@@ -30,11 +30,19 @@ your proxy.
3030 // only trust proxy headers coming from this IP addresses
3131 Request::setTrustedProxies(array('192.0.0.1', '10.0.0.0/8'));
3232
33+ You should also make sure that your proxy filters unauthorized use of these
34+ headers, e.g. if a proxy natively uses the ``X-Forwarded-For `` header, it
35+ should not allow clients to send ``Forwarded `` headers to Symfony.
36+
37+ If your proxy does not filter headers appropriately, you need to configure
38+ Symfony not to trust the headers your proxy does not filter (see below).
39+
3340Configuring Header Names
3441------------------------
3542
3643By default, the following proxy headers are trusted:
3744
45+ * ``Forwarded `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getClientIp `;
3846* ``X-Forwarded-For `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getClientIp `;
3947* ``X-Forwarded-Host `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getHost `;
4048* ``X-Forwarded-Port `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getPort `;
@@ -43,6 +51,7 @@ By default, the following proxy headers are trusted:
4351If your reverse proxy uses a different header name for any of these, you
4452can configure that header name via :method: `Symfony\\ Component\\ HttpFoundation\\ Request::setTrustedHeaderName `::
4553
54+ Request::setTrustedHeaderName(Request::HEADER_FORWARDED, 'X-Forwarded');
4655 Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X-Proxy-For');
4756 Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X-Proxy-Host');
4857 Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X-Proxy-Port');
@@ -51,9 +60,9 @@ can configure that header name via :method:`Symfony\\Component\\HttpFoundation\\
5160Not Trusting certain Headers
5261----------------------------
5362
54- By default, if you whitelist your proxy's IP address, then all four headers
63+ By default, if you whitelist your proxy's IP address, then all five headers
5564listed above are trusted. If you need to trust some of these headers but
5665not others, you can do that as well::
5766
58- // disables trusting the ``X- Forwarded-Proto `` header, the default header is used
59- Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, '' );
67+ // disables trusting the ``Forwarded`` header
68+ Request::setTrustedHeaderName(Request::HEADER_FORWARDED, null );
0 commit comments