-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security][SecurityBundle] Add #[IsCsrfTokenValid]
attribute
#52961
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
Conversation
src/Symfony/Component/Security/Http/EventListener/IsCsrfTokenValidAttributeListener.php
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/EventListener/IsCsrfTokenValidAttributeListener.php
Outdated
Show resolved
Hide resolved
c3cc2bb
to
11d7d37
Compare
c48c718
to
fec60e3
Compare
#[IsCsrfTokenValid]
attribute
#[IsCsrfTokenValid]
attribute#[IsCsrfTokenValid]
attribute
src/Symfony/Component/Security/Http/EventListener/IsCsrfTokenValidAttributeListener.php
Outdated
Show resolved
Hide resolved
fec60e3
to
54a7d6f
Compare
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.
Nicely done 👏
I know the name of the proposed attribute is inline with the |
|
@chalasr it's more inline with the |
Sounds valid to me 👍 (I honestly didn't know we had this helper method in the abstract controller) |
@yguedidi Can you have a look at the tests, they seem broken by this PR. |
Let's go with the name then 👍🏻 Thanks for the explanation ℹ️ |
@fabpot Indeed low deps unit tests are broken by this PR! |
You need to bump the minimum version in SecurityBundle. |
54a7d6f
to
a0e1d66
Compare
@fabpot SecurityBundle tests now pass! other failures seems unrelated |
Thank you @yguedidi. |
…sion in `#[IsCsrfTokenValid]` (yguedidi) This PR was merged into the 7.1 branch. Discussion ---------- [Security] Add support for dynamic CSRF id with Expression in `#[IsCsrfTokenValid]` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | continuation of #52961 from Hackday | License | MIT Use case is for example on a list page with delete action per item, and you want a CSRF token per item, so in the template you have something like the following: ```twig {# in a loop over multiple posts #} <form action="{{ path('post_delete', {post: post.id}) }}" method="POST"> <input type="hidden" name="_token" value="{{ csrf_token('delete-post-' ~ post.id) }}"> ... </form> ``` The new feature will allow: ```php #[IsCsrfTokenValid(new Expression('"delete-post-" ~ args["post"].id'))] public function delete(Request $request, Post $post): Response { // ... delete the post } ``` Maybe this need more tests but need help identify which test cases are useful. Hope this can pass before the feature freeze Commits ------- 8f99ca5 Add support for dynamic CSRF id in IsCsrfTokenValid
#SymfonyHackday