Skip to content

Commit c095889

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: Fixing function name Shortening the text some more Shortening the text and adding link to jQuery Allow to configure trusted proxies and headers using config options Replace link to getConfiguration method Add Firebase notifier to documentation
2 parents 89210de + 343d1e0 commit c095889

File tree

5 files changed

+132
-59
lines changed

5 files changed

+132
-59
lines changed

bundles/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ As long as your bundle's configuration is located in the standard location
330330
(``YourBundle\DependencyInjection\Configuration``) and does not have
331331
a constructor it will work automatically. If you
332332
have something different, your ``Extension`` class must override the
333-
:method:`Extension::getConfiguration() <Symfony\\Component\\HttpKernel\\DependencyInjection\\Extension::getConfiguration>`
333+
:method:`Extension::getConfiguration() <Symfony\\Component\\DependencyInjection\\Extension\\Extension::getConfiguration>`
334334
method and return an instance of your ``Configuration``.
335335

336336
Supporting XML

deployment/proxies.rst

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,69 @@ Solution: ``setTrustedProxies()``
2222
---------------------------------
2323

2424
To fix this, you need to tell Symfony which reverse proxy IP addresses to trust
25-
and what headers your reverse proxy uses to send information::
26-
27-
// public/index.php
28-
29-
// ...
30-
$request = Request::createFromGlobals();
31-
32-
// tell Symfony about your reverse proxy
33-
Request::setTrustedProxies(
34-
// the IP address (or range) of your proxy
35-
['192.0.0.1', '10.0.0.0/8'],
36-
37-
// trust *all* "X-Forwarded-*" headers
38-
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
39-
40-
// or, if your proxy instead uses the "Forwarded" header
41-
// Request::HEADER_FORWARDED
42-
43-
// or, if you're using a well-known proxy
44-
// Request::HEADER_X_FORWARDED_AWS_ELB
45-
// Request::HEADER_X_FORWARDED_TRAEFIK
46-
);
25+
and what headers your reverse proxy uses to send information:
26+
27+
.. configuration-block::
28+
29+
.. config-block:: yaml
30+
31+
# config/packages/framework.yaml
32+
framework:
33+
# ...
34+
// the IP address (or range) of your proxy
35+
trusted_proxies: '192.0.0.1,10.0.0.0/8'
36+
// trust *all* "X-Forwarded-*" headers (the ! prefix means to not trust those headers)
37+
trusted_headers: ['x-forwarded-all', '!x-forwarded-host', '!x-forwarded-prefix']
38+
// or, if your proxy instead uses the "Forwarded" header
39+
trusted_headers: ['forwarded', '!x-forwarded-host', '!x-forwarded-prefix']
40+
// or, if you're using a wellknown proxy
41+
trusted_headers: [!php/const Symfony\\Component\\HttpFoundation\\Request::HEADER_X_FORWARDED_AWS_ELB, '!x-forwarded-host', '!x-forwarded-prefix']
42+
trusted_headers: [!php/const Symfony\\Component\\HttpFoundation\\Request::HEADER_X_FORWARDED_TRAEFIK, '!x-forwarded-host', '!x-forwarded-prefix']
43+
44+
.. config-block:: xml
45+
46+
<!-- config/packages/framework.xml -->
47+
<?xml version="1.0" encoding="UTF-8" ?>
48+
<container xmlns="http://symfony.com/schema/dic/services"
49+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
50+
xmlns:framework="http://symfony.com/schema/dic/symfony"
51+
xsi:schemaLocation="http://symfony.com/schema/dic/services
52+
https://symfony.com/schema/dic/services/services-1.0.xsd
53+
http://symfony.com/schema/dic/symfony
54+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
55+
56+
<framework:config>
57+
<!-- the IP address (or range) of your proxy -->
58+
<framework:trusted-proxies>192.0.0.1,10.0.0.0/8</framework:trusted-proxies>
59+
60+
<!-- trust *all* "X-Forwarded-*" headers (the ! prefix means to not trust those headers) -->
61+
<framework:trusted-header>x-forwarded-all</framework:trusted-header>
62+
<framework:trusted-header>!x-forwarded-host</framework:trusted-header>
63+
<framework:trusted-header>!x-forwarded-prefix</framework:trusted-header>
64+
65+
<!-- or, if your proxy instead uses the "Forwarded" header -->
66+
<framework:trusted-header>forwarded</framework:trusted-header>
67+
<framework:trusted-header>!x-forwarded-host</framework:trusted-header>
68+
<framework:trusted-header>!x-forwarded-prefix</framework:trusted-header>
69+
</framework:config>
70+
</container>
71+
72+
.. config-block:: php
73+
74+
// config/packages/framework.php
75+
use Symfony\Component\HttpFoundation\Request;
76+
77+
$container->loadFromExtension('framework', [
78+
// the IP address (or range) of your proxy
79+
'trusted_proxies' => '192.0.0.1,10.0.0.0/8',
80+
// trust *all* "X-Forwarded-*" headers (the ! prefix means to not trust those headers)
81+
'trusted_headers' => ['x-forwarded-all', '!x-forwarded-host', '!x-forwarded-prefix'],
82+
// or, if your proxy instead uses the "Forwarded" header
83+
'trusted_headers' => ['forwarded', '!x-forwarded-host', '!x-forwarded-prefix'],
84+
// or, if you're using a wellknown proxy
85+
'trusted_headers' => [Request::HEADER_X_FORWARDED_AWS_ELB, '!x-forwarded-host', '!x-forwarded-prefix'],
86+
'trusted_headers' => [Request::HEADER_X_FORWARDED_TRAEFIK, '!x-forwarded-host', '!x-forwarded-prefix'],
87+
]);
4788
4889
.. deprecated:: 5.2
4990

