Forcing the registry to 0600 and runtime/ to 0700 broke shared-group
HERMES_HOME deployments (NixOS module: UMask 0007, setgid 2770 home):
other hermes-group users got EACCES on active_sessions.lock, and the CLI
and gateway claim paths swallow that and run with no lease. Group members
are already trusted with .env and state.db; the threat is other users, so
clear only the 'other' bits and keep group bits and setgid. A loose
registry left by an older build is now also closed on read, since attach
discovery never writes.
attach_proof now MACs profile_home and websocket_url too
("hermes-session-attach:<sid>:<nonce>:<profile_home>:<websocket_url>"),
so a relay holding a genuine proof cannot swap in its own socket.
Fixes#120604
The lease-keyed attach_proof now refuses an echoing listener, so the E2E
impersonator cell passes; a stale known_gate would hide a regression.
Also drop the redundant utf-8 encode args ruff UP012 flags.
Fixes#120604
The session-attach handshake MACs are keyed on lease ids stored in
active_sessions.json, which was written at umask-default permissions, so any
user on the machine could read the key and forge a valid attach proof for a
rogue listener. Write the registry with mode 0600 and tighten the runtime
directory to 0700 (best effort, POSIX only, never raises so shared mounts
keep working). A registry left loose by an older build is tightened again on
the next write.
Also soften the module docstring: the client checks the reply proof, but that
only proves the listener could read the registry, and client_proof has no
server-side verifier in the tree yet.
Tests: assert the registry lands at 0600 with a 0700 directory, assert an
already-loose registry is tightened on next write, and add the
informed-listener case (a rogue reading the registry as another user is
refused).
discover_attach_url verified the /api/session-attach reply by comparing
session_id, lease_id and profile_home against the values it had just sent,
so any process bound to the advertised loopback port could echo them back
and return its own ws:// endpoint. The TUI would then attach to the
impersonator and send it session traffic. lease_id was also transmitted in
the query, so the listener learned the only registry-side secret outright.
The request now carries a fresh nonce and client_proof = HMAC(lease_id,
"hermes-session-attach-request:<session_id>:<nonce>"), and the reply must
echo the request fields plus attach_proof = HMAC(lease_id,
"hermes-session-attach:<session_id>:<nonce>"). The lease id never leaves
the registry: a port hijacker cannot forge either proof, while a responder
can still authenticate the requester without receiving the secret.
The attach-refusal message framed an unimplemented capability as a property
of the live owner ("does not advertise cooperative attachment"), sending users
looking for a setting that does not exist. Follow the shared owner-refusal
contract instead: first line states the chat is open elsewhere and names the
working alternative (close it there, hermes --resume <id> here), second line
keeps the Details: owner summary. Same shape when the handshake itself fails.
Fixes#113457
(cherry picked from commit 78966577102f3db1383a162f526394d8af757a38)
Fence owner discovery by profile, lease and loopback endpoint, and hand the authenticated URL to the existing Ink transport without acquiring a competing lease. Distinguish lease age from turn activity in unsupported-owner recovery.
Client slice only: requires the integration runtime to advertise shared_runtime_url and provide the session-attach handshake. Classic CLI attachment remains an integration gap.