Skip to content

Commit cf3b5bf

Browse files
authored
fix: body loss on retries/redirects in remaining paths (#6693)
Continue the fix from #6666 by converting remaining direct Body assignments to use setter methods: * pkg/fuzz/component/body.go:139: use `SetBodyReader()` in transfer-encoding path. * pkg/protocols/http/request.go:694: use `SetBodyString()` in fuzz component `Rebuild()`. Fixes #6692. Signed-off-by: Dwi Siswanto <git@dw1.io>
1 parent b63a23b commit cf3b5bf

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

pkg/fuzz/component/body.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/projectdiscovery/gologger"
1212
"github.com/projectdiscovery/nuclei/v3/pkg/fuzz/dataformat"
1313
"github.com/projectdiscovery/retryablehttp-go"
14-
readerutil "github.com/projectdiscovery/utils/reader"
1514
)
1615

1716
// Body is a component for a request body
@@ -132,12 +131,10 @@ func (b *Body) Rebuild() (*retryablehttp.Request, error) {
132131
return nil, errors.Wrap(err, "could not encode body")
133132
}
134133
cloned := b.req.Clone(context.Background())
135-
reusableReader, err := readerutil.NewReusableReadCloser(encoded)
134+
err = cloned.SetBodyString(encoded)
136135
if err != nil {
137-
return nil, errors.Wrap(err, "could not create reusable reader")
136+
return nil, errors.Wrap(err, "could not set body")
138137
}
139-
cloned.Body = reusableReader
140-
cloned.ContentLength = int64(len(encoded))
141138
cloned.Header.Set("Content-Length", strconv.Itoa(len(encoded)))
142139
return cloned, nil
143140
}

pkg/protocols/http/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ func (request *Request) executeRequest(input *contextargs.Context, generatedRequ
691691
}
692692
if err == nil {
693693
// update the request body with the reusable reader
694-
generatedRequest.request.Body = newReqBody
694+
generatedRequest.request.SetBodyReader(newReqBody)
695695
// get content length
696696
length, _ := io.Copy(io.Discard, newReqBody)
697697
generatedRequest.request.ContentLength = length

0 commit comments

Comments
 (0)