Skip to content

Commit

Permalink
Merge pull request #55 from BloodHoundAD/fix-bhe-client-transport
Browse files Browse the repository at this point in the history
fix: close request body after computing hash
  • Loading branch information
ddlees authored Oct 12, 2023
2 parents ed2e55e + 8260b84 commit a4a6de5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func (s *rewindableByteReader) Rewind() (int64, error) {
return s.data.Seek(0, io.SeekStart)
}

func discard(reader io.Reader) {
io.Copy(io.Discard, reader)
}

type signingTransport struct {
base http.RoundTripper
tokenId string
Expand Down Expand Up @@ -332,6 +336,10 @@ func (s signingTransport) RoundTrip(req *http.Request) (*http.Response, error) {
tee = io.TeeReader(req.Body, body)
)

defer req.Body.Close()
defer discard(tee)
defer discard(body)

for {
numRead, err := tee.Read(hashBuf)
if numRead > 0 {
Expand Down

0 comments on commit a4a6de5

Please sign in to comment.