Treat an expired passthrough mark as intercepted again, and say what the window costs.

Replay was still honoring a stale bypass, and a host whose interception always fails now loses one request per minute instead of one per process.
This commit is contained in:
protonmatter
2026-11-17 15:58:24 -05:00
parent 08eb4ec244
commit 287cbb685c
3 changed files with 20 additions and 7 deletions
+1 -2
View File
@@ -86,8 +86,7 @@ func (t *Traffic) replayRecorded(scheme, host string) bool {
if scheme != "https" {
return true
}
_, tunneled := t.pass.Load(hostOnly(host))
return !tunneled
return !t.tunneling(hostOnly(host))
}
func replayInvalid(format string, args ...any) error {
+10 -2
View File
@@ -199,7 +199,10 @@ func TestReplayPassthroughHostIsNotIntercepted(t *testing.T) {
tr, _, _ := startProxy(t)
srv := httptest.NewTLSServer(http.HandlerFunc(echoHandler))
t.Cleanup(srv.Close)
tr.pass.Store("localhost", struct{}{})
tr.pass.Store("localhost", time.Now().Add(passthroughTTL))
if !tr.tunneling("localhost") {
t.Fatal("passthrough mark was not recognized before the replay")
}
target := localhostURL(srv.URL) + "/tunneled"
_, err := tr.Replay(t.Context(), ReplayRequest{Method: "GET", URL: target})
if err == nil || !strings.Contains(err.Error(), "certificate") {
@@ -249,7 +252,11 @@ func TestReplayRejectsInvalidRequests(t *testing.T) {
// Only an https host in passthrough is reported as not recorded.
func TestReplayRecordedHelper(t *testing.T) {
tr := &Traffic{}
tr.pass.Store("localhost", struct{}{})
tr.pass.Store("localhost", time.Now().Add(passthroughTTL))
if !tr.tunneling("localhost") {
t.Fatal("fresh passthrough mark was not tunneling")
}
tr.pass.Store("expired.example", time.Now().Add(-time.Second))
for _, c := range []struct {
scheme, host string
want bool
@@ -257,6 +264,7 @@ func TestReplayRecordedHelper(t *testing.T) {
{"https", "localhost:443", false},
{"https", "example.com:443", true},
{"http", "localhost:80", true},
{"https", "expired.example:443", true},
} {
if got := tr.replayRecorded(c.scheme, c.host); got != c.want {
t.Errorf("replayRecorded(%s, %s) = %v, want %v", c.scheme, c.host, got, c.want)
+9 -3
View File
@@ -439,8 +439,10 @@ func (s *sink) Response(f *mproxy.Flow) {
// RequestError fires when a request through an established MITM tunnel fails. If
// the failure looks proxy/protocol-caused (h2 quirks, HEAD-with-body, protocol
// errors) — not a plain target-unreachable error — we flag the host for
// transparent passthrough so future requests to it succeed instead of dying.
// errors) and not a plain target-unreachable error, the host is tunneled for
// passthroughTTL. This request has already failed. Later requests in the window
// connect straight through; the first request after the window tries
// interception again.
func (s *sink) RequestError(f *mproxy.Flow, err error) { s.t.maybePassthrough(f, err) }
// maybePassthrough marks a host to be tunneled transparently on the next
@@ -459,10 +461,14 @@ func (t *Traffic) maybePassthrough(f *mproxy.Flow, err error) {
}
until := time.Now().Add(passthroughTTL)
if _, loaded := t.pass.LoadOrStore(host, until); !loaded {
log.Printf("[traffic] MITM with %s failed, falling back to passthrough for %s (this host connects straight to the target and is not recorded until then; requests still proceed): %v", host, passthroughTTL, err)
log.Printf("[traffic] MITM with %s failed, falling back to passthrough for %s (this request failed; the host connects straight to the target and is not recorded until then; the first request after the window fails again if interception still cannot handle it): %v", host, passthroughTTL, err)
}
}
// passthroughTTL is how long a host stays tunneled after a proxy-caused MITM
// failure. A host whose interception always fails pays one lost request per
// window: one per host per minute, where a mark that never expired cost one
// per process. The window is what lets a stale bypass end.
const passthroughTTL = time.Minute
// tunneling reports whether host is inside an unexpired passthrough mark.