Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Security] Added Security\Csrf sub-component with better token generation#6554
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 ourterms of service andprivacy 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.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This method should be removed as it is unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Also if you do need such a method it's already present in Symfony\Component\Security\Core\Util\StringUtils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
which is currently used, if you check the code ;)
mvrhov commentedJan 4, 2013
IMO we do not need cryptographic safe tokens here. |
vicb commentedJan 5, 2013
@mvrhov good catch! This could indeed slow the server pretty badly(I was not aware of the problem until I read a forum post explaining whyAndroid sometimes lags - same root cause) |
webmozart commentedJan 5, 2013
@mvrhov I made the tokens URI safe now. |
vicb commentedJan 7, 2013
Really ? |
padraic commentedJan 7, 2013
@mvrhov You're correct, the randomness need not be very cryptographically secure. The CSRF token is already a sub-unit of a randomly generated session ID though even that has some predictive weaknesses (needs better entropy) due to be improved in PHP 5.4. The options currently in favour are to use openssl_pseudo_random_bytes() under PHP 5.3.4+ or fall back to a (concatenated) token generated using mt_rand(). Neither is, as far as I'm aware, blocking and mt_rand() is better than you'd expect if Suhosin is installed. I think openssl seeds itself using /dev/urandom intelligently (i.e. the non-blocking but lower entropy partner to /dev/random). Only thing you have to watch for is that openssl's random functions were blocking under Windows due to an openssl bug. This was fixed but you should avoid using openssl_pseudo_random_bytes() under PHP 5.3.3 or less and go straight to mt_rand(). CSRF tokens need to be random - just not as crazily random as if we needed a high value long-term key :P. |
webmozart commentedJan 8, 2013
Postponed to 2.3 |
vicb commentedJan 8, 2013
@bschussek I have created a 2.3 milestone, you can set it in the PR header (which I've done for this one). |
webmozart commentedJan 8, 2013
Thanks! :) |
webmozart commentedApr 18, 2013
I'm currently trying to get this into 2.3. I'm not sure which way to go though: (a) As is, plus a new parameter |
webmozart commentedApr 21, 2013
webmozart commentedApr 30, 2013
fabpot commentedMay 6, 2013
I'm for option (c) |
This PR was merged into the master branch.Discussion----------[Security] Split the component into 3 sub-components Core, ACL, HTTP| Q | A| ------------- | ---| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#9047,#8848| License | MIT| Doc PR | -The rationale behind this PR is to be able to use any of the sub components without requiring all the dependencies of the other sub components. Specifically, I'd like to use the core utils for an improved CSRF protection mechanism (#6554).Commits-------14e9f46 [Security] removed unneeded hard dependencies in Core5dbec8a [Security] fixed README files62bda79 [Security] copied the Resources/ directory to Core/Resources/7826781 [Security] Split the component into 3 sub-components Core, ACL, HTTP
webmozart commentedSep 27, 2013
I updated this PR now. I deprecated the old CSRF implementation in the Form component and added a new Security CSRF sub-component with a better implementation that depends on Security Core. See the CHANGELOGs in the diff for more information. I need some feedback regarding the service wiring. |
UPGRADE-3.0.md Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
you should use the FQCN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
wow you're fast ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
fabpot commentedSep 27, 2013
You can also remove |
webmozart commentedSep 27, 2013
I just updated the PR description above for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should be SessionInterface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
stof commentedSep 27, 2013
the root composer.json needs to replace the component too |
…component instead of Form
…dency to the Security CSRF sub-component instead
… new Security CSRF sub-component
webmozart commentedSep 27, 2013
Fixed all mentioned issues. |
webmozart commentedSep 27, 2013
The SecurityBundle currently features the configuration values "csrf_provider" and "intention". Is it possible to add aliases "csrf_token_generator" and "csrf_token_id" for these settings? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You probably should add this also in therequire-dev section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
true because its used in tests. also its missing suggestions for dependency injection, httpfoundation, templating and kernel for all the extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I've added this torequire-dev and added suggestions forsymfony/twig-bridge andsymfony/framework-bundle. I did not add suggestions for dependency injection, HTTP templating or kernel, because the corresponding form extensions don'tadd functionality, but only provide code tointegrate with those components.
Tobion commentedSep 27, 2013
You need to update the require(-dev) sections for all libraries/bundles that use the new CsrfTokenGeneratorInterface to ~2.4, e.g. twigbridge, frameworkbundle, securitybundle. |
webmozart commentedSep 30, 2013
Updated. |
Tobion commentedSep 30, 2013
FrameworkBundle also needs the security for security_csrf.xml. |
webmozart commentedSep 30, 2013
Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
missing@return
Tobion commentedSep 30, 2013
👍 |
…ger and TokenGenerator (bschussek)This PR was merged into the master branch.Discussion----------[Security\Csrf] Split CsrfTokenGenerator into CsrfTokenManager and TokenGenerator| Q | A| ------------- | ---| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#9210| License | MIT| Doc PR | -This is a follow-up PR of#6554 that splits the CsrfTokenGenerator into two separate classes for generating and managing CSRF tokens. As a consequence, it is now possible to explicitly remove or refresh CSRF tokens if they should be used only once. See#9210 for more information.Commits-------d4bb5f4 [Security\Csrf] Split CsrfTokenGenerator into CsrfTokenManager and TokenGenerator
…lfiren, Aaron Valandra, xabbuh)This PR was merged into the 2.7 branch.Discussion----------csrf_token_generator and csrf_token_id documentation| Q | A| ------------- | ---| Doc fix? | no| New docs? | yes (symfony/symfony#6554,symfony/symfony#9587)| Applies to | 2.4+| Fixed tickets |#3059,#5942Commits-------304d7a5 finish csrf_token_generator and csrf_token_id docs3ceb61c Improper markdown for versionadded.91b5e2e Updated documentation as requested by@stof and@xabbuh0044aa2 Updated csrf_in_login_form.rst to include csrf_token_id and csrf_token_generator
…enerator` to `firewalls.logout.csrf_token_manager` (MatTheCat)This PR was merged into the 6.3 branch.Discussion----------[SecurityBundle] Rename `firewalls.logout.csrf_token_generator` to `firewalls.logout.csrf_token_manager`| Q | A| ------------- | ---| Branch? | 6.3| Bug fix? | no| New feature? | no| Deprecations? | yes| Tickets | N/A| License | MIT| Doc PR |symfony/symfony-docs#17482A long time ago,#6554 replaced `CsrfProviderInterface` by `CsrfTokenGeneratorInterface`, and#9216 split the latter into `CsrfTokenManagerInterface` and `TokenGeneratorInterface`.#9587 later introduced `csrf_token_generator`, which was already wrong at the time.Given that token generators exist, it feels weird to have to set <code>csrf_token_**generator**</code> to <code>security.csrf.token_**manager**</code> as mentioned in [the documentation](https://symfony.com/doc/current/reference/configuration/security.html#csrf-token-generator).As this confusion recently led to#48339, I propose to rename `firewalls.logout.csrf_token_generator` to `firewalls.logout.csrf_token_manager`.Commits-------0a0a98a [SecurityBundle] Rename `firewalls.logout.csrf_token_generator` to `firewalls.logout.csrf_token_manager`
Update September 27, 2013
This PR simplifies the CSRF mechanism to generate completely random tokens. A random token is generated once per
intentiontoken ID and then stored in the session. Tokens are valid until the session expires.Since the CSRF token generator depends on
StringUtilsandSecureRandomfrom Security\Core, and since Security\Http currently depends on the Form component for token generation, I decided to add a new Security\Csrf sub-component that contains the improved CSRF token generator. Consequences:In the new Security\Csrf sub-component, I tried to improve the naming where I could do so without breaking BC:
TODO
SecureRandomnever blocks forCsrfTokenGenerator