Skip to content

Commit b01605b

Browse files
Snawootthinkerou
andauthored
basic auth: fix timing oracle (#2609)
Co-authored-by: thinkerou <[email protected]>
1 parent 46ddd42 commit b01605b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

auth.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package gin
66

77
import (
8+
"crypto/subtle"
89
"encoding/base64"
910
"net/http"
1011
"strconv"
@@ -30,7 +31,7 @@ func (a authPairs) searchCredential(authValue string) (string, bool) {
3031
return "", false
3132
}
3233
for _, pair := range a {
33-
if pair.value == authValue {
34+
if subtle.ConstantTimeCompare([]byte(pair.value), []byte(authValue)) == 1 {
3435
return pair.user, true
3536
}
3637
}

0 commit comments

Comments
 (0)