fix: Use constant-time comparison for Basic auth verification.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
James Read 2026-01-06 22:09:17 +00:00 committed by GitHub
parent f22b3953b1
commit 11278ff6c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 2 deletions

View File

@ -120,10 +120,21 @@ func (v *AuthVerifier) verifyBasic(r *http.Request) bool {
return false return false
} }
import (
"crypto/subtle"
// ... existing imports
)
func (v *AuthVerifier) verifyBasic(r *http.Request) bool {
// ... existing checks ...
parts := strings.SplitN(v.config.Secret, ":", 2) parts := strings.SplitN(v.config.Secret, ":", 2)
if len(parts) == 2 { if len(parts) == 2 {
return username == parts[0] && password == parts[1] usernameMatch := subtle.ConstantTimeCompare([]byte(username), []byte(parts[0]))
passwordMatch := subtle.ConstantTimeCompare([]byte(password), []byte(parts[1]))
return usernameMatch == 1 && passwordMatch == 1
} }
return password == v.config.Secret return subtle.ConstantTimeCompare([]byte(password), []byte(v.config.Secret)) == 1
}
} }