Skip to content

egress: a request admitted before a fence trip cannot outlive it - #505

Merged
CMGS merged 1 commit into
mainfrom
egress/fence-drop-scope
Nov 7, 2026
Merged

CMGS merged 1 commit into
mainfrom
egress/fence-drop-scope

Conversation

@CMGS

@CMGS CMGS commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Closes the window left open by the fence egress fix in #501.

A fence trip (DropTunnels) closed only the connections already tracked. Two kinds of request slipped through on a fenced node:

  • A CONNECT or SOCKS5 request whose policy check passed just before the trip finished its upstream dial afterwards, was then tracked, and was spliced.
  • A forwarded plain-HTTP response that was already streaming kept streaming.

Either way a replicated claim kept a live outside connection after a peer could have adopted it.

The fix gives the proxy a drop scope, a context that DropTunnels ends and replaces under the connection lock. Each request takes the scope before its policy check:

  • track refuses, and closes, a connection whose scope has ended.
  • A forwarded request is cancelled with its scope.

Intercepted inner requests need nothing new: closing their tracked tunnel cancels them.

Cost: one mutex-guarded read per proxied request or tunnel. A forwarded plain-HTTP request also pays one cancellable context and one AfterFunc registration. CONNECT splices are unchanged after tracking.

Test: a streaming forward ends at DropTunnels; a tunnel whose scope predates the drop is refused and closed; a later one is accepted. With the scope checks removed, the test fails ("a forwarded stream outlived DropTunnels"). Gates: sandboxd unit tests, -race on egress/outbound, golangci-lint 0 issues on linux and darwin, asl 0.

…utlive DropTunnels

DropTunnels closed only connections already tracked, so a CONNECT or SOCKS5 request whose policy check passed just before the trip finished its dial afterwards, got tracked and spliced on a fenced node, and a forwarded plain-HTTP response kept streaming. Each request now takes the proxy's drop scope before its policy check: track refuses a connection whose scope DropTunnels ended, and a forwarded request is cancelled with it.
@CMGS
CMGS merged commit 05275a5 into main Nov 7, 2026
1 check passed
@CMGS
CMGS deleted the egress/fence-drop-scope branch November 7, 2026 13:46
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