@@ -61,6 +102,13 @@ The Request object has several ``Request::HEADER_*`` constants that control exac
61102
*which* headers from your reverse proxy are trusted. The argument is a bit field,
62103
so you can also pass your own value (e.g. ``0b00110``).
63104

105+
.. versionadded:: 5.2
106+
107+
The feature to configure trusted proxies and headers with ``trusted_proxies``
108+
and ``trusted_headers`` options was introduced in Symfony 5.2. In earlier
109+
Symfony versions you needed to use the ``Request::setTrustedProxies()``
110+
method in the ``public/index.php`` file.
111+
64112
But what if the IP of my Reverse Proxy Changes Constantly!
65113
----------------------------------------------------------
66114

@@ -74,17 +122,17 @@ In this case, you'll need to - *very carefully* - trust *all* proxies.
74122
#. Once you've guaranteed that traffic will only come from your trusted reverse
75123
proxies, configure Symfony to *always* trust incoming request::
76124

77-
// public/index.php
125+
.. config-block:: yaml
78126

79-
// ...
80-
Request::setTrustedProxies(
81-
// trust *all* requests (the 'REMOTE_ADDR' string is replaced at
82-
// run time by $_SERVER['REMOTE_ADDR'])
83-
['127.0.0.1', 'REMOTE_ADDR'],
127+
# config/packages/framework.yaml
128+
framework:
129+
# ...
130+
// trust *all* requests (the 'REMOTE_ADDR' string is replaced at
131+
// run time by $_SERVER['REMOTE_ADDR'])
132+
trusted_proxies: '127.0.0.1,REMOTE_ADDR'
84133

85-
// if you're using ELB, otherwise use a constant from above
86-
Request::HEADER_X_FORWARDED_AWS_ELB
87-
);
134+
// if you're using ELB, otherwise use another Request::HEADER-* constant
135+
trusted_headers: [!php/const Symfony\\Component\\HttpFoundation\\Request::HEADER_X_FORWARDED_AWS_ELB, '!x-forwarded-host', '!x-forwarded-prefix']
88136

89137
That's it! It's critical that you prevent traffic from all non-trusted sources.
90138
If you allow outside traffic, they could "spoof" their true IP address and
@@ -100,6 +148,12 @@ other information.
100148
# .env
101149
TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR
102150
151+
.. config-block:: yaml
152+
153+
# config/packages/framework.yaml
154+
framework:
155+
# ...
156+
trusted_proxies: '%env(TRUSTED_PROXIES)%'
103157

