use ConstantTimeCompare for password comparison (#549)

This commit is contained in:
Fabio Berchtold 2020-11-17 18:45:04 +01:00 committed by GitHub
parent 314d7e7e3f
commit 062dcf6306
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package middleware
import (
"crypto/subtle"
"fmt"
"net/http"
)
@ -16,7 +17,7 @@ func BasicAuth(realm string, creds map[string]string) func(next http.Handler) ht
}
credPass, credUserOk := creds[user]
if !credUserOk || pass != credPass {
if !credUserOk || subtle.ConstantTimeCompare([]byte(pass), []byte(credPass)) != 1 {
basicAuthFailed(w, realm)
return
}