1
1
.. index ::
2
2
single: Security; Restrict Security Firewalls to a Host
3
3
4
- How to restrict Firewalls to a Specific Host
4
+ How to Restrict Firewalls to a Specific Host
5
5
============================================
6
6
7
7
.. versionadded :: 2.4
8
8
Support for restricting security firewalls to a specific host was added in
9
9
Symfony 2.4.
10
10
11
11
When using the Security component, you can create firewalls that match certain
12
- url patterns and thereby restrict access to all urls matching these patterns.
13
- Additionally, you can restrict a firewall to a host using the ``host `` key:
12
+ URL patterns and therefore are activated for all pages whose URL matches
13
+ that pattern. Additionally, you can restrict the initialization of a firewall
14
+ to a host using the ``host `` key:
14
15
15
16
.. configuration-block ::
16
17
@@ -24,7 +25,7 @@ Additionally, you can restrict a firewall to a host using the ``host`` key:
24
25
firewalls :
25
26
secured_area :
26
27
pattern : ^/
27
- host : admin\.example\.com
28
+ host : ^ admin\.example\.com$
28
29
http_basic : true
29
30
30
31
.. code-block :: xml
@@ -39,7 +40,7 @@ Additionally, you can restrict a firewall to a host using the ``host`` key:
39
40
40
41
<config >
41
42
<!-- ... -->
42
- <firewall name =" secured_area" pattern =" ^/" host =" admin.example.com" >
43
+ <firewall name =" secured_area" pattern =" ^/" host =" ^ admin\ .example\ .com$ " >
43
44
<http-basic />
44
45
</firewall >
45
46
</config >
@@ -55,8 +56,15 @@ Additionally, you can restrict a firewall to a host using the ``host`` key:
55
56
'firewalls' => array(
56
57
'secured_area' => array(
57
58
'pattern' => '^/',
58
- 'host' => 'admin.example.com',
59
+ 'host' => '^ admin\ .example\ .com$ ',
59
60
'http_basic' => true,
60
61
),
61
62
),
62
63
));
64
+
65
+ The ``host `` (like the ``path ``) is a regular expression. In this example,
66
+ the firewall will only be activated if the host is equal exactly (due to
67
+ the ``^ `` and ``$ `` regex characters) to the hostname ``admin.example.com ``.
68
+ If the hostname does not match this pattern, the firewall will not be activated
69
+ and subsequent firewalls will have the opportunity to be matched for this
70
+ request.
0 commit comments