@@ -11,9 +11,9 @@ Trusting Proxies
11
11
12
12
If you find yourself behind some sort of proxy - like a load balancer - then
13
13
certain 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 an ``X-Forwarded-Host `` header.
17
17
18
18
Since HTTP headers can be spoofed, Symfony does *not * trust these proxy
19
19
headers by default. If you are behind a proxy, you should manually whitelist
@@ -26,11 +26,19 @@ your proxy.
26
26
// only trust proxy headers coming from this IP addresses
27
27
Request::setTrustedProxies(array('192.0.0.1', '10.0.0.0/8'));
28
28
29
+ You should also make sure that your proxy filters unauthorized use of these
30
+ headers, e.g. if a proxy natively uses the ``X-Forwarded-For `` header, it
31
+ should not allow clients to send ``Forwarded `` headers to Symfony.
32
+
33
+ If your proxy does not filter headers appropriately, you need to configure
34
+ Symfony not to trust the headers your proxy does not filter (see below).
35
+
29
36
Configuring Header Names
30
37
------------------------
31
38
32
39
By default, the following proxy headers are trusted:
33
40
41
+ * ``Forwarded `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getClientIp `;
34
42
* ``X-Forwarded-For `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getClientIp `;
35
43
* ``X-Forwarded-Host `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getHost `;
36
44
* ``X-Forwarded-Port `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getPort `;
@@ -39,6 +47,7 @@ By default, the following proxy headers are trusted:
39
47
If your reverse proxy uses a different header name for any of these, you
40
48
can configure that header name via :method: `Symfony\\ Component\\ HttpFoundation\\ Request::setTrustedHeaderName `::
41
49
50
+ Request::setTrustedHeaderName(Request::HEADER_FORWARDED, 'X-Forwarded');
42
51
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X-Proxy-For');
43
52
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X-Proxy-Host');
44
53
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X-Proxy-Port');
@@ -47,9 +56,9 @@ can configure that header name via :method:`Symfony\\Component\\HttpFoundation\\
47
56
Not Trusting certain Headers
48
57
----------------------------
49
58
50
- By default, if you whitelist your proxy's IP address, then all four headers
59
+ By default, if you whitelist your proxy's IP address, then all five headers
51
60
listed above are trusted. If you need to trust some of these headers but
52
61
not others, you can do that as well::
53
62
54
- // disables trusting the ``X- Forwarded-Proto `` header, the default header is used
55
- Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, '' );
63
+ // disables trusting the ``Forwarded`` header
64
+ Request::setTrustedHeaderName(Request::HEADER_FORWARDED, null );
0 commit comments