-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 2.3: [#4606] Getting my XML (and PHP) on in the new security chapter [#4606] Tweaks thanks entirely to stof Changing to _ for consistency [#4606] Updating thanks to comments from everyone! Completely re-reading the security book Misc changes [Cookbook] Fix XML example of RTE Conflicts: book/security.rst cookbook/map.rst.inc cookbook/security/index.rst
- Loading branch information
Showing
24 changed files
with
1,832 additions
and
1,697 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ Security | |
firewall | ||
authentication | ||
authorization | ||
secure_tools |
This file contains 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,60 @@ | ||
Securely Comparing Strings and Generating Random Numbers | ||
======================================================== | ||
|
||
The Symfony Security component comes with a collection of nice utilities | ||
related to security. These utilities are used by Symfony, but you should | ||
also use them if you want to solve the problem they address. | ||
|
||
Comparing Strings | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
The time it takes to compare two strings depends on their differences. This | ||
can be used by an attacker when the two strings represent a password for | ||
instance; it is known as a `Timing attack`_. | ||
|
||
Internally, when comparing two passwords, Symfony uses a constant-time | ||
algorithm; you can use the same strategy in your own code thanks to the | ||
:class:`Symfony\\Component\\Security\\Core\\Util\\StringUtils` class:: | ||
|
||
use Symfony\Component\Security\Core\Util\StringUtils; | ||
|
||
// is some known string (e.g. password) equal to some user input? | ||
$bool = StringUtils::equals($knownString, $userInput); | ||
|
||
.. caution:: | ||
|
||
To avoid timing attacks, the known string must be the first argument | ||
and the user-entered string the second. | ||
|
||
Generating a Secure random Number | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Whenever you need to generate a secure random number, you are highly | ||
encouraged to use the Symfony | ||
:class:`Symfony\\Component\\Security\\Core\\Util\\SecureRandom` class:: | ||
|
||
use Symfony\Component\Security\Core\Util\SecureRandom; | ||
|
||
$generator = new SecureRandom(); | ||
$random = $generator->nextBytes(10); | ||
|
||
The | ||
:method:`Symfony\\Component\\Security\\Core\\Util\\SecureRandom::nextBytes` | ||
method returns a random string composed of the number of characters passed as | ||
an argument (10 in the above example). | ||
|
||
The SecureRandom class works better when OpenSSL is installed. But when it's | ||
not available, it falls back to an internal algorithm, which needs a seed file | ||
to work correctly. Just pass a file name to enable it:: | ||
|
||
use Symfony\Component\Security\Core\Util\SecureRandom; | ||
|
||
$generator = new SecureRandom('/some/path/to/store/the/seed.txt'); | ||
$random = $generator->nextBytes(10); | ||
|
||
.. note:: | ||
|
||
If you're using the Symfony Framework, you can access a secure random | ||
instance directly from the container: its name is ``security.secure_random``. | ||
|
||
.. _`Timing attack`: http://en.wikipedia.org/wiki/Timing_attack |
This file contains 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 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 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
Oops, something went wrong.