Skip to content

fix(start-os): keep streams a re-addressed vhost target still accepts - #4764

Merged
dr-bonez merged 1 commit into
masterfrom
fix/os-vhost-retarget
Nov 18, 2026
Merged

dr-bonez merged 1 commit into
masterfrom
fix/os-vhost-retarget

Conversation

@Dominion5254

Copy link
Copy Markdown
Member

Deleting a gateway on StartOS 0.4.2 showed "rpc error: replay attack detected" alongside the success message, even though the gateway was deleted.

Cause

A vhost target's identity includes the addresses it accepts on, so any change to that set (a gateway added or removed, an address switched off) made the net controller drop the old target and add a new one. Dropping a target cancels every stream proxied through it, including the admin UI's own connection while the delete RPC was still in flight. The browser resent the signed POST on a fresh connection, NonceCache rejected the repeated nonce, and the delete that had already succeeded reported "replay attack detected".

The browser resend is inferred: it is the only path that presents the same nonce twice. The server-side cut is what the new tests cover. On master the UI's authenticated RPCs travel over the session websocket (#4583), so the same cut would surface as a transport error rather than a replay rejection, but it still disconnects every session on addresses that stay enabled.

Change

  • VHostController::replace / VHostServer::replace: when the new target routes exactly like the old one (routes_like) and this owner holds the entry alone, the new target takes over the entry and its connection registry in place. Otherwise it falls back to drop-then-add, as before.
  • Each stream records the Arrival it came in on. ConnRegistry::readmit cancels the streams the new target rejects and keeps the predicate, so streams that register later (a TLS handshake already in flight) are checked against it too. Switching an address off still ends its streams immediately.
  • PlainHttpProxy::retarget does the same for plaintext listeners, sharing the target with the accept loop.
  • net_controller reconciles through replace / retarget instead of always rebuilding.
  • ProxyTarget splits its equality into same_route (how a stream is relayed) plus the admission fields.

Verification

Ran on 4049ae2f9 (same patch as the pushed head; rebased onto master 362bbd1 without conflicts, git range-diff identical):

  • cargo test vhost tests: 58 passed, 3 ignored (capability-gated), 0 failed. This includes the reworked disabling_an_address_disconnects_only_its_streams_and_gates_new_arrivals, plus new retargeting_a_plaintext_proxy_keeps_only_the_streams_it_still_accepts and readmission_cancels_rejected_streams_including_later_ones.
  • Regression check: with the old drop-and-re-add restored on a scratch branch, the TLS test fails at "a stream on a still-enabled address survives"; it passes with this change.
  • make start-core-test: 33 + 1827 (37 ignored) + 3 passed, 0 failed.
  • make start-core-format-check: clean. node scripts/changelog.mjs check-version projects/start-os: passes. Prettier on the fragment: clean.

Not run: a live StartOS deploy (no VM on hand), or a separate startbox build (the change is confined to start-core; CI compiles it).

A vhost target's identity includes the addresses it accepts on, so any
change to that set (a gateway added or removed, an address switched off)
replaced the target, and replacing a target cancelled every stream
proxied through it. Deleting a WireGuard gateway therefore cut the admin
UI's own connection while the deletion RPC was still in flight. The
browser resent the signed POST on a fresh connection, the nonce cache
rejected the resend, and a delete that had succeeded reported "replay
attack detected".

A target that differs from its predecessor only in what it accepts now
takes over the predecessor's entry in place. Each stream records where
it arrived, and the takeover cancels only the streams the new target
rejects. Streams that register afterwards, such as a TLS handshake
already in flight, are checked against the new target as well, so
switching an address off still ends its streams immediately. The
plaintext proxy is retargeted the same way. A change to how streams are
relayed, or an entry another owner shares, still replaces the target
and cancels its streams.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 5343f53ec. The head merges cleanly with current master; I found no blocking correctness regressions in the reconciliation, ownership, admission or cancellation paths.

Gateway/address changes preserve existing proxy connections when the replacement still admits their arrival and relays identically. Disabled arrivals are cancelled, including connections registered after replacement. TLS preservation additionally requires exclusive ownership and no existing replacement entry; other cases retain the existing drop-and-add behavior without changing another owner's entry.

The change extends the existing per-target connection registry and cancellation tokens rather than weakening replay protection or adding retries. Recorded arrival metadata and a retained admission predicate cover handshakes completing after reconciliation; plaintext listeners share their updated target with their existing accept loop. Relay equality is shared with target equality, and admission reuses the existing address filter. No persisted configuration or wire contract changes.

Implementation diff: +238 / −65 lines in 2 files (excludes lockfiles, tests, docs, release notes, and changelog).

Verification evidence: The author reports 58 passing focused vhost tests, a passing full make start-core-test, formatting and release checks on 4049ae2f9, with an identical patch after rebasing to this head. The TLS regression reportedly fails with the old teardown restored. I inspected the tests but ran no builds or tests as reviewer. The evidence covers retained/rejected streams and late registry admission, not a live StartOS gateway deletion or an observed browser resend; that explanation for the original replay error remains inferred.

Current CI has passed Prettier, changelog/version validation, conflict-marker and license checks. start-core Tests & Man Pages, formatting/generated-artifact checks, other test suites and product build matrices remain pending; this approval does not establish their success.

Open #4688 changes the same proxy target and relay machinery. It is independent of this PR; integration must retain its chain identity in the shared relay comparison and adapt its connection-tracking calls. #4666 separately preserves public-address intent across renumbering and does not supply this connection-lifetime fix.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@dr-bonez
dr-bonez merged commit 09ed246 into master Nov 18, 2026
57 checks passed
@dr-bonez
dr-bonez deleted the fix/os-vhost-retarget branch November 18, 2026 19:42
@helix-white

Copy link
Copy Markdown
Member

Confirmed merged. All executed PR-head CI checks passed, including core tests, generated artifacts, formatting and platform builds. No further changes were requested in the final approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants