Repository navigation
feat(replies): add verified sender context and optional return-route diagnostics - #86
Merged
Merged
Conversation
abruption
force-pushed
the
feat/21-sender-context
branch
5 times, most recently
from
October 2, 2026 05:44
5a84cf9 to
63eec74
Compare
8 of 11 tasks
abruption
force-pushed
the
feat/20-multi-host-ssh
branch
from
October 3, 2026 02:35
8cbad61 to
05f1234
Compare
…diagnostics Detect the sender from bounded evidence: the inherited inbox socket variable must match exactly one live registered session, and the Codex thread/session variable must be a valid UUID. Nested, conflicting or absent evidence gives no identity. Generate inert session-peer://v1/reply routes with host precedence --reply-to, SESSION_PEER_REPLY_HOST, CC_PEER_REPLY_HOST, then the tailnet address, and report replyRoute/addressResolution like the Python reference. Use tailscale status only as a routing hint with exact Online states: keep the SSH alias, add HostName for known online peers and HostKeyAlias only when ssh_config sets none, refuse known offline or ambiguous peers before SSH, and leave everything else as ordinary SSH. Normalize a reply URI to local only for this user on this machine. Add doctor --check-return-route as an explicit, bounded, noninteractive reverse SSH probe that stays bound to the origin and is never inferred from forward reachability. Closes #21
…eiver names from the login user Treat every numeric IPv4 form accepted by inet_aton (127.1, 2130706433, 0x7f.1, 0177.0.0.1, 0) and IPv4-mapped or compatible IPv6 as loopback or unspecified, without DNS. Decide whether a host names the receiver with a helper that ignores the login user, so an unusable local username cannot turn the receiver's own host name into a verified remote route.
A jump host implies SSH, so a reply URI naming this user on this machine is normalized to a local route only when neither --host, an SSH option nor --ssh-jump was given.
Split the host predicates. Return and reply hosts that might name a machine are refused without guessing resolver behavior: localhost names, canonical loopback and unspecified addresses, their mapped forms, IPv4-compatible IPv6 and every non-canonical numeric form. Local normalization accepts only exact localhost, canonical 127.x.y.z, ::1 and canonical mapped loopback, never a non-canonical numeric or an IPv4-compatible address.
abruption
force-pushed
the
feat/21-sender-context
branch
from
October 3, 2026 02:39
63eec74 to
bfd0e8f
Compare
State that the receiver refuses a known self name or an unprovable numeric form, that known names are only the exact OS host name and Tailscale self names and addresses, and that remote sends refuse loopback and non-canonical numeric reply hosts. Add regressions for a private return host and for an unusable login name.
abruption
force-pushed
the
feat/21-sender-context
branch
from
October 3, 2026 02:50
bfd0e8f to
de6aef7
Compare
This was referenced Oct 3, 2026
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.
Summary
Closes #21.
Retargeted to main after #84 merged (
b2575da). The five #21 commits were rebased onto main (b2575daon top of #79da0e06d); the tree differs from the pre-merge stacked head63eec74only by #79's three files. History below records the earlier stacked state.Review fixes (
6689f7b). These address the independent review off35f1c6:invalid_return_route,return_host_is_receiver, and refusing loopback reply hosts on remote sends);HostKeyAlias, read through the samessh -G;Onlinestates, including refusing known-offline peers with MagicDNS off;exit 0probe command and documented lookup bounds;src/ssh.tsgainssshConfig()on this branch only. #84 is unchanged.Follow-up (
63eec74, non-blocking review).return_host_is_receivernow reads "known self name OR unprovable numeric form". Known names are only an exact match with the OS host name or the Tailscale self names and addresses; there is no claim of verification against other DNS or LAN aliases. The remote reply-host refusal now names non-canonical numerics as well as loopback. Code comments, PARITY and the four guides are updated.[email protected]return host is an ordinary remote host, forwarded and probed (verified with the fake probe), not refused;'Fixture User', injected through a test-only--importpreload),--reply-to remote-hoststays unqualified, and even--reply-to localhoststays an SSH route because "this user on this machine" cannot be proven.test/replies.test.ts,test/ssh-hosts.test.tsandtest/process.test.tsgave 24 tests, 23 pass, 0 fail, 1 skipped (Windows-only); the repository check is OK.Review fix (
15d10d4, formerly5a84cf9): non-canonical numerics. The45b753dhelper guessed inet_aton meanings, but resolvers differ: this Mac'sgetaddrinfo(AI_NUMERICHOST)reads0177.0.0.1as 177.0.0.1 and wraps overflow forms such as6425673729to loopback. There are now two separate predicates that are never mixed.unsafeReturnHost()is conservative and fails closed. It refuses return/reply hosts that are localhost names, canonical 127.0.0.0/8 or 0.0.0.0/8,::1,::, their::ffff:mapped forms, IPv4-compatible IPv6 (::a.b.c.d,::7f00:1), or any non-canonical numeric (leading zeros, fewer than four parts, hex/octal parts, single integers, overflow).localName()is strict and decides local delivery. It accepts only exactlocalhost, canonical127.x.y.z,::1and canonical mapped::ffff:127.x.y.z; never non-canonical numerics and never IPv4-compatible addresses (RFC 4291 section 2.5.5.1, deprecated).0177.0.0.1,127.1,2130706433,6425673729,::7f00:1and::127.0.0.1stay SSH (one attempt, nossh_self);6425673729,4294967296and18446744075840258049, plus[::7f00:1]and[::127.0.0.1], are refused asinvalid_return_routewith zero SSH, and fail on the receiver asreturn_host_is_receiverwith no probe;isSelf.Review fix (
81c6353).--ssh-jumpnow counts as an explicit SSH transport. A same-user self reply URI combined with--ssh-jumpstays an SSH route through the hop (one SSH attempt,sshJumpreported) instead of being normalized to local with the jump silently ignored. A regression was added to the self-normalization cases.Review fixes (
45b753d, formerly93bce35).127.1,2130706433,0,0x7f.1,0177.0.0.1,017700000001) and IPv4-mapped or compatible IPv6 ([::ffff:127.0.0.1],::ffff:7f00:1,::7f00:1), alongside::1,::and the localhost names. All of these are refused asinvalid_return_routewith zero SSH, fail on the receiver asreturn_host_is_receiverwith no probe, and are refused as remote-send reply hosts (invalid_reply_host).namesThisMachine()decides whether a host names the receiver independently of the login user, sobob@<receiver hostname>fails asreturn_host_is_receivereven whenos.userInfo().usernameis unusable (unit regression with a mocked'Fixture User').isSelf()keeps requiring that user for local normalization.Rebase notes (
--ssh-jump).ProxyCommandsits with the fixed hardening options, ahead of the TailscaleHostName/HostKeyAliasoptions and the user options. With a resolved peer, the hop's-W '[%h]:%p'therefore targets the MagicDNS name.sshJumpis added to every per-host result next to the Tailscale metadata.--ssh-jump.Earlier rebase notes.
remotes()combines both changes. The per-host Tailscaleroute()runs first, so a known offline peer still gets zero SSH. Thessh -Guser lookup then runs in its own guard: a failure givesunknownfor that host only, and the host is still dispatched.--hostvalues also skips the values of the new--reply-tooption and the wire-only--return-route-hostoption.ssh -Glookup use the probing machine's trusted ssh_config (ProxyCommand,Match exec). This matches feat(ssh): support ordered multi-host commands and constrained connection options #84's trust-boundary text in all four guides and PARITY. PARITY also notes that the injectedHostName/HostKeyAliasoverride the same ssh_config keys.Adds sender context, generated structured reply routes, Tailscale routing hints, same-user self normalization and an opt-in
doctor --check-return-route. All of this is inert metadata: nothing here authenticates a peer, authorizes a send, executes Reply text or infers ACK. Delivery contracts are unchanged: owner verification, ambiguity refusal, pre-submit revalidation, exact-version SSH preflight, stdin JSON request, and no retry afterunknown.Acceptance criteria
*_CODE_MESSAGING_SOCKETmust match exactly one live registered session, by PID parsed from…<pid>.sockas in Python, else by exact socket path. Its name is used only if it is printable, not all digits, has no:, and is unique by casefold; otherwise the PID is used. Codex:CODEX_THREAD_ID, elseCODEX_SESSION_ID, must be a valid UUID.codexHomeis added only for an absoluteCODEX_HOME. Ambiguity: two different Codex IDs, or socket-agent evidence and Codex evidence together (a nested agent), give no identity. Python instead prefers the socket agent; the issue asks for ambiguous evidence to be omitted.--reply-toand env precedence; keep--reply-address,--no-from,--no-reply-to; only validated structured URIs--reply-to, thenSESSION_PEER_REPLY_HOST, thenCC_PEER_REPLY_HOST, then the tailnet address (MagicDNS name, else 100.64.0.0/10 IPv4 fromtailscale status). The current user is added when missing.--reply-to,--reply-addressand--no-reply-toare mutually exclusive (conflicting_reply_options). An invalid configured host isinvalid_reply_host. A generated URI is accepted only if the existingreply()parser parses it back.replyRoute(localverified/same_machine_route; SSHunverified/reverse_ssh_not_checked) andaddressResolution(uri,transport,normalizedFrom) use Python's names. There is no executableReply:line.tailscale status --json: 3 s bound, queried at most once per command, and only when a route needs it. Exact states: onlyOnline === true(boolean) with MagicDNS on is resolved: the alias stays the SSH destination and-o HostName=<MagicDNS>is added after the fixed hardening options.-o HostKeyAlias=<original>is added only when the samessh -Gused forsshUserread the config and found nohostkeyalias. A configured alias is kept, and an unreadable config is never overridden.Online === false(boolean) is refused before any SSH (tailscale_peer_offline) even with MagicDNS off; an ambiguous name givestailscale_destination_ambiguous. A missing, null, string or numericOnline, MagicDNS off, an unknown name, a stopped/failing/missing CLI, orSESSION_PEER_TAILSCALE=offmeans ordinary SSH with no canonicalization. Metadata follows Python:hostis the MagicDNS name andsshHostis the alias.doctor --check-return-route [--reply-to USER@HOST]; forward never implies reversenormalizedFrom: "ssh_self") only when its host has an explicit user equal to the current OS user, names this machine, and the route came from the URI alone. Python also normalizes a host without a user; TS requires the user. Origin binding: with--host, a loopback return host (localhost,*.localhost,127.x,::1) is refused before any SSH (invalid_return_route). On the receiver, a forwarded return host naming the receiver itself (loopback, its hostname or its tailnet self, for any user) fails asreturn_host_is_receiverand is never reported as a verified local route. A remote send refuses a loopback reply host (invalid_reply_host). The probe runsssh -T -o BatchMode=yes -o PasswordAuthentication=no -o KbdInteractiveAuthentication=no -o NumberOfPasswordPrompts=0 -o StrictHostKeyChecking=yes -o UpdateHostKeys=no -o ConnectTimeout=5 -o ConnectionAttempts=1 -o ControlMaster=no -o ControlPath=none -- USER@HOST 'exit 0'. The 8 s deadline covers that finalsshonly; the Tailscale (3 s) andssh -G(5 s) lookups are bounded separately.exit 0is a no-op in POSIX shells, cmd.exe and PowerShell (Python usestrue, which cmd/PowerShell lack); only POSIX return hosts have fixture coverage. There is no stderr in output and no retry. It never changesok/ready.test/replies.test.ts(10 tests).Files
src/replies.ts(new):sender(),tailnet(),route(),isSelf(),detectedHost(),configuredHost(),returnHost(),replyUri(),probeReturnRoute().src/cli.ts: new--reply-toand--check-return-routeflags and the wire-only--return-route-host; sender and route generation; reply-URI self normalization; per-host Tailscale resolution inremotes(); doctor probe and remotereturnRoutevalidation;replyRoute/addressResolutionon send results.src/protocol.ts:envelope()takes an optional 4thsender({agent,id}ornull). Existing three-argument calls behave as before.docs/api.mdis updated.src/output.ts: doctor textReturn route:line.src/help.ts: send/doctor/transport usage.test/replies.test.ts, and thetest/fixtures/isolate-env.mjspreload, added tonpm testandnpm run test:windows. The preload setsSESSION_PEER_TAILSCALE=offand clears the inbox-socket variable,CODEX_THREAD_ID,CODEX_SESSION_ID,SESSION_PEER_REPLY_HOSTandCC_PEER_REPLY_HOST; fixtures that need an identity set it explicitly. A guard test asserts this.scripts/release.mjs,test/package-smoke.tsincludedist/replies.*.Type
Validation
npm ci --ignore-scriptsandnpm run buildSESSION_PEER_PYTHON_ROOT=/path/to/pinned/reference npm test(on main after retargeting): 101 tests, 96 pass, 0 fail, 5 skipped (Windows-only).npm run test:package:packageSmoke: pass.npm audit: 0 vulnerabilities.node scripts/check-repository.mjs: OK.node scripts/release.mjs pack: includesdist/replies.*.release gateand CodeQL run on the main-based head after retargeting (see the latest checks on this PR). Earlier stacked runs (e.g. 36970305866 on63eec74) are history.Test coverage (
test/replies.test.ts, fakesshand faketailscaleon a tempPATH):CODEX_HOME. Name fallback to PID for casefold collisions, all-digit names,:and newlines. Exact-path matching for pipe-style sockets.--no-from, and--no-reply-to. Absent and ambiguous senders add nothing. Precedence order across--reply-to,SESSION_PEER_REPLY_HOSTandCC_PEER_REPLY_HOST. A self--reply-togives a local route. Conflicts and invalid hosts are refused before delivery. A body containing$(touch pwned)is delivered as text and never executed. Zero ssh and zero tailscale calls.list: three hosts (online, offline, unknown), exit 1, one status query. Exact argv (HostName/HostKeyAliasafter the fixed options and before-p). The offline host gets zero SSH calls. Missing, stopped andoffTailscale give ordinary SSH.unverified). The body and Reply-To are never in argv.--hoststays SSH (exactly one attempt). Malformed and conflicting URIs give zero SSH and zero deliveries.--reply-towith--hostgivesinvalid_return_routeand zero SSH (me@localhost,127.0.0.1,[::1]). A receiver's own hostname givesreturn_host_is_receiverwith no probe. A direct wire request with--return-route-host bob@localhostgivesreturn_host_is_receiver. A remote send with a loopback--reply-toorSESSION_PEER_REPLY_HOSTgivesinvalid_reply_hostand zero SSH. ForHostKeyAlias: a configured alias is kept,-Gfailure means no injection, and no config alias means ours is injected; each is checked for bothworkerandaudit@worker.Onlinevalues undefined, null,'true','false', 1 and 0 all give ordinary SSH. With MagicDNS off, an offline peer is refused.--reply-towithout--check-return-route,list --check-return-routeand--return-route-hostoutside the wire are refused. Return-route outcomes: unavailable host, self as local without SSH, and verified/auth/host-key/timeout-stderr/other with no stderr leak. A hung probe is killed at 8 s and reported astimeout, with no retry. Exact probe argv is checked. Over SSH, two hosts each probe back with the forwarded--return-route-host. A missing return host is not forwarded. Text output is checked.Tested environments / limitations
test/replies.test.ts. The CLI fixtures are POSIX-only. Windows pipe-path sender matching is unit-tested on POSIX with a pipe-style string; there is no Windows-native evidence.Release impact
No release or deployment. Behavior changes, all additive or opt-in:
Reply-Toby default (Python parity).--no-reply-todisables it.--hostmay querytailscale status --json(≤3 s) and may refuse a known offline peer.replyRoute,addressResolution,returnRoute.hostbecomes the MagicDNS name for resolved peers.envelope()gains an optional 4th parameter.SESSION_PEER_REPLY_HOST,CC_PEER_REPLY_HOST,SESSION_PEER_TAILSCALE.Both SSH endpoints still require the same version. No native dependency changes.