-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Use constant time string comparison in FormKey validator #13509
Use constant time string comparison in FormKey validator #13509
Conversation
CSRF tokens should be considered sensitive strings. While the risk of a malicious actor attempting gleam the form key via a timing attack is very low, we should still follow best practices in verifying this token.
|
Hi @p0pr0ck5, form key is regenerated each time you enter it incorrectly, isn't it? |
Hey @orlangur, I'm having trouble following the code path to see exactly what's going on under the hood. Even if the key does rotate I would still say this is a good best-practice to implement, no? |
@p0pr0ck5 no, I think. The whole point of attack is to examine one hash multiple times, if the hash is new each time, attack is not possible. Could you please try attack scenario in action:
|
@orlangur I understand what you're saying. Can you highlight where in the code this rotation occurs, for the benefit of my edification? I'm also still struggling to understand the harm this brings- even if the key rotates, why wouldn't this be considered a secure token that should have best practices applied to it? Is it not saner to incorporate a more secure approach simply because it is a more secure approach that hardens the application, and does not bring any ill consequences? |
Honestly, I have no idea about it, will try to play with code and then tell you after I process currently assigned PRs and have some time.
There is no such general approach, it is applicable only to a particular vector of attack. It must not be applied blindly if attack vector is not possible in particular place (otherwise someone would desire to replace any string comparison with such call). |
Hi @p0pr0ck5, after some googling and reading https://www.sjoerdlangkemper.nl/2016/04/21/combining-csrf-with-timing-attacks/ I'm also taking into consideration that as every other framework like Drupal/Symfony/Laravel is comparing CSRF token like this, you're probably not the last person who will report it for Magento :) Please sign our Contributor License Agreement so that this PR can be merged. |
@orlangur thanks for the update. Signed. |
@magento-cicd2 badge still looks yellow to me, I assume it's temporary lag or something. |
Hi @orlangur, thank you for the review. |
Hi @p0pr0ck5. Thank you for your contribution. Please, consider to port this solution to 2.3 release line. |
Description
CSRF tokens should be considered sensitive strings. While the risk of a malicious actor attempting gleam the form key via a timing attack is very low, we should still follow best practices in verifying this token.
Contribution checklist