-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[form] use the same csrf token id for all forms by default #18115
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
Comments
What if I opened two browser tabs, Tab A and Tab B (two separate forms)? I submit the form on Tab A, now when I go to submit form B I get a CSRF validation error. I feel like UX might suffer if this was implemented as a global change. |
form submission doesnt invalidate the token. the same token per form and session is used, but it would suffice to use only one token for any form per session. |
a small proposal on how this can be achieved:
|
OWASP says that per request tokens are the most secure: https://www.owasp.org/index.php/CSRF_Prevention_Cheat_Sheet
|
well they also mention the caveats after your quoted part. but symfony doesnt use per-request tokens, but per-form tokens. |
@backbone87 Sounds like an elegant and simple solution to me. You'd need to use two different CSRF tokens though: one for HTTP requests (stored in normal cookie - could be sniffed by MITM) and one for HTTPS requests (stored in a HTTPS-only cookie - not sniffable). I think it should be possible to implement this as new implementation of |
i have created a new ticket for the double submit cookies, as the issue here deals with another problem not directly related to the security-csrf component, but the application of the component within the form csrf extension. since the DSC feature can only be merged into symfony 3 (?), it would be nice to have a fix for this issue, that could be merged into symfony 2 the problem is in the following line: Would a change to |
@backbone87 Using the same token would pose a security threat in mixed HTTP/HTTPS environments. It's easy to sniff the CSRF token of a HTTP form. The attacker would consequently be able to use the same token for a HTTPS form. At the moment, the number of tokens in the session is limited by the number of forms you have, so this functionality does not bear the potential to bring down the server. If you have too many forms in your application and want to reduce the size of your session, I suggest to use custom IDs or type extension - but take care of the HTTP/HTTPS attack vector described above. Once we implement DSC, the CSRF token ID becomes obsolete anyway. I don't think there's anything we should do here. |
that reasoning is weird. we dont use different token IDs based on protocol currently, but based on form name/type name. if i use the same form, one on https and one on http, you have the same security issue. |
@backbone87 has a valid point IMO. |
Since #24992 different protocols do not share the same tokens anymore. So I think we can close here as using the same token ID for all forms can easily be done in a custom extension if really needed. |
currently each form uses a separate csrf token id (based on the forms name or its type's class name). as far as i understand, this doesnt provide much more safety than using the same token id for all forms (or for the whole app). the major problem is with long living sessions and a potential access to many different forms, causing the session to get spammed with tokens.
i know this can be solved with a custom form type extension that fixes the token id to a globally configured value.
but i opened this issue to confirm my assumption, that the security impact is minimal, when using a single token, and if thats the case, changing it in the core would be a nice little performance tweak (a medium sized application can easily generate up to 100 different forms on a few dozen page loads).
The text was updated successfully, but these errors were encountered: