Open jerbob92 opened 2 years ago
I'm just wondering now if the padding loop in Sprintf also might allow for a timing attack. It's probably less vulnerable than subtle.ConstantTimeCompare
, but it's still looping for one of the strings to make it equal length.
Maybe hashing is the better way after all?
is it a better suggestion to golang crypto package method ConstantTimeCompare?
There have been various discussions about that, for example here: https://github.com/golang/go/issues/18936 It doesn't really look like they want to change it.
Description
In #2226 and #2609 a fix was discussed and made to prevent timing attacks on the basic auth logic of Gin. However, this was only partly fixed. The decision was made to use
subtle.ConstantTimeCompare
, however, that has quite a big flaw that it immediately returns when the length of the 2 strings is not equal, which still allows it to be used for timing attacks to guess how long the password should be.There are basically 2 ways to fix this:
In a personal project I decided to go for option 2, which looks like this: