Skip to content

Commit

Permalink
Address out of bounds panic on Proxy-Authenticate header
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Dwyer <Brian.Dwyer@broadridge.com>
  • Loading branch information
bdwyertech committed Apr 18, 2020
1 parent fb78529 commit 20a87f0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ntlm_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"net/http"
"net/url"
"strings"

"github.com/alexbrainman/sspi"
"github.com/alexbrainman/sspi/ntlm"
Expand Down Expand Up @@ -70,7 +71,18 @@ func dialNTLM(p Proxy, addr string, baseDial func() (net.Conn, error)) (net.Conn
return conn, errors.New("Unexpected HTTP status code")
}

challenge, err := base64.StdEncoding.DecodeString(resp.Header["Proxy-Authenticate"][0][5:])
challengeHeaders, found := resp.Header["Proxy-Authenticate"]
if !found {
return conn, errors.New("did not receive a challenge from the server")
}
if len(challengeHeaders) != 1 {
return conn, errors.New("received malformed challenge from the server")
}
if len(challengeHeaders[0]) < 6 || !strings.HasPrefix(challengeHeaders[0], "NTLM ") {
return conn, errors.New("received malformed challenge from the server")
}

challenge, err := base64.StdEncoding.DecodeString(challengeHeaders[0][5:])
if err != nil {
debugf("ntlm> Could not read challenge response")
return conn, err
Expand Down

0 comments on commit 20a87f0

Please # to comment.