Skip to content

document how to restrict a firewall to a specific host #2986

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cookbook/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
* :doc:`/cookbook/security/acl`
* :doc:`/cookbook/security/acl_advanced`
* :doc:`/cookbook/security/force_https`
* :doc:`/cookbook/security/host_restriction`
* :doc:`/cookbook/security/form_login`
* :doc:`/cookbook/security/securing_services`
* :doc:`/cookbook/security/custom_provider`
Expand Down
62 changes: 62 additions & 0 deletions cookbook/security/host_restriction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. 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 added in
Symfony 2.4.

When using the Security component, you can create firewalls that match certain
url patterns and thereby restrict access to all urls matching these patterns.
Additionally, you can restrict 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the documentation is using an example admin.example.com so maybe at least mentioning that the firewall will be only active on that domain admin.example.com illutstrates it very explicitly. Also what happens on other domains? the firewall does not apply? does the user need to take care about some security issues?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What security issues do you mean?

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,
),
),
));
1 change: 1 addition & 0 deletions cookbook/security/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Security
acl
acl_advanced
force_https
host_restriction
form_login
securing_services
custom_provider
Expand Down