Skip to content

fix: clear requestRaw and requestHostname on Request.Reset()#1

Open
steps-re wants to merge 1 commit into
vidocsecurity:mainfrom
steps-re:fix/reset-clear-raw-request
Open

fix: clear requestRaw and requestHostname on Request.Reset()#1
steps-re wants to merge 1 commit into
vidocsecurity:mainfrom
steps-re:fix/reset-clear-raw-request

Conversation

@steps-re

@steps-re steps-re commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Request.Reset() does not clear the two fields this fork adds for raw requests, so a Request reused from the sync.Pool can send a stale raw request set by a previous user.

Details

requestRaw and requestHostname implement this fork's core "send a raw HTTP request" feature. Request.Reset() (via resetSkipHeader()) clears body/uri/headers/postArgs but never these two fields. Since ReleaseRequest() calls Reset() and returns the object to a pool, and Request.Write() emits requestRaw verbatim whenever it is non-empty, a recycled Request silently writes the previous user's raw bytes (old method/path/host/body) to the wire. For a request-forging library this is a correctness and safety bug.

Fix

Clear both fields in resetSkipHeader() so every reset path (client pool reuse and server keep-alive reuse) starts clean.

Verification

  • go build ./... clean (Go 1.23).
  • Added regression test rawrequest_reset_test.go: sets a raw request, calls Reset(), builds a normal request on the recycled object, and asserts the stale bytes are not written. Fails without the fix (Reset did not clear requestRaw), passes with it.
  • go test -short suite passes, no regressions.

Request objects are recycled through the request pool (ReleaseRequest ->
Reset -> pool). Reset() did not clear the raw-request fields, so a Request
reused from the pool retained a previously set raw request. Because Write()
emits requestRaw verbatim when it is non-empty, a recycled Request would
send the stale raw bytes instead of the newly built request.

Clear both fields in resetSkipHeader() so all Reset paths (client pool and
server keep-alive reuse) start from a clean state. Adds a regression test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Mike German <mike@stepsventures.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant