Skip to content

Commit 5c262d0

Browse files
committed
Merge pull request #2442 from danfinnie/multiple_ip_matching
[WCM] [SecurityBundle] Document multiple IP matching in rules
2 parents af8bd77 + 5f0aba7 commit 5c262d0

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

book/security.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ access control should be used on this request. The following ``access_control``
770770
options are used for matching:
771771

772772
* ``path``
773-
* ``ip``
773+
* ``ip`` or ``ips``
774774
* ``host``
775775
* ``methods``
776776

@@ -877,6 +877,11 @@ prevent any direct access to these resources from a web browser (by guessing the
877877
ESI URL pattern), the ESI route **must** be secured to be only visible from
878878
the trusted reverse proxy cache.
879879

880+
.. versionadded:: 2.3
881+
Version 2.3 allows multiple IP addresses in a single rule with the ``ips: [a, b]``
882+
construct. Prior to 2.3, users should create one rule per IP address to match and
883+
use the ``ip`` key instead of ``ips``.
884+
880885
Here is an example of how you might secure all ESI routes that start with a
881886
given prefix, ``/esi``, from outside access:
882887

@@ -888,36 +893,37 @@ given prefix, ``/esi``, from outside access:
888893
security:
889894
# ...
890895
access_control:
891-
- { path: ^/esi, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
896+
- { path: ^/esi, roles: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
892897
- { path: ^/esi, roles: ROLE_NO_ACCESS }
893898
894899
.. code-block:: xml
895900
896901
<access-control>
897-
<rule path="^/esi" role="IS_AUTHENTICATED_ANONYMOUSLY" ip="127.0.0.1" />
902+
<rule path="^/esi" role="IS_AUTHENTICATED_ANONYMOUSLY" ips="127.0.0.1, ::1" />
898903
<rule path="^/esi" role="ROLE_NO_ACCESS" />
899904
</access-control>
900905
901906
.. code-block:: php
902907
903908
'access_control' => array(
904-
array('path' => '^/esi', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY', 'ip' => '127.0.0.1'),
909+
array('path' => '^/esi', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY', 'ips' => '127.0.0.1, ::1'),
905910
array('path' => '^/esi', 'role' => 'ROLE_NO_ACCESS'),
906911
),
907912
908913
Here is how it works when the path is ``/esi/something`` coming from the
909914
``10.0.0.1`` IP:
910915

911916
* The first access control rule is ignored as the ``path`` matches but the
912-
``ip`` does not;
917+
``ip`` does not match either of the IPs listed;
913918

914919
* The second access control rule is enabled (the only restriction being the
915920
``path`` and it matches): as the user cannot have the ``ROLE_NO_ACCESS``
916921
role as it's not defined, access is denied (the ``ROLE_NO_ACCESS`` role can
917922
be anything that does not match an existing role, it just serves as a trick
918923
to always deny access).
919924

920-
Now, if the same request comes from ``127.0.0.1``:
925+
Now, if the same request comes from ``127.0.0.1`` or ``::1`` (the IPv6 loopback
926+
address):
921927

922928
* Now, the first access control rule is enabled as both the ``path`` and the
923929
``ip`` match: access is allowed as the user always has the

0 commit comments

Comments
 (0)