Skip to content

Commit 56b6d42

Browse files
dwisiswant0zzyjsj
andauthored
fix(http): lost request body on retries & redirects (#6666)
* fix(http): lost request body on retries & redirects Updates the HTTP protocol to use `(*retryablehttp.Request).SetBodyString` instead of direct `Body` assignment. This fixes #6665 where the request body was dropped during retries or 307/308 redirects because `GetBody` was not being populated. Thanks to @zzyjsj for reporting the bug in the upstream dependency and the hints! Signed-off-by: Dwi Siswanto <[email protected]> * empty: add co-author Co-authored-by: zzy <[email protected]> Signed-off-by: Dwi Siswanto <[email protected]> --------- Signed-off-by: Dwi Siswanto <[email protected]> Co-authored-by: zzy <[email protected]>
1 parent 2c46f2c commit 56b6d42

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/projectdiscovery/interactsh v1.2.4
2828
github.com/projectdiscovery/rawhttp v0.1.90
2929
github.com/projectdiscovery/retryabledns v1.0.110
30-
github.com/projectdiscovery/retryablehttp-go v1.0.133
30+
github.com/projectdiscovery/retryablehttp-go v1.1.0
3131
github.com/projectdiscovery/yamldoc-go v1.0.6
3232
github.com/remeh/sizedwaitgroup v1.0.0
3333
github.com/rs/xid v1.6.0
@@ -270,7 +270,7 @@ require (
270270
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 // indirect
271271
github.com/kataras/jwt v0.1.10 // indirect
272272
github.com/kevinburke/ssh_config v1.2.0 // indirect
273-
github.com/klauspost/compress v1.18.1 // indirect
273+
github.com/klauspost/compress v1.18.2 // indirect
274274
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
275275
github.com/klauspost/pgzip v1.2.6 // indirect
276276
github.com/kylelemons/godebug v1.1.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ github.com/kitabisa/go-ci v1.0.3/go.mod h1:e3wBSzaJbcifXrr/Gw2ZBLn44MmeqP5WySwXy
645645
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
646646
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
647647
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
648+
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
649+
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
648650
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
649651
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
650652
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
@@ -875,6 +877,8 @@ github.com/projectdiscovery/retryabledns v1.0.110 h1:24p1PzWBdfsRnGsBf6ZxXPzvK0s
875877
github.com/projectdiscovery/retryabledns v1.0.110/go.mod h1:GFj5HjxfaGrZeoYf79zI/R99XljBNjmOqNvwOqPepRU=
876878
github.com/projectdiscovery/retryablehttp-go v1.0.133 h1:uAIGwsRelrS1Ulelyp9qLtZRDTFHixw4O0cUQWLhTJQ=
877879
github.com/projectdiscovery/retryablehttp-go v1.0.133/go.mod h1:9DU57ezv5cfZSWw/m5XFDTMjy1yKeMyn1kj35lPlcfM=
880+
github.com/projectdiscovery/retryablehttp-go v1.1.0 h1:uYp3EnuhhamTwvG41X6q6TAc/SHEO9pw9CBWbRASIQk=
881+
github.com/projectdiscovery/retryablehttp-go v1.1.0/go.mod h1:9DU57ezv5cfZSWw/m5XFDTMjy1yKeMyn1kj35lPlcfM=
878882
github.com/projectdiscovery/sarif v0.0.1 h1:C2Tyj0SGOKbCLgHrx83vaE6YkzXEVrMXYRGLkKCr/us=
879883
github.com/projectdiscovery/sarif v0.0.1/go.mod h1:cEYlDu8amcPf6b9dSakcz2nNnJsoz4aR6peERwV+wuQ=
880884
github.com/projectdiscovery/stringsutil v0.0.2 h1:uzmw3IVLJSMW1kEg8eCStG/cGbYYZAja8BH3LqqJXMA=

pkg/protocols/http/build_request.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/projectdiscovery/rawhttp"
2929
"github.com/projectdiscovery/retryablehttp-go"
3030
"github.com/projectdiscovery/utils/errkit"
31-
readerutil "github.com/projectdiscovery/utils/reader"
3231
stringsutil "github.com/projectdiscovery/utils/strings"
3332
urlutil "github.com/projectdiscovery/utils/url"
3433
)
@@ -466,11 +465,9 @@ func (r *requestGenerator) fillRequest(req *retryablehttp.Request, values map[st
466465
if err != nil {
467466
return nil, errkit.Wrap(err, "could not evaluate helper expressions")
468467
}
469-
bodyReader, err := readerutil.NewReusableReadCloser([]byte(body))
470-
if err != nil {
471-
return nil, errors.Wrap(err, "failed to create reusable reader for request body")
468+
if err := req.SetBodyString(body); err != nil {
469+
return nil, errors.Wrap(err, "failed to set request body")
472470
}
473-
req.Body = bodyReader
474471
}
475472
if !r.request.Unsafe {
476473
userAgent := useragent.PickRandom()

0 commit comments

Comments
 (0)