Skip to content

Commit 8bd668e

Browse files
committed
Merge branch '2.4'
Conflicts: book/security.rst
2 parents 2746067 + 4bb11ea commit 8bd668e

23 files changed

+310
-189
lines changed

book/security.rst

+38-72
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ see :doc:`/cookbook/security/form_login`.
661661
),
662662
),
663663
664-
**3. Be sure ``/login_check`` is behind a firewall**
664+
**3. Be sure /login_check is behind a firewall**
665665

666666
Next, make sure that your ``check_path`` URL (e.g. ``/login_check``)
667667
is behind the firewall you're using for your form login (in this example,
@@ -1098,7 +1098,7 @@ Thanks to the SensioFrameworkExtraBundle, you can also secure your controller us
10981098
// ...
10991099
}
11001100

1101-
For more information, see the
1101+
For more information, see the
11021102
:doc:`FrameworkExtraBundle documentation </bundles/SensioFrameworkExtraBundle/annotations/security>`.
11031103

11041104
Securing other Services
@@ -1338,7 +1338,7 @@ in plain text (whether those users are stored in a configuration file or in
13381338
a database somewhere). Of course, in a real application, you'll want to encode
13391339
your users' passwords for security reasons. This is easily accomplished by
13401340
mapping your User class to one of several built-in "encoders". For example,
1341-
to store your users in memory, but obscure their passwords via ``sha1``,
1341+
to store your users in memory, but obscure their passwords via ``bcrypt``,
13421342
do the following:
13431343

13441344
.. configuration-block::
@@ -1352,14 +1352,17 @@ do the following:
13521352
in_memory:
13531353
memory:
13541354
users:
1355-
ryan: { password: bb87a29949f3a1ee0559f8a57357487151281386, roles: 'ROLE_USER' }
1356-
admin: { password: 74913f5cd5f61ec0bcfdb775414c2fb3d161b620, roles: 'ROLE_ADMIN' }
1355+
ryan:
1356+
password: $2a$12$w/aHvnC/XNeDVrrl65b3dept8QcKqpADxUlbraVXXsC03Jam5hvoO
1357+
roles: 'ROLE_USER'
1358+
admin:
1359+
password: $2a$12$HmOsqRDJK0HuMDQ5Fb2.AOLMQHyNHGD0seyjU3lEVusjT72QQEIpW
1360+
roles: 'ROLE_ADMIN'
13571361
13581362
encoders:
13591363
Symfony\Component\Security\Core\User\User:
1360-
algorithm: sha1
1361-
iterations: 1
1362-
encode_as_base64: false
1364+
algorithm: bcrypt
1365+
cost: 12
13631366
13641367
.. code-block:: xml
13651368
@@ -1369,18 +1372,18 @@ do the following:
13691372
<provider name="in_memory">
13701373
<memory>
13711374
<user name="ryan"
1372-
password="bb87a29949f3a1ee0559f8a57357487151281386"
1375+
password="$2a$12$w/aHvnC/XNeDVrrl65b3dept8QcKqpADxUlbraVXXsC03Jam5hvoO"
13731376
roles="ROLE_USER" />
13741377
<user name="admin"
1375-
password="74913f5cd5f61ec0bcfdb775414c2fb3d161b620"
1378+
password="$2a$12$HmOsqRDJK0HuMDQ5Fb2.AOLMQHyNHGD0seyjU3lEVusjT72QQEIpW"
13761379
roles="ROLE_ADMIN" />
13771380
</memory>
13781381
</provider>
13791382
13801383
<encoder class="Symfony\Component\Security\Core\User\User"
1381-
algorithm="sha1"
1382-
iterations="1"
1383-
encode_as_base64="false" />
1384+
algorithm="bcrypt"
1385+
cost="12"
1386+
/>
13841387
</config>
13851388
13861389
.. code-block:: php
@@ -1393,11 +1396,11 @@ do the following:
13931396
'memory' => array(
13941397
'users' => array(
13951398
'ryan' => array(
1396-
'password' => 'bb87a29949f3a1ee0559f8a57357487151281386',
1399+
'password' => '$2a$12$w/aHvnC/XNeDVrrl65b3dept8QcKqpADxUlbraVXXsC03Jam5hvoO',
13971400
'roles' => 'ROLE_USER',
13981401
),
13991402
'admin' => array(
1400-
'password' => '74913f5cd5f61ec0bcfdb775414c2fb3d161b620',
1403+
'password' => '$2a$12$HmOsqRDJK0HuMDQ5Fb2.AOLMQHyNHGD0seyjU3lEVusjT72QQEIpW',
14011404
'roles' => 'ROLE_ADMIN',
14021405
),
14031406
),
@@ -1406,73 +1409,32 @@ do the following:
14061409
),
14071410
'encoders' => array(
14081411
'Symfony\Component\Security\Core\User\User' => array(
1409-
'algorithm' => 'sha1',
1410-
'iterations' => 1,
1411-
'encode_as_base64' => false,
1412+
'algorithm' => 'bcrypt',
1413+
'iterations' => 12,
14121414
),
14131415
),
14141416
));
14151417
1416-
By setting the ``iterations`` to ``1`` and the ``encode_as_base64`` to false,
1417-
the password is simply run through the ``sha1`` algorithm one time and without
1418-
any extra encoding. You can now calculate the hashed password either programmatically
1419-
(e.g. ``hash('sha1', 'ryanpass')``) or via some online tool like `functions-online.com`_
1418+
.. versionadded:: 2.2
1419+
The BCrypt encoder was introduced in Symfony 2.2.
14201420

