@@ -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 a ``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
@@ -30,11 +30,19 @@ your proxy.
30
30
// only trust proxy headers coming from this IP addresses
31
31
Request::setTrustedProxies(array('192.0.0.1', '10.0.0.0/8'));
32
32
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
+
33
40
Configuring Header Names
34
41
------------------------
35
42
36
43
By default, the following proxy headers are trusted:
37
44
45
+ * ``Forwarded `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getClientIp `;
38
46
* ``X-Forwarded-For `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getClientIp `;
39
47
* ``X-Forwarded-Host `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getHost `;
40
48
* ``X-Forwarded-Port `` Used in :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getPort `;
@@ -43,6 +51,7 @@ By default, the following proxy headers are trusted:
43
51
If your reverse proxy uses a different header name for any of these, you
44
52
can configure that header name via :method: `Symfony\\ Component\\ HttpFoundation\\ Request::setTrustedHeaderName `::
45
53
54
+ Request::setTrustedHeaderName(Request::HEADER_FORWARDED, 'X-Forwarded');
46
55
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X-Proxy-For');
47
56
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X-Proxy-Host');
48
57
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X-Proxy-Port');
@@ -51,9 +60,9 @@ can configure that header name via :method:`Symfony\\Component\\HttpFoundation\\
51
60
Not Trusting certain Headers
52
61
----------------------------
53
62
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
55
64
listed above are trusted. If you need to trust some of these headers but
56
65
not others, you can do that as well::
57
66
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 );