Skip to content

Suggest settings trusted proxies via env var for more traditional infrastructure #18157

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

Merged
merged 1 commit into from
Apr 26, 2023
Merged
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
33 changes: 16 additions & 17 deletions deployment/proxies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ and what headers your reverse proxy uses to send information:
to trust all "X-Forwarded-" headers, but that constant is deprecated since
Symfony 5.2 in favor of the individual ``HEADER_X_FORWARDED_*`` constants.

.. tip::

You can set a ``TRUSTED_PROXIES`` env var to configure proxies on a per-environment basis:

.. code-block:: bash

# .env
TRUSTED_PROXIES=127.0.0.1,10.0.0.0/8

.. code-block:: yaml

# config/packages/framework.yaml
framework:
# ...
trusted_proxies: '%env(TRUSTED_PROXIES)%'

.. caution::

Enabling the ``Request::HEADER_X_FORWARDED_HOST`` option exposes the
Expand Down Expand Up @@ -136,23 +152,6 @@ 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.

.. tip::

In applications using :ref:`Symfony Flex <symfony-flex>` you can set the
``TRUSTED_PROXIES`` env var:

.. code-block:: bash

# .env
TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR

.. code-block:: yaml

# config/packages/framework.yaml
framework:
# ...
trusted_proxies: '%env(TRUSTED_PROXIES)%'

If you are also using a reverse proxy on top of your load balancer (e.g.
`CloudFront`_), calling ``$request->server->get('REMOTE_ADDR')`` won't be
enough, as it will only trust the node sitting directly above your application
Expand Down