-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Next
Next commit
Enhanced Firewall Restrictions docs
Squashed commits: [2081fc4] Enhanced Firewall Restrictions docs for PR symfony/symfony#10404 [8f065bc] Add redirect to new page [b42e80f] fixed typos [cc6b07d] tiny update
- Loading branch information
commit 9889dbe00be1e046168bdb0001f7f80f15d766b5
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
.. index:: | ||
single: Security; Restrict Security Firewalls to a Request | ||
|
||
How to Restrict Firewalls to a Specific Request | ||
=============================================== | ||
|
||
When using the Security component, you can create firewalls that match certain request options. | ||
In most cases, matching against the URL is sufficient, but in special cases you can further | ||
restrict the initialization of a firewall against other options of the request. | ||
|
||
.. note:: | ||
|
||
You can use any of these restrictions individually or mix them together to get | ||
your desired firewall configuration. | ||
|
||
Restricting by Pattern | ||
---------------------- | ||
|
||
This is the default restriction and restricts a firewall to only be initialized if the request URL | ||
matches the configured ``pattern``. | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/security.yml | ||
|
||
# ... | ||
security: | ||
firewalls: | ||
secured_area: | ||
pattern: ^/admin | ||
# ... | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/security.xml --> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<srv:container xmlns="http://symfony.com/schema/dic/security" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:srv="http://symfony.com/schema/dic/services" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<config> | ||
<!-- ... --> | ||
<firewall name="secured_area" pattern="^/admin"> | ||
<!-- ... --> | ||
</firewall> | ||
</config> | ||
</srv:container> | ||
|
||
.. code-block:: php | ||
|
||
// app/config/security.php | ||
|
||
// ... | ||
$container->loadFromExtension('security', array( | ||
'firewalls' => array( | ||
'secured_area' => array( | ||
'pattern' => '^/admin', | ||
// ... | ||
), | ||
), | ||
)); | ||
|
||
The ``pattern`` is a regular expression. In this example, the firewall will only be | ||
activated if the URL starts (due to the ``^`` regex character) with ``/admin`. If | ||
the URL does not match this pattern, the firewall will not be activated and subsequent | ||
firewalls will have the opportunity to be matched for this request. | ||
|
||
Restricting by Host | ||
------------------- | ||
|
||
.. versionadded:: 2.4 | ||
Support for restricting security firewalls to a specific host was introduced in | ||
Symfony 2.4. | ||
|
||
If matching against the ``pattern`` only is not enough, the request can also be matched against | ||
``host``. When the configuration option ``host`` is set, the firewall will be restricted to | ||
only initialize if the host from the request matches against the configuration. | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/security.yml | ||
|
||
# ... | ||
security: | ||
firewalls: | ||
secured_area: | ||
host: ^admin\.example\.com$ | ||
# ... | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/security.xml --> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<srv:container xmlns="http://symfony.com/schema/dic/security" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:srv="http://symfony.com/schema/dic/services" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<config> | ||
<!-- ... --> | ||
<firewall name="secured_area" host="^admin\.example\.com$"> | ||
<!-- ... --> | ||
</firewall> | ||
</config> | ||
</srv:container> | ||
|
||
.. code-block:: php | ||
|
||
// app/config/security.php | ||
|
||
// ... | ||
$container->loadFromExtension('security', array( | ||
'firewalls' => array( | ||
'secured_area' => array( | ||
'host' => '^admin\.example\.com$', | ||
// ... | ||
), | ||
), | ||
)); | ||
|
||
The ``host`` (like the ``pattern``) is a regular expression. In this example, | ||
the firewall will only be activated if the host is equal exactly (due to | ||
the ``^`` and ``$`` regex characters) to the hostname ``admin.example.com``. | ||
If the hostname does not match this pattern, the firewall will not be activated | ||
and subsequent firewalls will have the opportunity to be matched for this | ||
request. | ||
|
||
Restricting by HTTP Methods | ||
--------------------------- | ||
|
||
.. versionadded:: 2.5 | ||
Support for restricting security firewalls to specific HTTP methods was introduced in | ||
Symfony 2.5. | ||
|
||
The configuration option ``methods`` restricts the ini 8000 tialization of the firewall to | ||
the provided HTTP methods. | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/security.yml | ||
|
||
# ... | ||
security: | ||
firewalls: | ||
secured_area: | ||
methods: [GET, POST] | ||
# ... | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/security.xml --> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<srv:container xmlns="http://symfony.com/schema/dic/security" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:srv="http://symfony.com/schema/dic/services" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<config> | ||
<!-- ... --> | ||
<firewall name="secured_area" methods="GET,POST"> | ||
<!-- ... --> | ||
</firewall> | ||
</config> | ||
</srv:container> | ||
|
||
.. code-block:: php | ||
|
||
// app/config/security.php | ||
|
||
// ... | ||
$container->loadFromExtension('security', array( | ||
'firewalls' => array( | ||
'secured_area' => array( | ||
'methods' => array('GET', 'POST'), | ||
// ... | ||
), | ||
), | ||
)); | ||
|
||
In this example, the firewall will only be activated if the HTTP method of the | ||
request is either ``GET`` or ``POST``. If the method is not in the array of the | ||
allowed methods, the firewall will not be activated and subsequent firewalls will again | ||
have the opportunity to be matched for this request. |
8000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,4 @@ | ||
.. index:: | ||
single: Security; Restrict Security Firewalls to a Host | ||
|
||
How to Restrict Firewalls to a Specific Host | ||
============================================ | ||
|
||
.. versionadded:: 2.4 | ||
Support for restricting security firewalls to a specific host was introduced in | ||
Symfony 2.4. | ||
|
||
When using the Security component, you can create firewalls that match certain | ||
URL patterns and therefore are activated for all pages whose URL matches | ||
that pattern. Additionally, you can restrict the initialization of a firewall | ||
to a host using the ``host`` key: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/security.yml | ||
|
||
# ... | ||
|
||
security: | ||
firewalls: | ||
secured_area: | ||
pattern: ^/ | ||
host: ^admin\.example\.com$ | ||
http_basic: true | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/security.xml --> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<srv:container xmlns="http://symfony.com/schema/dic/security" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:srv="http://symfony.com/schema/dic/services" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<config> | ||
<!-- ... --> | ||
<firewall name="secured_area" pattern="^/" host="^admin\.example\.com$"> | ||
<http-basic /> | ||
</firewall> | ||
</config> | ||
</srv:container> | ||
|
||
.. code-block:: php | ||
|
||
// app/config/security.php | ||
|
||
// ... | ||
|
||
$container->loadFromExtension('security', array( | ||
'firewalls' => array( | ||
'secured_area' => array( | ||
'pattern' => '^/', | ||
'host' => '^admin\.example\.com$', | ||
'http_basic' => true, | ||
), | ||
), | ||
)); | ||
|
||
The ``host`` (like the ``pattern``) is a regular expression. In this example, | ||
the firewall will only be activated if the host is equal exactly (due to | ||
the ``^`` and ``$`` regex characters) to the hostname ``admin.example.com``. | ||
If the hostname does not match this pattern, the firewall will not be activated | ||
and subsequent firewalls will have the opportunity to be matched for this | ||
request. | ||
This entry has moved to ":doc:`/cookbook/security/firewall_restriction`". |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Firewall backport #3695
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
Uh oh!
There was an error while loading. Please reload this page.
Firewall backport #3695
Changes from 1 commit
9889dbe
be46c76
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.