1421-
.. tip::
1422-
1423-
Supported algorithms for this method depend on your PHP version.
1424-
A full list is available calling the PHP function :phpfunction:`hash_algos`.
1425-
1426-
If you're creating your users dynamically (and storing them in a database),
1427-
you can use even tougher hashing algorithms and then rely on an actual password
1428-
encoder object to help you encode passwords. For example, suppose your User
1429-
object is ``Acme\UserBundle\Entity\User`` (like in the above example). First,
1430-
configure the encoder for that user:
1431-
1432-
.. configuration-block::
1433-
1434-
.. code-block:: yaml
1435-
1436-
# app/config/security.yml
1437-
security:
1438-
# ...
1439-
1440-
encoders:
1441-
Acme\UserBundle\Entity\User: sha512
1442-
1443-
.. code-block:: xml
1421+
You can now calculate the hashed password either programmatically
1422+
(e.g. ``password_hash('ryanpass', PASSWORD_BCRYPT, array('cost' => 12));``)
1423+
or via some online tool.
14441424

1445-
<!-- app/config/security.xml -->
1446-
<config>
1447-
<!-- ... -->
1448-
1449-
<encoder class="Acme\UserBundle\Entity\User" algorithm="sha512" />
1450-
</config>
1425+
.. include:: /cookbook/security/_ircmaxwell_password-compat.rst.inc
14511426

1452-
.. code-block:: php
1453-
1454-
// app/config/security.php
1455-
$container->loadFromExtension('security', array(
1456-
// ...
1457-
'encoders' => array(
1458-
'Acme\UserBundle\Entity\User' => 'sha512',
1459-
),
1460-
));
1461-
1462-
In this case, you're using the stronger ``sha512`` algorithm. Also, since
1463-
you've simply specified the algorithm (``sha512``) as a string, the system
1464-
will default to hashing your password 5000 times in a row and then encoding
1465-
it as base64. In other words, the password has been greatly obfuscated so
1466-
that the hashed password can't be decoded (i.e. you can't determine the password
1467-
from the hashed password).
1427+
Supported algorithms for this method depend on your PHP version. A full list
1428+
is available by calling the PHP function :phpfunction:`hash_algos`.
14681429

14691430
Determining the Hashed Password
14701431
...............................
14711432

1472-
If you have some sort of registration form for users, you'll need to be able
1473-
to determine the hashed password so that you can set it on your user. No
1474-
matter what algorithm you configure for your user object, the hashed password
1475-
can always be determined in the following way from a controller::
1433+
If you're storing users in the database and you have some sort of registration
1434+
form for users, you'll need to be able to determine the hashed password so
1435+
that you can set it on your user before inserting it. No matter what algorithm
1436+
you configure for your user object, the hashed password can always be determined
1437+
in the following way from a controller::
14761438

14771439
$factory = $this->get('security.encoder_factory');
14781440
$user = new Acme\UserBundle\Entity\User();
@@ -1481,6 +1443,10 @@ can always be determined in the following way from a controller::
14811443
$password = $encoder->encodePassword('ryanpass', $user->getSalt());
14821444
$user->setPassword($password);
14831445

