Skip to content

Commit 5f7ef85

Browse files
committed
feature #4651 Documented the security:check command (javiereguiluz)
This PR was merged into the 2.3 branch. Discussion ---------- Documented the security:check command | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | all | Fixed tickets | #4051 Commits ------- 897dc70 Added a lot of changes suggested by reviewers fdfb1a0 Added a note about the SensioDistributionBundle necessary for security:check 3c9a962 Added a note about the security:check command e552369 Added a missing link reference 0e7d0cd Added a note about the security advisories database 36d3f2b This command is available sin Symfony 2.5 7f3fb71 Documented the security:check command
2 parents 310f4ae + 897dc70 commit 5f7ef85

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

book/installation.rst

+12
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@ them all at once:
287287
Depending on the complexity of your project, this update process can take up to
288288
several minutes to complete.
289289

290+
.. tip::
291+
292+
Symfony provides a command to check whether your project's dependencies
293+
contain any know security vulnerability:
294+
295+
.. code-block:: bash
296+
297+
$ php app/console security:check
298+
299+
A good security practice is to execute this command regularly to be able to
300+
update or replace compromised dependencies as soon as possible.
301+
290302
.. _installing-a-symfony2-distribution:
291303

292304
Installing a Symfony Distribution

book/security.rst

+87
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,92 @@ cookie will be ever created by Symfony):
12281228
If you use a form login, Symfony will create a cookie even if you set
12291229
``stateless`` to ``true``.
12301230

1231+
Utilities
1232+
---------
1233+
1234+
.. versionadded:: 2.2
1235+
The ``StringUtils`` and ``SecureRandom`` classes were introduced in Symfony
1236+
2.2
1237+
1238+
The Symfony Security component comes with a collection of nice utilities related
1239+
to security. These utilities are used by Symfony, but you should also use
1240+
them if you want to solve the problem they address.
1241+
1242+
Comparing Strings
1243+
~~~~~~~~~~~~~~~~~
1244+
1245+
The time it takes to compare two strings depends on their differences. This
1246+
can be used by an attacker when the two strings represent a password for
1247+
instance; it is known as a `Timing attack`_.
1248+
1249+
Internally, when comparing two passwords, Symfony uses a constant-time
1250+
algorithm; you can use the same strategy in your own code thanks to the
1251+
:class:`Symfony\\Component\\Security\\Core\\Util\\StringUtils` class::
1252+
1253+
use Symfony\Component\Security\Core\Util\StringUtils;
1254+
1255+
// is password1 equals to password2?
1256+
$bool = StringUtils::equals($password1, $password2);
1257+
1258+
Generating a secure random Number
1259+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1260+
1261+
Whenever you need to generate a secure random number, you are highly
1262+
encouraged to use the Symfony
1263+
:class:`Symfony\\Component\\Security\\Core\\Util\\SecureRandom` class::
1264+
1265+
use Symfony\Component\Security\Core\Util\SecureRandom;
1266+
1267+
$generator = new SecureRandom();
1268+
$random = $generator->nextBytes(10);
1269+
1270+
The
1271+
:method:`Symfony\\Component\\Security\\Core\\Util\\SecureRandom::nextBytes`
1272+
methods returns a random string composed of the number of characters passed as
1273+
an argument (10 in the above example).
1274+
1275+
The SecureRandom class works better when OpenSSL is installed but when it's
1276+
not available, it falls back to an internal algorithm, which needs a seed file
1277+
to work correctly. Just pass a file name to enable it::
1278+
1279+
$generator = new SecureRandom('/some/path/to/store/the/seed.txt');
1280+
$random = $generator->nextBytes(10);
1281+
1282+
.. note::
1283+
1284+
You can also access a secure random instance directly from the Symfony
1285+
dependency injection container; its name is ``security.secure_random``.
1286+
1287+
.. _book-security-checking-vulnerabilities:
1288+
1289+
Checking for Known Security Vulnerabilities in Dependencies
1290+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1291+
1292+
.. versionadded:: 2.5
1293+
The ``security:check`` command was introduced in Symfony 2.5. This command is
1294+
included in ``SensioDistributionBundle``, which has to be registered in your
1295+
application in order to use this command.
1296+
1297+
When using lots of dependencies in your Symfony projects, some of them may
1298+
contain security vulnerabilities. That's why Symfony includes a command called
1299+
``security:check`` that checks your ``composer.lock`` file to find any known
1300+
security vulnerability in your installed dependencies:
1301+
1302+
.. code-block:: bash
1303+
1304+
$ php app/console security:check
1305+
1306+
A good security practice is to execute this command regularly to be able to
1307+
update or replace compromised dependencies as soon as possible. Internally,
1308+
this command uses the public `security advisories database`_ published by the
1309+
FriendsOfPHP organization.
1310+
1311+
.. tip::
1312+
1313+
The ``security:check`` command terminates with a non-zero exit code if
1314+
any of your dependencies is affected by a known security vulnerability.
1315+
Therefore, you can easily integrate it in your build process.
1316+
12311317
Final Words
12321318
-----------
12331319

@@ -1256,3 +1342,4 @@ Learn more from the Cookbook
12561342

12571343
.. _`online tool`: https://www.dailycred.com/blog/12/bcrypt-calculator
12581344
.. _`frameworkextrabundle documentation`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
1345+
.. _`security advisories database`: https://github.com/FriendsOfPHP/security-advisories

contributing/code/security.rst

+10-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ confirmed, the core-team works on a solution following these steps:
3838
#. Publish the post on the official Symfony `blog`_ (it must also be added to
3939
the "`Security Advisories`_" category);
4040
#. Update the security advisory list (see below).
41+
#. Update the public `security advisories database`_ maintained by the
42+
FriendsOfPHP organization and which is used by the ``security:check`` command.
4143

4244
.. note::
4345

@@ -93,6 +95,11 @@ of the downstream projects included in this process:
9395
Security Advisories
9496
-------------------
9597

98+
.. tip::
99+
100+
You can check your Symfony application for known security vulnerabilities
101+
using the ``security:check`` command. See :doc:`</book/security/checking-vulnerabilities>`
102+
96103
This section indexes security vulnerabilities that were fixed in Symfony
97104
releases, starting from Symfony 1.0.0:
98105

@@ -119,6 +126,7 @@ releases, starting from Symfony 1.0.0:
119126
* March 21, 2008: `symfony 1.0.12 is (finally) out ! <http://symfony.com/blog/symfony-1-0-12-is-finally-out>`_
120127
* June 25, 2007: `symfony 1.0.5 released (security fix) <http://symfony.com/blog/symfony-1-0-5-released-security-fix>`_
121128

122-
.. _Git repository: https://github.com/symfony/symfony
123-
.. _blog: http://symfony.com/blog/
129+
.. _Git repository: https://github.com/symfony/symfony
130+
.. _blog: http://symfony.com/blog/
124131
.. _Security Advisories: http://symfony.com/blog/category/security-advisories
132+
.. _`security advisories database`: https://github.com/FriendsOfPHP/security-advisories

0 commit comments

Comments
 (0)