-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Security] Add $tokenSource argument to #[IsCsrfTokenValid] to support reading tokens from the query string or headers
#61694
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
[Security] Add $tokenSource argument to #[IsCsrfTokenValid] to support reading tokens from the query string or headers
#61694
Conversation
|
Reading it from cookies is a bad idea, as the security of the CSRF protection has never been evaluated for such usage, which is a totally different behavior (a cookie could be submitted based on a stored value rather than a value submitted as part of the request, which has to be known by the attacker submitting the request) |
|
I'd rather make this explicit using an option on the attribute. Fishing for security values is calling for troubles :) |
A simple improvement could be to allow But the naming |
|
we could use a bitfield - that'd prevent everybody needed this from figuring out the correct expression (there's only a very limited way of reading that token - and we even don't want to open for things like cookies): |
43c46e8 to
2119ddc
Compare
src/Symfony/Component/Security/Http/EventListener/IsCsrfTokenValidAttributeListener.php
Outdated
Show resolved
Hide resolved
#[IsCsrfTokenValid]$tokenSource argument to #[IsCsrfTokenValid]
src/Symfony/Component/Security/Http/EventListener/IsCsrfTokenValidAttributeListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/Attribute/IsCsrfTokenValid.php
Outdated
Show resolved
Hide resolved
b545acb to
0ddd4e6
Compare
src/Symfony/Component/Security/Http/Attribute/IsCsrfTokenValid.php
Outdated
Show resolved
Hide resolved
| $sources = [ | ||
| IsCsrfTokenValid::SOURCE_PAYLOAD => static fn () => $request->getPayload()->get($tokenKey), | ||
| IsCsrfTokenValid::SOURCE_QUERY => static fn () => $request->query->get($tokenKey), | ||
| IsCsrfTokenValid::SOURCE_HEADER => static fn () => $request->headers->get($tokenKey), |
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.
Would we really expect the header name to be _token like payload fields ?
If the name cannot be common, we cannot really support a bitfield IMO.
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 think we can yes, that'd be just a custom header. Ppl that want something else can always do it the procedural way I'd say
src/Symfony/Component/Security/Http/EventListener/IsCsrfTokenValidAttributeListener.php
Outdated
Show resolved
Hide resolved
075183a to
ec51c23
Compare
$tokenSource argument to #[IsCsrfTokenValid]$tokenSource argument to #[IsCsrfTokenValid] to support reading tokens from the query string or headers
…pport reading tokens from the query string or headers
ec51c23 to
3a36435
Compare
|
Thank you @webda2l. |
The IsCsrfTokenValid attribute currently only reads the token value from the request payload, which is somewhat restrictive. This PR add the ability to choose more sources.