1446+
In order for this to work, just make sure that you have the encoder for your
1447+
user class (e.g. ``Acme\UserBundle\Entity\User``) configured under the ``encoders``
1448+
key in ``app/config/security.yml``.
1449+
14841450
.. caution::
14851451

14861452
When you allow a user to submit a plaintext password (e.g. registration
@@ -2157,8 +2123,8 @@ Learn more from the Cookbook
21572123
* :doc:`Blacklist users by IP address with a custom voter </cookbook/security/voters>`
21582124
* :doc:`Access Control Lists (ACLs) </cookbook/security/acl>`
21592125
* :doc:`/cookbook/security/remember_me`
2126+
* :doc:`How to Restrict Firewalls to a Specific Host </cookbook/security/host_restriction>`
21602127

21612128
.. _`FOSUserBundle`: https://github.com./FriendsOfSymfony/FOSUserBundle
21622129
.. _`implement the \Serializable interface`: http://php.net/manual/en/class.serializable.php
2163-
.. _`functions-online.com`: http://www.functions-online.com/sha1.html
21642130
.. _`Timing attack`: http://en.wikipedia.org/wiki/Timing_attack

components/config/introduction.rst

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ The Config component provides several classes to help you find, load, combine,
1212
autofill and validate configuration values of any kind, whatever their source
1313
may be (YAML, XML, INI files, or for instance a database).
1414

15+
.. caution::
16+
17+
The ``IniFileLoader`` parses the file contents using the
18+
:phpfunction:`parse_ini_file` function, therefore, you can only set
19+
parameters to string values. To set parameters to other data types
20+
(e.g. boolean, integer, etc), the other loaders are recommended.
21+
1522
Installation
1623
------------
1724

components/http_foundation/trusting_proxies.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ headers by default. If you are behind a proxy, you should manually whitelist
1515
your proxy.
1616

1717
.. versionadded:: 2.3
18-
CIDR notation support was introduced, so you can whitelist whole
18+
CIDR notation support was introduced in Symfony 2.3, so you can whitelist whole
1919
subnets (e.g. ``10.0.0.0/8``, ``fc00::/7``).
2020

2121
.. code-block:: php

contributing/code/patches.rst

+9-10
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ When your patch is not about a bug fix (when you add a new feature or change
200200
an existing one for instance), it must also include the following:
201201

202202
* An explanation of the changes in the relevant ``CHANGELOG`` file(s) (the
203-
``[BC BREAK]`` or the ``[DEPRECATION]`` prefix must be used when relevant);
203+
``[BC BREAK]`` or the ``[DEPRECATION]`` prefix must be used when relevant);
204204

205205
* An explanation on how to upgrade an existing application in the relevant
206206
``UPGRADE`` file(s) if the changes break backward compatibility or if you
@@ -244,7 +244,7 @@ Check that all tests still pass and push your branch remotely:
244244

245245
.. code-block:: bash
246246
247-
$ git push -f origin BRANCH_NAME
247+
$ git push --force origin BRANCH_NAME
248248
249249
Make a Pull Request
250250
~~~~~~~~~~~~~~~~~~~
@@ -369,11 +369,11 @@ patch. Before re-submitting the patch, rebase with ``upstream/master`` or
369369
.. code-block:: bash
370370
371371
$ git rebase -f upstream/master
372-
$ git push -f origin BRANCH_NAME
372+
$ git push --force origin BRANCH_NAME
373373
374374
.. note::
375375

376-
when doing a ``push --force``, always specify the branch name explicitly
376+
When doing a ``push --force``, always specify the branch name explicitly
377377
to avoid messing other branches in the repo (``--force`` tells Git that
378378
you really want to mess with things so do it carefully).
379379

@@ -383,10 +383,9 @@ convert many commits to one commit. To do this, use the rebase command:
383383
.. code-block:: bash
384384
385385
$ git rebase -i upstream/master
386-
$ git push -f origin BRANCH_NAME
386+
$ git push --force origin BRANCH_NAME
387387
388-
The number 3 here must equal the amount of commits in your branch. After you
389-
type this command, an editor will popup showing a list of commits:
388+
After you type this command, an editor will popup showing a list of commits:
390389