104158
If you are also using a reverse proxy on top of your load balancer (e.g.
105159
`CloudFront`_), calling ``$request->server->get('REMOTE_ADDR')`` won't be
@@ -111,11 +165,13 @@ trusted proxies.
111165
Custom Headers When Using a Reverse Proxy
112166
-----------------------------------------
113167

114-
Some reverse proxies (like `CloudFront`_ with ``CloudFront-Forwarded-Proto``) may force you to use a custom header.
115-
For instance you have ``Custom-Forwarded-Proto`` instead of ``X-Forwarded-Proto``.
168+
Some reverse proxies (like `CloudFront`_ with ``CloudFront-Forwarded-Proto``)
169+
may force you to use a custom header. For instance you have
170+
``Custom-Forwarded-Proto`` instead of ``X-Forwarded-Proto``.
116171

117-
In this case, you'll need to set the header ``X-Forwarded-Proto`` with the value of
118-
``Custom-Forwarded-Proto`` early enough in your application, i.e. before handling the request::
172+
In this case, you'll need to set the header ``X-Forwarded-Proto`` with the value
173+
of ``Custom-Forwarded-Proto`` early enough in your application, i.e. before
174+
handling the request::
119175

120176
// public/index.php
121177

form/form_collections.rst

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ the following ``data-prototype`` attribute to the existing ``<ul>`` in your temp
245245

246246
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e('html_attr') }}"></ul>
247247

248-
Now add a button just next to the ``<ul>`` to dynamically add a new tag
248+
Now add a button just next to the ``<ul>`` to dynamically add a new tag:
249249

250250
.. code-block:: html+twig
251251

@@ -280,13 +280,13 @@ On the rendered page, the result will look something like this:
280280
the ``data-prototype`` attribute is automatically added to the containing ``div``,
281281
and you need to adjust the following JavaScript accordingly.
282282

283-
The goal of this section will be to use JavaScript to read this attribute
284-
and dynamically add new tag forms when the user clicks the "Add a tag" button.
285-
This example uses jQuery and assumes you have it included somewhere on your page.
283+
Now add some JavaScript to read this attribute and dynamically add new tag forms
284+
when the user clicks the "Add a tag" link. This example uses `jQuery`_ and
285+
assumes you have it included somewhere on your page (e.g. using Symfony's
286+
:doc:`Webpack Encore </frontend>`).
286287

287-
Add a ``script`` tag somewhere on your page so you can start writing some
288-
JavaScript. In this script, bind to the "click" event of the "Add a tag"
289-
button so you can add a new tag form (``addFormToCollection()`` will be show next):
288+
Add a ``<script>`` tag somewhere on your page to include the required
289+
functionality with JavaScript:
290290

291291
.. code-block:: javascript
292292
@@ -304,14 +304,11 @@ button so you can add a new tag form (``addFormToCollection()`` will be show nex
304304
})
305305
});
306306
307-
The ``addTagForm()`` function's job will be to use the ``data-prototype`` attribute
308-
to dynamically add a new form when this link is clicked. The ``data-prototype``
309-
HTML contains the tag ``text`` input element with a name of ``task[tags][__name__][name]``
310-
and id of ``task_tags___name___name``. The ``__name__`` is a little "placeholder",
311-
which you'll replace with a unique, incrementing number (e.g. ``task[tags][3][name]``).
312-
313-
The actual code needed to make this all work can vary quite a bit, but here's
314-
one example:
307+
The ``addFormToCollection()`` function's job will be to use the ``data-prototype``
308+
attribute to dynamically add a new form when this link is clicked. The ``data-prototype``
309+
HTML contains the tag's ``text`` input element with a name of ``task[tags][__name__][name]``
310+
and id of ``task_tags___name___name``. The ``__name__`` is a placeholder, which
311+
you'll replace with a unique, incrementing number (e.g. ``task[tags][3][name]``):
315312

