-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Security] Add tokenSource
parameter for CSRF token validation sources
#21363
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,27 @@ array, the attribute is ignored for that request, and no CSRF validation occurs: | |
// ... delete the object | ||
} | ||
|
||
You can also choose where the CSRF token is read from using the ``tokenSource`` parameter | ||
This is a bitfield allowing you to combine these sources: | ||
|
||
* ``IsCsrfTokenValid::SOURCE_PAYLOAD`` (default): request payload (POST body / json) | ||
* ``IsCsrfTokenValid::SOURCE_QUERY``: query string | ||
* ``IsCsrfTokenValid::SOURCE_HEADER``: request headers | ||
|
||
Example:: | ||
|
||
#[IsCsrfTokenValid( | ||
'delete-item', | ||
tokenKey: 'token', | ||
tokenSource: IsCsrfTokenValid::SOURCE_PAYLOAD | IsCsrfTokenValid::SOURCE_QUERY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion, but perhaps overkill Document one simple source and one with combination? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it "as is" because I think it's simple enough to understand it. Thanks. |
||
)] | ||
public function delete(Post $post): Response | ||
{ | ||
// ... delete the object | ||
} | ||
|
||
The token will be checked in each selected source, and validation fails if none match. | ||
|
||
.. versionadded:: 7.1 | ||
|
||
The :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsCsrfTokenValid` | ||
|
@@ -330,6 +351,10 @@ array, the attribute is ignored for that request, and no CSRF validation occurs: | |
|
||
The ``methods`` parameter was introduced in Symfony 7.3. | ||
|
||
.. versionadded:: 7.4 | ||
|
||
The ``tokenSource`` parameter was introduced in Symfony 7.4. | ||
|
||
CSRF Tokens and Compression Side-Channel Attacks | ||
------------------------------------------------ | ||
|
||
|
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.
As it checks only one no?
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.
Yes. Fixed while merging. Thanks!