Skip to content

Commit

Permalink
Merge pull request #7 from n1tr0g/master
Browse files Browse the repository at this point in the history
Proper handling of a malformed/bad header data length.
  • Loading branch information
elithrar committed Jan 7, 2015
2 parents ad16386 + dab6fee commit 74459b2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ func (b *basicAuth) authenticate(r *http.Request) bool {
// allowable characters in the password.
creds := bytes.SplitN(str, []byte(":"), 2)

if len(creds) != 2 {
return false
}

// Equalize lengths of supplied and required credentials
// by hashing them
givenUser := sha256.Sum256(creds[0])
givenPass := sha256.Sum256(creds[1])
requiredUser := sha256.Sum256([]byte(b.opts.User))
requiredPass := sha256.Sum256([]byte(b.opts.Password))

if len(creds) != 2 {
return false
}

// Compare the supplied credentials to those set in our options
if subtle.ConstantTimeCompare(givenUser[:], requiredUser[:]) == 1 &&
subtle.ConstantTimeCompare(givenPass[:], requiredPass[:]) == 1 {
Expand Down

0 comments on commit 74459b2

Please sign in to comment.