feat(remote): require bearer-token handshake on WebSocket upgrade (M1.3)#4
Merged
Merged
Conversation
`myagent remote serve` previously accepted any local TCP client on the WebSocket port. Anything that could reach 127.0.0.1:8765 could drive the agent. Closes that hole: - `ensureRemoteAuthToken(cwd)` creates `.myagent/remote/auth.json` on first launch (mode 0o600 best-effort -- POSIX enforces; Windows no-op) with a 256-bit URL-safe token, and reuses it across restarts. - `createRemoteAgentServer` now requires `authToken`. The upgrade handler rejects requests whose `Authorization: Bearer <token>` header is missing, malformed, or wrong with HTTP 401 + a `WWW-Authenticate: Bearer realm="myagent-remote"` challenge -- before any WebSocket framing is negotiated. - Token comparison uses `crypto.timingSafeEqual` to avoid timing side-channel leaks on local-shared hosts. - `connectRemoteClient` accepts an `authToken` option that injects the matching header. - `remote sessions` (the metadata listing subcommand) is unchanged -- it reads JSON files directly off disk and never opens a socket. The existing three remote tests now pass `authToken: "test-token"` through. Six new tests in `packages/core/test/security/remote-auth.test.ts` pin the invariants: missing header rejected, wrong token rejected, non-Bearer scheme rejected, correct token reaches `ready`, token file persists and round-trips through JSON, and the metadata API does not need the auth file. Catalog row added under "Remote WebSocket auth" in `packages/core/test/security/README.md`. CLAUDE.md updated. Multi-client session ownership and a dedicated `myagent remote client` CLI stay deferred to v2.0 per the M1 plan. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
myagent remote servepreviously accepted any local TCP client on the WebSocket port. Anything that could reach 127.0.0.1:8765 could drive the agent. Closes that hole:ensureRemoteAuthToken(cwd)creates.myagent/remote/auth.jsonon first launch (mode 0o600 best-effort -- POSIX enforces; Windows no-op) with a 256-bit URL-safe token, and reuses it across restarts.createRemoteAgentServernow requiresauthToken. The upgrade handler rejects requests whoseAuthorization: Bearer <token>header is missing, malformed, or wrong with HTTP 401 + aWWW-Authenticate: Bearer realm="myagent-remote"challenge -- before any WebSocket framing is negotiated.crypto.timingSafeEqualto avoid timing side-channel leaks on local-shared hosts.connectRemoteClientaccepts anauthTokenoption that injects the matching header.remote sessions(the metadata listing subcommand) is unchanged -- it reads JSON files directly off disk and never opens a socket.The existing three remote tests now pass
authToken: "test-token"through. Six new tests inpackages/core/test/security/remote-auth.test.tspin the invariants: missing header rejected, wrong token rejected, non-Bearer scheme rejected, correct token reachesready, token file persists and round-trips through JSON, and the metadata API does not need the auth file.Catalog row added under "Remote WebSocket auth" in
packages/core/test/security/README.md. CLAUDE.md updated.Multi-client session ownership and a dedicated
myagent remote clientCLI stay deferred to v2.0 per the M1 plan.