316313
.. code-block:: javascript
317314
@@ -344,11 +341,6 @@ one example:
344341
$collectionHolder.append($newFormLi)
345342
}
346343
347-
.. note::
348-
349-
It is better to separate your JavaScript in real JavaScript files than
350-
to write it inside the HTML as is done here.
351-
352344
Now, each time a user clicks the ``Add a tag`` link, a new sub form will
353345
appear on the page. When the form is submitted, any new tag forms will be converted
354346
into new ``Tag`` objects and added to the ``tags`` property of the ``Task`` object.
@@ -572,7 +564,7 @@ First, add a "delete this tag" link to each tag form:
572564
// ... the rest of the block from above
573565
});
574566
575-
function addTagForm() {
567+
function addFormToCollection() {
576568
// ...
577569
578570
// add a delete link to the new form
@@ -684,6 +676,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
684676
the `symfony-collection`_ package based on jQuery for the rest of browsers.
685677

686678
.. _`Owning Side and Inverse Side`: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/unitofwork-associations.html
679+
.. _`jQuery`: http://jquery.com/
687680
.. _`JSFiddle`: http://jsfiddle.net/847Kf/4/
688681
.. _`@a2lix/symfony-collection`: https://github.com/a2lix/symfony-collection
689682
.. _`symfony-collection`: https://github.com/ninsuo/symfony-collection

notifier.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ integration with these chat services:
145145
Service Package DSN
146146
========== ================================ ===========================================================================
147147
Discord ``symfony/discord-notifier`` ``discord://TOKEN@default?webhook_id=ID``
148+
Firebase ``symfony/firebase-notifier`` ``firebase://USERNAME:PASSWORD@default``
148149
GoogleChat ``symfony/google-chat-notifier`` ``googlechat://ACCESS_KEY:ACCESS_TOKEN@default/SPACE?threadKey=THREAD_KEY``
149150
LinkedIn ``symfony/linked-in-notifier`` ``linkedin://TOKEN:USER_ID@default``
150151
Mattermost ``symfony/mattermost-notifier`` ``mattermost://ACCESS_TOKEN@HOST/PATH?channel=CHANNEL``
@@ -156,7 +157,9 @@ Zulip ``symfony/zulip-notifier`` ``zulip://EMAIL:TOKEN@HOST?channel
156157

157158
.. versionadded:: 5.1
158159

159-
The Mattermost and RocketChat integrations were introduced in Symfony 5.1.
160+
The Firebase, Mattermost and RocketChat integrations were introduced in Symfony
161+
5.1. The Slack DSN changed in Symfony 5.1 to use Slack Incoming
162+
Webhooks instead of legacy tokens.
160163

161164
.. versionadded:: 5.2
162165

reference/configuration/framework.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ Configuration
284284
* `logging`_
285285
* :ref:`paths <reference-translator-paths>`
286286

287+
* `trusted_headers`_
287288
* `trusted_hosts`_
288289
* `trusted_proxies`_
289290
* `validation`_
@@ -380,12 +381,32 @@ named ``kernel.http_method_override``.
380381
$request = Request::createFromGlobals();
381382
// ...
382383

384+
.. _reference-framework-trusted-headers:
385+
386+
trusted_headers
387+
~~~~~~~~~~~~~~~
388+
389+
.. versionadded:: 5.2
390+
391+
The ``trusted_headers`` option was introduced in Symfony 5.2.
392+
393+
The ``trusted_headers`` option is needed to configure which client information
394+
should be trusted (e.g. their host) when running Symfony behind a load balancer
395+
or a reverse proxy. See :doc:`/deployment/proxies`.
396+
383397
.. _reference-framework-trusted-proxies:
384398

385399
trusted_proxies
386400
~~~~~~~~~~~~~~~
387401

388-
The ``trusted_proxies`` option was removed in Symfony 3.3. See :doc:`/deployment/proxies`.
402+
.. versionadded:: 5.2
403+
404+
The ``trusted_headers`` option was reintroduced in Symfony 5.2 (it had been
405+
removed in Symfony 3.3).
406+
407+
The ``trusted_proxies`` option is needed to get precise information about the
408+
client (e.g. their IP address) when running Symfony behind a load balancer or a
409+
reverse proxy. See :doc:`/deployment/proxies`.
389410

390411
ide
391412
~~~

0 commit comments

Comments
 (0)