Skip to content

Commit

Permalink
Make sure to check redirects before we loop through and parse the host
Browse files Browse the repository at this point in the history
Properly handle no redirects wanted to return success
  • Loading branch information
Seanstoppable committed Aug 19, 2024
1 parent babad09 commit 04c99a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,17 @@ func (c *Client) Do(req *Request) (resp *Response, err error) {
}
return nil, uerr(err)
}
err = c.checkRedirect(req, resp, reqs)

// Sentinel error to let users select the
// previous response, without closing its
// body. See Issue 10069.
if err == ErrUseLastResponse {
return resp, nil
}
if err != nil {
return resp, err
}

var shouldRedirect bool
redirectMethod, shouldRedirect, includeBody = redirectBehavior(req.Method, resp, reqs[0])
Expand Down
6 changes: 5 additions & 1 deletion modules/http/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
// ErrTooManyRedirects is returned when the number of HTTP redirects exceeds
// MaxRedirects.
ErrTooManyRedirects = errors.New("Too many redirects")

ErrDoNotRedirect = errors.New("No redirects configured")
)

// Flags holds the command-line configuration for the HTTP scan module.
Expand Down Expand Up @@ -389,7 +391,7 @@ func redirectsToLocalhost(host string) bool {
func (scan *scan) getCheckRedirect() func(*http.Request, *http.Response, []*http.Request) error {
return func(req *http.Request, res *http.Response, via []*http.Request) error {
if scan.scanner.config.MaxRedirects == 0 {
return nil
return ErrDoNotRedirect
}
if len(via) > scan.scanner.config.MaxRedirects {
return ErrTooManyRedirects
Expand Down Expand Up @@ -531,6 +533,8 @@ func (scan *scan) Grab() *zgrab2.ScanError {
}
if err != nil {
switch err {
case ErrDoNotRedirect:
break
case ErrRedirLocalhost:
break
case ErrTooManyRedirects:
Expand Down

0 comments on commit 04c99a3

Please sign in to comment.