Conversation
Extract auth-token resolution into a pure helper with deterministic generated-token testing coverage for CLI/env precedence and no-auth behavior.
Route server startup/shutdown through ServerService startServer/stopServer, enable secure-by-default auth token resolution with --no-auth and --print-auth-token options, and refresh startup output with connection helpers. Also update mux server --help assertions for the new flags.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d1b65ce95
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address Codex review: check for an existing server BEFORE serviceContainer.initialize() to prevent orphaned task resumptions. ServerService.startServer() still re-checks as defense-in-depth.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ca123cd6c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Print networkBaseUrls[0] instead of baseUrl in 'Connect from another machine' instructions, since baseUrl is loopback for wildcard binds. - Shell-quote the auth token to handle metacharacters. - URL-encode the token in the browser query string.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff4d79461e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Make
mux serversecure-by-default: when no auth token is provided via--auth-tokenorMUX_SERVER_AUTH_TOKEN, the CLI now auto-generates a random 32-byte hex token. This matches the desktop app's existing behavior (randomBytes(32).toString("hex")).Simultaneously consolidates duplicated server lifecycle logic by delegating to
ServerService.startServer()/stopServer(), eliminating ~70 lines of manual lockfile, mDNS, andcreateOrpcServer()wiring.Background
Previously,
mux serverwith no flags ran unauthenticated — anyone who could reach the network interface had full API access. The desktop app was already secure-by-default, but the CLI server was not.The CLI also duplicated server startup responsibilities (lockfile check/acquire,
createOrpcServer()call, mDNS advertising,isLoopbackHost()) thatServerServicealready handles, creating maintenance burden.Implementation
New:
resolveServerAuthToken()helper (src/cli/serverAuthToken.ts)Pure function with clear precedence:
--no-auth>--auth-token>MUX_SERVER_AUTH_TOKEN> auto-generated. Returns a discriminated union (ResolvedAuthToken) with mode + source metadata.Consolidated
src/cli/server.tsServerLockfile,createOrpcServer,MdnsAdvertiserService,isLoopbackHost()usageserverService.startServer()call +serverService.stopServer()for cleanup--no-auth(explicit insecure escape hatch) and--print-auth-tokenServerService.getLockfilePath()accessorSmall addition so the CLI can print where the lockfile lives without re-instantiating
ServerLockfile.Validation
make typecheck✅bun test src/cli/serverAuthToken.test.ts— 9/9 ✅bun test src/cli/run.test.ts— 17/17 ✅make static-check✅📋 Implementation Plan
Plan: Secure-by-default
mux server+ consolidate startup viaServerServiceContext / Why
The standalone CLI server (
mux server) can currently run unauthenticated when no token is provided. That’s unsafe by default.Separately,
src/cli/server.tsduplicates server-startup responsibilities that already exist inServerService(lockfile discovery/acquire, network base URL computation, mDNS advertising, stop/cleanup). Consolidating ontoServerService.startServer()/stopServer()reduces long-term maintenance and keeps the desktop + server codepaths consistent.Evidence (repo)
src/cli/server.tsderivesAUTH_TOKENfrom--auth-token/MUX_SERVER_AUTH_TOKEN, and converts blank/missing values toundefined.src/node/orpc/authMiddleware.tsbypasses auth when token is missing/blank:if (!authToken?.trim()) return passThrough.src/desktop/main.ts:process.env.MUX_SERVER_AUTH_TOKEN ?? randomBytes(32).toString('hex').src/node/services/serverService.tsalready implementsstartServer()/stopServer()with lockfile, mDNS, andcomputeNetworkBaseUrls().What `src/cli/server.ts` duplicates today (high-level)
ServerLockfilecreateOrpcServer()directlyserver.lockMdnsAdvertiserServiceServerService.startServer()/stopServer()already handle these.Recommended approach: Refactor
mux serverto useServerService.startServer()and always provide an auth tokenNet LoC (product code only): ~-20 LoC (delete duplicated lockfile+mDNS code; add token resolution + a couple flags)
Acceptance criteria
mux serverwith no flags/env vars generates a random auth token and requires it for HTTP/WS API.mux server --auth-token …andMUX_SERVER_AUTH_TOKEN=… mux serverstill work.mux server --no-auth(disables auth; writes empty token to lockfile).src/cli/server.tsno longer contains duplicated lockfile + mDNS logic.Implementation details (ordered)
1) Extract token resolution into a tiny helper (unit-testable)
Files:
src/cli/serverAuthToken.ts(new)src/cli/serverAuthToken.test.ts(new)Suggested API:
Key test cases:
noAuth=true→{ mode: 'disabled', token: '' }cliToken=' abc '→{ mode: 'enabled', token: 'abc', source: 'cli' }randomBytesFn)2) Consolidate server startup/shutdown in
src/cli/server.tsFile:
src/cli/server.tsCommander flags:
--auth-token <token>, but update help text (no longer “optional”; default is generated)--no-auth--print-auth-token(optional; forces printing even on loopback)Replace the manual wiring:
ServerLockfilepre-check +lockfile.acquire(...)createOrpcServer(...)MdnsAdvertiserServicehandlingwith a single call:
startServer()resolves.await serviceContainer.serverService.stopServer()(thenawait serviceContainer.dispose()).3) Startup output / UX improvements
File:
src/cli/server.tsUse
ServerInforeturned bystartServer():info.baseUrl${info.baseUrl}/api/docsinfo.token.length > 0)--print-auth-tokenis set or wheninfo.networkBaseUrls.length > 0(strong signal user intends LAN/VPN access).MUX_SERVER_URL=...MUX_SERVER_AUTH_TOKEN=.../?token=...--no-auth, print a loud warning that the server is open to anyone who can reach it.4) Avoid re-instantiating
ServerLockfilejust to print the lockfile path (optional consolidation)File:
src/node/services/serverService.tsAdd a small accessor:
Then
src/cli/server.tscan print the lockfile path viaserviceContainer.serverService.getLockfilePath().(If we want zero churn outside CLI, the fallback is to instantiate
new ServerLockfile(serviceContainer.config.rootDir)purely for printing; but the accessor is cleaner.)5) Update tests
src/cli/run.test.ts: updatemux server --helpexpectations to include--no-auth/--print-auth-tokenand updated--auth-tokendescription.serverAuthTokenunit tests (fast; no real server process).6) (Optional) Clarify the browser auth prompt
File:
src/browser/components/AuthTokenModal.tsxTweak the description to mention the token comes from startup output or the
server.lockfile.Validation
make testmake typecheckAlternative (smaller churn, more duplication): secure-by-default without consolidation
Net LoC (product code only): ~+40 LoC
Only change
src/cli/server.tsto generate a token when missing, and keep the existing directcreateOrpcServer()+ lockfile + mDNS logic. This is lower refactor risk, but keeps two server-start implementations that must be maintained together.Generated with
mux• Model:anthropic:claude-opus-4-6• Thinking:xhigh• Cost:$0.94