Skip to content

Commit 347ab14

Browse files
Fixes a few issues with redirects (#462)
Cherry-pick: 8981417 * Fixes a few issues with redirects First, this prevents a DNS lookup from happening when we encounter a redirect, *even if we don't intend to follow it*. This likely addresses some part of #452 Second, if we aren't following redirects, don't have the scan fail in an 'application-error'. We are succeeding in what we intended to do, which is to scan without following redirects * Make sure to check redirects before we loop through and parse the host Properly handle no redirects wanted to return success * Handle 0 indexing * Pull out the original checkRedirectCode so we deal with consistently * lint * add redirect fix to ipp module --------- Co-authored-by: Phillip Stephens <phillip@cs.stanford.edu> Co-authored-by: Zakir Durumeric <zakird@gmail.com>
1 parent 8cfb9f5 commit 347ab14

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/http/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,9 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) {
637637
for {
638638
// For all but the first request, create the next
639639
// request hop and replace req.
640+
loc := req.URL.String()
640641
if len(reqs) > 0 {
641-
loc := resp.Header.Get("Location")
642+
loc = resp.Header.Get("Location")
642643
if loc == "" {
643644
// While most 3xx responses include a Location, it is not
644645
// required and 3xx responses without a Location have been

modules/http/scanner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ func (scan *scan) getCheckRedirect() func(*http.Request, *http.Response, []*http
316316
if len(via)-1 > scan.scanner.config.MaxRedirects {
317317
return ErrTooManyRedirects
318318
}
319+
if !scan.scanner.config.FollowLocalhostRedirects && redirectsToLocalhost(req.URL.Hostname()) {
320+
return ErrRedirLocalhost
321+
}
319322
// We're following a re-direct. The IP that the framework resolved initially is no longer valid. Clearing
320323
scan.target.IP = nil
321324
scan.results.RedirectResponseChain = append(scan.results.RedirectResponseChain, res)

0 commit comments

Comments
 (0)