mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-27 03:21:09 +01:00
fix(auth): reorder password validation to enhance security against timing attacks
- Always perform bcrypt comparison before checking the username to mitigate potential timing attack vulnerabilities.
This commit is contained in:
@@ -137,11 +137,12 @@ func (auth *UserPassAuth) LogoutHandler(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func (auth *UserPassAuth) validatePassword(user, pass string) error {
|
||||
if user != auth.username {
|
||||
return ErrInvalidUsername
|
||||
}
|
||||
// always perform bcrypt comparison to avoid timing attacks
|
||||
if err := bcrypt.CompareHashAndPassword(auth.pwdHash, []byte(pass)); err != nil {
|
||||
return err
|
||||
}
|
||||
if user != auth.username {
|
||||
return ErrInvalidUsername
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user