Skip to content

Commit

Permalink
Prevent timing attack on usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
akrantz01 committed Jun 4, 2021
1 parent 46f3b36 commit f8f2cad
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plugins/common/auth/basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func (b *BasicAuth) Verify(r *http.Request) bool {
}

username, password, ok := r.BasicAuth()
return ok &&
subtle.ConstantTimeCompare([]byte(username), []byte(b.Username)) == 1 &&
subtle.ConstantTimeCompare([]byte(password), []byte(b.Password)) == 1

usernameComparison := subtle.ConstantTimeCompare([]byte(username), []byte(b.Username)) == 1
passwordComparison := subtle.ConstantTimeCompare([]byte(password), []byte(b.Password)) == 1
return ok && usernameComparison && passwordComparison
}

0 comments on commit f8f2cad

Please sign in to comment.