1
- How does the Security access_control Work?
1
+ How Does the Security access_control Work?
2
2
==========================================
3
3
4
4
For each incoming request, Symfony checks each ``access_control `` entry
@@ -150,33 +150,24 @@ options:
150
150
151
151
.. _book-security-securing-ip :
152
152
153
- Securing by IP
154
- --------------
153
+ Matching access_control By IP
154
+ -----------------------------
155
155
156
- Certain situations may arise when you may need to restrict access to a given
157
- path based on IP. This is particularly relevant in the case of
158
- :ref: `Edge Side Includes <edge-side-includes >` (ESI), for example. When ESI is
159
- enabled, it's recommended to secure access to ESI URLs. Indeed, some ESI may
160
- contain some private content like the current logged in user's information. To
161
- prevent any direct access to these resources from a web browser (by guessing the
162
- ESI URL pattern), the ESI route **must ** be secured to be only visible from
163
- the trusted reverse proxy cache.
164
-
165
- .. versionadded :: 2.3
166
- Version 2.3 allows multiple IP addresses in a single rule with the ``ips: [a, b] ``
167
- construct. Prior to 2.3, users should create one rule per IP address to match and
168
- use the ``ip `` key instead of ``ips ``.
156
+ Certain situations may arise when you need to have an ``access_control ``
157
+ entry that *only * matches requests coming from some IP address or range.
158
+ For example, this *could * be used to deny access to a URL pattern to all
159
+ requests *except * those from a trusted, internal server.
169
160
170
161
.. caution ::
171
162
172
- As you'll read in the explanation below the example, the ``ip `` option
173
- does not restrict to a specific IP address. Instead, using the ``ip ``
163
+ As you'll read in the explanation below the example, the ``ips `` option
164
+ does not restrict to a specific IP address. Instead, using the ``ips ``
174
165
key means that the ``access_control `` entry will only match this IP address,
175
166
and users accessing it from a different IP address will continue down
176
167
the ``access_control `` list.
177
168
178
- Here is an example of how you might secure all ESI routes that start with a
179
- given prefix, `` /esi ``, from outside access :
169
+ Here is an example of how you configure some example `` /internal* `` URL
170
+ pattern so that it is only accessible by requests from the local server itself :
180
171
181
172
.. configuration-block ::
182
173
@@ -186,8 +177,9 @@ given prefix, ``/esi``, from outside access:
186
177
security :
187
178
# ...
188
179
access_control :
189
- - { path: ^/esi, roles: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
190
- - { path: ^/esi, roles: ROLE_NO_ACCESS }
180
+ #
181
+ - { path: ^/internal, roles: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
182
+ - { path: ^/internal, roles: ROLE_NO_ACCESS }
191
183
192
184
.. code-block :: xml
193
185
@@ -227,19 +219,19 @@ given prefix, ``/esi``, from outside access:
227
219
),
228
220
));
229
221
230
- Here is how it works when the path is ``/esi /something `` coming from the
231
- ``10.0.0.1 `` IP :
222
+ Here is how it works when the path is ``/internal /something `` coming from
223
+ the external IP address ``10.0.0.1 ``:
232
224
233
225
* The first access control rule is ignored as the ``path `` matches but the
234
- `` ip `` does not match either of the IPs listed;
226
+ IP address does not match either of the IPs listed;
235
227
236
228
* The second access control rule is enabled (the only restriction being the
237
- ``path `` and it matches): as the user cannot have the `` ROLE_NO_ACCESS ``
238
- role as it's not defined, access is denied (the ``ROLE_NO_ACCESS `` role can
239
- be anything that does not match an existing role, it just serves as a trick
240
- to always deny access).
229
+ ``path ``) and so it matches. If you make sure that no users ever have
230
+ `` ROLE_NO_ACCESS ``, then access is denied (``ROLE_NO_ACCESS `` can be anything
231
+ that does not match an existing role, it just serves as a trick to always
232
+ deny access).
241
233
242
- Now, if the same request comes from ``127.0.0.1 `` or ``::1 `` (the IPv6 loopback
234
+ But if the same request comes from ``127.0.0.1 `` or ``::1 `` (the IPv6 loopback
243
235
address):
244
236
245
237
* Now, the first access control rule is enabled as both the ``path `` and the
0 commit comments