From dd1621c0077e079e0693f16fe83f17d50338216e Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Fri, 15 May 2026 19:48:00 +0200 Subject: Stop mislabeling truncated captures as "exact" internal/proxy/tee.go's teeConn silently drops bytes past maxCaptureBytes (10 MiB) but callers unconditionally marked the result "exact" anyway. Confirmed live: proxying a 15 MiB response worked correctly end-to-end (the client got the full, real 15 MiB - proxying itself is unbounded, only storage is capped), but the stored history entry was exactly 10485760 bytes with response_exact=1 still set. For a tool whose core value proposition is "raw bytes are the source of truth," a silently truncated capture presented as complete could hide the very evidence a smuggling or parser-differential investigation is looking for in the tail of a large body - and give false confidence that it isn't there. teeConn.Take() now returns (data, truncated) instead of just data; truncated is true whenever a Read had to drop bytes because the buffer was already at cap. Every caller (proxy.go's forward() on both the request and response side, repeat.go's sendRaw for Repeater/Intruder) now folds truncated into exact - a truncated capture is never marked exact - and additionally threads a distinct RequestTruncated/ ResponseTruncated bool through store.Entry, ipc.EntryDetail, and the TUI, since "truncated" and "reconstructed" (HTTP/2, which never had wire-exact bytes to begin with) are different situations worth telling apart: a truncated capture is still real wire bytes, just incomplete, not a synthesized reconstruction. The detail/repeater views now show "truncated (hit capture size limit)" specifically rather than lumping it in with "reconstructed", which would have implied more transformation happened than actually did. Schema: history gains request_truncated/response_truncated columns via the same ALTER-TABLE-and-ignore-duplicate-column pattern already used for source/flagged, so existing databases upgrade in place. Verified live: a target server returning a 15 MiB body (over the 10 MiB cap) proxied through cleanly - full body reached the client - while the stored entry shows length=10485760, response_exact=0, response_truncated=1 (previously would have shown response_exact=1); the TUI's Detail view correctly displays "Response (10485760 bytes, truncated (hit capture size limit))" instead of "exact". go build/vet/gofmt/test/mod tidy all clean. --- internal/proxy/capture.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'internal/proxy/capture.go') diff --git a/internal/proxy/capture.go b/internal/proxy/capture.go index ec4dc8d..3902e5c 100644 --- a/internal/proxy/capture.go +++ b/internal/proxy/capture.go @@ -36,12 +36,19 @@ func (c *cappedTee) Read(p []byte) (int, error) { // captureRequest returns the raw bytes of r for storage. When tee is // non-nil (an HTTP/1.1 client connection), the bytes are exactly what -// was read off the wire. Otherwise (HTTP/2, which has no single "raw -// bytes" representation - it's multiplexed, HPACK-compressed framing) -// it's a reconstruction from the parsed request, exact=false. -func captureRequest(r *http.Request, tee *teeConn, bodyCap *cappedTee) (raw []byte, exact bool) { +// was read off the wire, unless truncated hits maxCaptureBytes and has +// to drop bytes off the end - still real wire bytes, just incomplete, +// which is a different (and less severe) kind of "not exact" than the +// HTTP/2 case below and worth telling apart in the UI (see +// store.Entry's *Truncated fields). Otherwise (HTTP/2, which has no +// single "raw bytes" representation - it's multiplexed, HPACK- +// compressed framing) it's a reconstruction from the parsed request, +// exact=false, truncated=false (truncated only applies to a would-be- +// exact capture). +func captureRequest(r *http.Request, tee *teeConn, bodyCap *cappedTee) (raw []byte, exact, truncated bool) { if tee != nil { - return tee.Take(), true + data, truncated := tee.Take() + return data, !truncated, truncated } dump := r.Clone(r.Context()) @@ -54,9 +61,9 @@ func captureRequest(r *http.Request, tee *teeConn, bodyCap *cappedTee) (raw []by } var buf bytes.Buffer if err := dump.Write(&buf); err != nil { - return nil, false + return nil, false, false } - return buf.Bytes(), false + return buf.Bytes(), false, false } // captureResponse reconstructs raw response bytes from the parsed -- cgit v1.2.3