Skip to content

feat(traffic): pace Bash requests at the capture proxy - #234

Merged
BaaRai merged 2 commits into
mainfrom
feat/proxy-pace-bash
Nov 15, 2026
Merged

BaaRai merged 2 commits into
mainfrom
feat/proxy-pace-bash

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 3b: with traffic capture on, the recording proxy paces the requests that Bash commands send through it, by the current noise profile. A request is never paced twice, the marker never reaches a target, and recording keeps working. Capture off is out of scope.

Checkpoint (run before the feature)

The design relies on three properties of go-mitmproxy v1.9.2. A test with a real traffic.Open proxy and a curl-like client (proxy URL with userinfo, CA trusted) confirmed all three before any feature code was written:

  • (a) The proxy URL's userinfo, sent as Proxy-Authorization, is visible in Requestheaders on the CONNECT and on a plain-HTTP GET.
  • (b) The requests inside one MITM tunnel carry the CONNECT's ClientConn.Id.
  • (c) Without stripping, the plain-HTTP target received Proxy-Authorization. With Header.Del in Requestheaders, no target received it. Inner TLS requests never carry it.

Design

  • Marker: proxyEnv puts the userinfo artex-pace:artex-pace (egress.MarkProxyURL) in the Bash proxy URL, only when a MITM CA is present (capture on). The global proxy of the capture-off path is unchanged. WebFetch, the http custom tools and enrich keep the plain URL.
  • Proxy (traffic/pace.go), in Requestheaders:
    • it drops Proxy-Authorization from every request before anything is forwarded or recorded; the recording proxy takes no credentials;
    • when the value is the marker (egress.IsPaceMarker), it marks the ClientConn.Id;
    • every later non-CONNECT request on a marked connection is paced before it goes upstream; this includes the requests inside the CONNECT tunnel;
    • ClientDisconnected removes the mark.
  • Pacing (egress.Wait):
    • it uses the same per-host token bucket and jitter as a governed request, and counts the request in the host's noise counter (shown on the Target noise card);
    • it takes no in-flight slot, and there is no cache, coalescing, retry or backoff at the proxy;
    • off is a no-op, and a profile change applies to the next request;
    • the wait is bounded at 30 s, and by the request's own context; past that, the request is logged and sent unpaced, never blocked indefinitely.
  • No double pacing: unmarked connections are not paced at the proxy, because egress already paces them.

Limitations (also in the README and on the card)

  • Only clients that honour the proxy are covered (curl, wget, python-requests…), not raw scanners such as nmap.
  • Capture must be on.
  • A command that drops the marker or bypasses the proxy (--noproxy, an unset variable) is not paced.
  • Hosts the proxy has switched to passthrough after a failed interception are tunnelled without visible requests, so they are not paced.
  • This is best effort, not a security boundary.

Tests

  • traffic/pace_test.go, on a real proxy with curl-like clients:
    • three marked plain-HTTP requests to one host take at least 1 s under a 2 req/s, burst 1 profile, and are counted (rpm 3);
    • unmarked requests to another host are not counted (not paced at the proxy);
    • two marked requests inside a CONNECT tunnel are counted, and share the CONNECT's connection;
    • no target receives Proxy-Authorization;
    • all 8 exchanges are recorded, none with Proxy-Authorization;
    • marks are removed after the clients close;
    • under off, marked requests are not counted;
    • a sink unit test: foreign credentials are stripped and not marked, the marker on a CONNECT is stripped and marked, and a disconnect clears the mark.
  • egress/pace_test.go: MarkProxyURL, IsPaceMarker, Wait (off no-op, pacing with no slot taken, a bounded wait that still counts, the package Wait following the current profile).
  • agent/proxyenv_test.go: the marker is present on all six proxy variables only when the CA is present; the capture-off global proxy is passed unchanged.

Verification

  • gofmt -l on the changed Go files: clean. go build ./... and go vet ./...: ok.
  • go test -count=1 -p 1 ./egress ./traffic ./agent ./server ./db on a fresh throwaway database: egress 3.127s, traffic 7.651s, agent 5.656s, server 56.220s, db 29.220s, all ok.
  • go test -count=1 -race -p 1 ./egress ./traffic ./agent ./server: egress 4.322s, traffic 92.826s, agent 8.840s, server 67.295s, all ok, 0 DATA RACE.
  • Web, the same steps as CI: npm ci ok, npx tsc --noEmit ok, npm run build:static ok.

With traffic capture on, the Bash proxy URL carries a marker userinfo. The recording proxy drops Proxy-Authorization from every request before it is forwarded or recorded; when the value is the marker it marks the client connection, and every later request on it, including those inside its CONNECT tunnel, waits for the per-host token and jitter of the current noise profile (egress.Wait) and is counted, with a bounded wait. WebFetch, the http custom tools and enrich keep the unmarked URL, which egress already paces, so nothing is paced twice. Off paces nothing. Best effort: only clients that honour the proxy are covered, with capture on.
The low-and-slow block said that commands launched through Bash are not paced. With traffic capture on, Bash commands that use the capture proxy are now paced by rate and jitter; raw scanners and commands that bypass the proxy are not, so the rate flags remain the brake.
@BaaRai
BaaRai merged commit 59f768f into main Nov 15, 2026
3 checks passed
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