Skip to content

Added a minor help note about Request::setTrustedProxies #7382

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions components/http_foundation/trusting_proxies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ the actual host may be stored in an ``X-Forwarded-Host`` header.

Since HTTP headers can be spoofed, Symfony does *not* trust these proxy
headers by default. If you are behind a proxy, you should manually whitelist
your proxy.

.. versionadded:: 2.3
CIDR notation support was introduced in Symfony 2.3, so you can whitelist whole
subnets (e.g. ``10.0.0.0/8``, ``fc00::/7``).
your proxy as follows:
Copy link
Member

Choose a reason for hiding this comment

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

Should we move the versionadded block somewhere as it may not read a bit weird with the colon here?


.. code-block:: php

use Symfony\Component\HttpFoundation\Request;

// only trust proxy headers coming from this IP addresses
// put this code as early as possible in your application (e.g. in your
// front controller) to only trust proxy headers coming from these IP addresses
Request::setTrustedProxies(array('192.0.0.1', '10.0.0.0/8'));

.. versionadded:: 2.3
CIDR notation support was introduced in Symfony 2.3, so you can whitelist whole
subnets (e.g. ``10.0.0.0/8``, ``fc00::/7``).

You should also make sure that your proxy filters unauthorized use of these
headers, e.g. if a proxy natively uses the ``X-Forwarded-For`` header, it
should not allow clients to send ``Forwarded`` headers to Symfony.
Expand Down