Skip to content

[Security\Csrf] Split CsrfTokenGenerator into CsrfTokenManager and TokenGenerator #9216

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

Merged
merged 1 commit into from
Oct 7, 2013

Conversation

webmozart
Copy link
Contributor

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.

if ($csrfTokenManager instanceof CsrfProviderInterface) {
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
Copy link
Member

Choose a reason for hiding this comment

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

you should use FQCN in the message IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, but then it becomes insanely long

@webmozart
Copy link
Contributor Author

Thanks once again @stof for your invaluable feedback. I addressed your comments in the latest commit.

fabpot added a commit that referenced this pull request Oct 7, 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
@fabpot fabpot closed this Oct 7, 2013
@fabpot fabpot merged commit d4bb5f4 into symfony:master Oct 7, 2013
*
* @param string $tokenId The token ID
*
* @return Boolean Returns true if a token existed for this ID, false
Copy link
Contributor

Choose a reason for hiding this comment

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

this does not correspond with the implementation. the implementation calls storage->remove which does not return a boolean but string|null. so either the implementation is wrong or this phpdoc is wrong.

@Tobion Tobion mentioned this pull request Oct 16, 2013
fabpot added a commit that referenced this pull request Oct 17, 2013
This PR was squashed before being merged into the master branch (closes #9311).

Discussion
----------

[Csrf] component fixes

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9216
| License       | MIT
| Doc PR        | -

- [Csrf] fixed some phpdocs
- [Csrf] fixed return types (also #9216 (comment) )
- [Csrf] fixed test class namespaces

Commits
-------

d7eb8ff [Csrf] component fixes
fabpot added a commit that referenced this pull request Jun 7, 2015
…precation (jakzal)

This PR was merged into the 2.7 branch.

Discussion
----------

[FrameworkBundle] Document form.csrf_provider service deprecation

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14899
| License       | MIT
| Doc PR        | -

`form.csrf_provider` was deprecated in #9216.

Commits
-------

0fea66f [FrameworkBundle] Document form.csrf_provider service deprecation
fabpot added a commit that referenced this pull request Dec 22, 2022
…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#17482

A 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants