Repository navigation
Conversation
handleWebSocket propagated a half-close only for *net.TCPConn. In MITM mode both legs are *tls.Conn, so when the client went away the upstream was never told: the session, and the audit record emitted when it ends, waited for the upstream's idle timeout, and was lost if the proxy stopped first. Half-close any connection that supports CloseWrite (*tls.Conn sends close_notify); close one that does not. Fixes paradigmxyz#272 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
#244 would also fix this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #272.
handleWebSocketpasses a half-close on to the other leg only when the connection is a*net.TCPConn. In MITM mode both legs are*tls.Conn, so when the client goes away the upstream is never told: the client→upstream copy ends, but the upstream→client copy keeps waiting until the upstream's idle timeout.wg.Wait(), and with it the deferredEmitAudit, waits just as long, and the record is lost if the proxy stops first.This change half-closes any connection that implements
CloseWrite() error(*tls.Connsendsclose_notify,*net.TCPConnshuts down its write side) and closes one that doesn't, so a session can no longer outlive both of its peers.Test:
TestCloseWriteininternal/proxy/proxy_test.gocovers both cases: a TLS pair, where the peer must see EOF while the reply in the other direction still arrives, and anet.Pipeconnection, which has no half-close and is closed. The TLS case fails with the previous*net.TCPConncheck.go vet ./...andgo test ./...pass.End to end (tunnel listener,
mitm, linux/arm64, v0.52.0 with this patch), against an upstream that keeps a WebSocket open until the client leaves, as most services do:status_code: 101).Against
wss://chatgpt.com/backend-api/codex/responses(Codex), sessions that were missing from the audit log now appear asGET /backend-api/codex/responses 101.🤖 Generated with Claude Code