391390
.. code-block:: text
392391
@@ -396,9 +395,9 @@ type this command, an editor will popup showing a list of commits:
396395
397396
To squash all commits into the first one, remove the word ``pick`` before the
398397
second and the last commits, and replace it by the word ``squash`` or just
399-
``s``. When you save, Git will start rebasing, and if successful, will ask
400-
you to edit the commit message, which by default is a listing of the commit
401-
messages of all the commits. When you are finished, execute the push command.
398+
``s``. When you save, Git will start rebasing, and if successful, will ask
399+
you to edit the commit message, which by default is a listing of the commit
400+
messages of all the commits. When you are finished, execute the push command.
402401

403402
.. _ProGit: http://git-scm.com/book
404403
.. _GitHub: https://github.com./signup/free

contributing/documentation/overview.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ tag and a short description:
135135
.. code-block:: text
136136
137137
.. versionadded:: 2.3
138-
The ``askHiddenResponse`` method was added in Symfony 2.3.
138+
The ``askHiddenResponse`` method was introduced in Symfony 2.3.
139139
140140
You can also ask a question and hide the response. This is particularly...
141141

cookbook/doctrine/file_uploads.rst

+9
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ object, which is what's returned after a ``file`` field is submitted::
300300
Using Lifecycle Callbacks
301301
-------------------------
302302

303+
.. caution::
304+
305+
Using lifecycle callbacks is a limited technique that has some drawbacks.
306+
If you want to remove the hardcoded ``__DIR__`` reference inside
307+
the ``Document::getUploadRootDir()`` method, the best way is to start
308+
using explicit :doc:`doctrine listeners </cookbook/doctrine/event_listeners_subscribers>`.
309+
There you will be able to inject kernel parameters such as ``kernel.root_dir``
310+
to be able to build absolute paths.
311+
303312
Even if this implementation works, it suffers from a major flaw: What if there
304313
is a problem when the entity is persisted? The file would have already moved
305314
to its final location even though the entity's ``path`` property didn't

cookbook/routing/service_container_parameters.rst

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ inside your routing configuration:
1818

1919
.. code-block:: yaml
2020
21+
# app/config/routing.yml
2122
contact:
2223
path: /{_locale}/contact
2324
defaults: { _controller: AcmeDemoBundle:Main:contact }
2425
requirements:
25-
_locale: %acme_demo.locales%
26+
_locale: "%acme_demo.locales%"
2627
2728
.. code-block:: xml
2829
30+
<!-- app/config/routing.xml -->
2931
<?xml version="1.0" encoding="UTF-8" ?>
30-
3132
<routes xmlns="http://symfony.com/schema/routing"
3233
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3334
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
@@ -40,6 +41,7 @@ inside your routing configuration:
4041
4142
.. code-block:: php
4243
44+
// app/config/routing.php
4345
use Symfony\Component\Routing\RouteCollection;
4446
use Symfony\Component\Routing\Route;
4547
@@ -82,14 +84,15 @@ path):
8284

8385
.. code-block:: yaml
8486
87+
# app/config/routing.yml
8588
some_route:
8689
path: /%acme_demo.route_prefix%/contact
8790
defaults: { _controller: AcmeDemoBundle:Main:contact }
8891
8992
.. code-block:: xml
9093
94+
<!-- app/config/routing.xml -->
9195
<?xml version="1.0" encoding="UTF-8" ?>
92-
9396
<routes xmlns="http://symfony.com/schema/routing"
9497
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9598
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
@@ -101,6 +104,7 @@ path):
101104
102105
.. code-block:: php
103106
107+
// app/config/routing.php
104108
use Symfony\Component\Routing\RouteCollection;
105109
use Symfony\Component\Routing\Route;
106110
@@ -116,7 +120,7 @@ path):
116120
Just like in normal service container configuration files, if you actually
117121
need a ``%`` in your route, you can escape the percent sign by doubling
118122
it, e.g. ``/score-50%%``, which would resolve to ``/score-50%``.
119-
123+
120124
However, as the ``%`` characters included in any URL are automatically encoded,
121125
the resulting URL of this example would be ``/score-50%25`` (``%25`` is the
122126
result of encoding the ``%`` character).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. caution::
2+
3+
If you're using PHP 5.4 or lower, you'll need to install the ``ircmaxell/password-compat``
4+
library via Composer in order to be able to use the ``bcrypt`` encoder:
5+
6+
.. code-block:: json
7+
8+
{
9+
"require": {
10+
...
11+
"ircmaxell/password-compat": "~1.0.3"
12+
}
13+
}

0 commit comments

Comments
 (0)