Skip to content

Commit

Permalink
Modified storing of redirect response chain to output all redirects a…
Browse files Browse the repository at this point in the history
…nd responses
  • Loading branch information
skraxberger committed Aug 31, 2023
1 parent b14f64a commit e45afdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 7 additions & 3 deletions common/httpx/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ func (r *Response) GetChainStatusCodes() []int {
// GetChain dump the whole redirect chain as string
func (r *Response) GetChain() string {
var respchain strings.Builder
for _, chainItem := range r.Chain {
respchain.Write(chainItem.Request)
respchain.Write(chainItem.Response)
for counter, chainItem := range r.Chain {
if counter != 0 {
respchain.Write(chainItem.Request)
}
if counter < len(r.Chain)-1 {
respchain.Write(chainItem.Response)
}
}
return respchain.String()
}
Expand Down
9 changes: 3 additions & 6 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,18 +1819,15 @@ retry:
respRaw = respRaw[:scanopts.MaxResponseBodySizeToSave]
}
data := append([]byte(fullURL), append([]byte("\n\n"), reqRaw...)...)
if scanopts.StoreChain && resp.HasChain() {
data = append(data, append([]byte("\n"), []byte(resp.GetChain())...)...)
}
data = append(data, append([]byte("\n"), respRaw...)...)
_ = fileutil.CreateFolder(responseBaseDir)
writeErr := os.WriteFile(responsePath, data, 0644)
if writeErr != nil {
gologger.Error().Msgf("Could not write response at path '%s', to disk: %s", responsePath, writeErr)
}
if scanopts.StoreChain && resp.HasChain() {
writeErr := os.WriteFile(responsePath, []byte(resp.GetChain()), 0644)
if writeErr != nil {
gologger.Warning().Msgf("Could not write response at path '%s', to disk: %s", responsePath, writeErr)
}
}
}

parsed, err := r.parseURL(fullURL)
Expand Down

0 comments on commit e45afdf

Please sign in to comment.