Repository navigation
harden(l1): equalise answer timing, expire captured hellos, canary the gate - #1
Merged
Conversation
…e gate Three weaknesses closed and three defects found while closing them. Full narrative in docs/CHANGELOG.md; the reasoning that does not fit a diff is below. Answer timing. A relay has two answer paths costing structurally different amounts of time: a client holding a valid tag is answered out of local state, while everyone else is spliced, which costs a TCP connection to the borrowed site plus that site's own answer time. Connections to one relay address therefore split into two latency modes, and no real web server does that. It needs no decryption, no key and no active probing — a clock is enough — and it survived every shape measurement because shape was only ever counted in bytes. ProfileSite now measures how long the site takes to answer and the relay waits that out, from the hello's arrival so the key exchange comes out of the budget rather than being added to it, and capped so a slow or hostile site cannot turn every handshake into a stall. Measured: 510us against a site taking 150ms. This narrows the gap rather than closing it, and the gate says so. The splice still pays the TCP connect that the profile's measurement does not include, so cmd/probe captures a third, unauthenticated session against the relay and reports the two paths side by side. The residual is measured, not assumed. Replay freshness. The tag is a function of the hello, so a verbatim replay verifies by construction and a cache of seen randoms was what refused it. But a cache is a memory budget and every memory budget expires: a censor holding one captured hello only had to wait out the TTL, and waiting is free, so the TTL was the real lifetime of the defence. The tag now also covers a coarse clock and a relay accepts only adjacent windows, so a captured hello expires on its own. Nothing changes on the wire — the window is an input to the HMAC, not a field. The cost is stated rather than hidden: a client whose clock is wrong past the slack is silently unreachable, because an out-of-window tag has to be answered exactly like a forged one. Dial now fails with ErrRelayRejected naming the clock among the causes, instead of the raw AEAD failure being spliced used to produce. The cache also stopped collapsing. At its ceiling it used to empty itself, so a relay busy enough to fill it inside one TTL periodically forgot everything and ran unprotected until it refilled — a cliff that appears on a relay doing well, not one under attack. Entries now live in rotating generations and the ceiling costs the oldest only. The freshness window is what makes that safe. Canaries. Every test in internal/network/probe asserted the harness finds nothing, which is also what a harness returns once it has quietly stopped working, and the gate downstream keeps certifying relays either way. The harness and the probe binary are now pointed at deliberately-wrong relays and required to fail, one canary per measurement so none can be satisfied by an unrelated failure. The first run earned its keep: the post-handshake comparison had inherited a 512-byte tolerance from the certificate-flight comparison, and that window is only a few hundred bytes in total, so a relay sending no session tickets at all was inside tolerance. That measurement had been inert. Defects found on the way: - TCP teardown mirroring never worked on Windows. A peer reset arrives as WSAECONNRESET while syscall.ECONNRESET there is a synthetic value no socket returns, so the check matched nothing and a Windows relay closed every spliced connection with a FIN against a site sending RST. This is a distinguisher cmd/probe found and fixed once already, on a platform most of the residential pool this design bets on would run, invisible because CI is Linux-only. Detection is per-platform now and has its own test. - The splice truncated the site's answer under load. Teardown waited for whichever direction finished first, then allowed a fixed 200ms; when the site closed straight after answering, the client-to-site copy could win that race and start a grace the response had to beat. It now waits on the site's direction by name, bounded, because a site always finishes what it started. - A gofmt check that cannot run on a CRLF checkout, i.e. any Windows clone. Recorded rather than fixed. What is owed but not done is in docs/ROADMAP.md's new hardening backlog, H1-H25, including two distinguishers found while reading this code and not yet fixed: the relay hardcodes its ServerHello cipher suite instead of echoing the one the borrowed site negotiated (H4), and the splice ignores the ClientHello's SNI while the docs claim it honours it (H5). Verified: go build, go vet, go test ./..., gofmt, and hack/smoke.sh including its new gate-failure canary. Not verified locally: -race, which needs cgo and a C toolchain this machine lacks; CI covers it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
croc100
deleted the
harden/answer-timing-replay-freshness-gate-canaries
branch
October 3, 2026 01:25
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.
Closes three L1 relay distinguishers and fixes three defects found while closing them. Full narrative in
docs/CHANGELOG.md; backlog of what remains indocs/ROADMAP.md(H1–H25).Weaknesses closed
ProfileSitenow measures the site's answer time and the relay waits it out (from hello arrival, so the key exchange comes out of the budget), capped so a slow/hostile site can't stall every handshake.cmd/probecaptures a third unauthenticated session and reports the residual (the splice's TCP connect) side by side rather than assuming it away.ErrRelayRejectednaming the clock, instead of the splice's raw AEAD failure. The cache also no longer collapses at its ceiling — rotating generations evict only the oldest, which the freshness window makes safe.Defects found on the way
WSAECONNRESETvs the syntheticsyscall.ECONNRESET), so a Windows relay FIN'd against a site sending RST — invisible because CI is Linux-only. Detection is per-platform now, with a test.gofmtcheck that cannot run on a CRLF checkout — recorded, not fixed.Not yet fixed (noted in ROADMAP)
Two distinguishers found while reading this code: the relay hardcodes its ServerHello cipher suite instead of echoing the site's (H4), and the splice ignores the ClientHello SNI while the docs claim it honours it (H5).
Verification
go build,go vet,go test ./...,gofmt, andhack/smoke.sh(including its new gate-failure canary) all pass. Not verified locally:-race(needs cgo/a C toolchain this machine lacks); CI covers it.🤖 Generated with Claude Code