Terminal WebSocket Authentication and Ownership Gap
Summary
The terminal access path currently trusts a user-supplied session identifier and does not enforce authentication or session ownership before attaching to the underlying tmux session.
This affects both terminal implementations:
packages/web/server/terminal-websocket.tspackages/web/server/direct-terminal-ws.ts
On the client side, the dashboard terminal entry points build terminal URLs from a session ID and connect without a per-connection proof of authorization:
packages/web/src/components/Terminal.tsxpackages/web/src/components/DirectTerminal.tsx
The issue is broader than URL construction. The server-side terminal endpoints accept a valid session ID, resolve the tmux session, and attach to it. There is currently no auth token, no ownership check against session metadata, and no terminal-specific rate limiting.
Files Involved
packages/web/server/terminal-websocket.tspackages/web/src/components/Terminal.tsxpackages/web/server/direct-terminal-ws.tspackages/core/src/metadata.ts- Session metadata storage under
~/.agent-orchestrator/{hash}-{projectId}/sessions/{sessionId}
Security Impact
- Any caller that can reach the terminal HTTP/WS ports and guess or enumerate a valid session ID may be able to attach to a live agent terminal.
- Terminal access is effectively equivalent to interactive shell access within the session runtime, including seeing prompts, outputs, secrets printed to the terminal, and potentially sending input.
- Session ID validation only checks format. It does not establish who is connecting or whether they are allowed to access that session.
- Current metadata storage contains session state and routing data, but it is not used as an authorization source for terminal attachment.
- The issue exists in both the ttyd-backed path and the direct
wspath, so fixing only one endpoint would leave the other exposed.
Reproduction or Risk
Example risk flow:
- Discover the terminal host/port or a proxied WS path.
- Obtain or guess a valid session ID such as
ao-15. - Connect to:
- ttyd path via the terminal server flow that returns a session-specific URL, or
- direct WebSocket path such as
/ws?session=<id>or/ao-terminal-ws?session=<id>.
- The server validates the session ID format, resolves the tmux session, and attaches without verifying the caller's identity or ownership.
Even if session IDs are not trivially enumerable, they are user-facing identifiers that appear throughout the dashboard and logs. That makes "unguessable ID" an insufficient control here.
Recommended Fixes
1. Add a terminal auth token
Introduce a short-lived, signed terminal access token issued by the web app for a specific session and user context. The token should be required by both terminal server implementations before any tmux resolution or attach.
Recommended properties:
- Bound to
sessionId - Bound to the authenticated user or dashboard session
- Short TTL
- Single-purpose for terminal access
- Verifiable by both
terminal-websocket.tsanddirect-terminal-ws.ts
2. Enforce ownership checks
Use session metadata as part of authorization, not just discovery.
Recommended changes:
- Persist an ownership or access-control field in session metadata storage
- Resolve the requested session from metadata first
- Verify the authenticated caller is allowed to access that session before attaching
- Reject access before spawning or reusing ttyd / PTY resources
packages/core/src/metadata.ts is the obvious place to extend the metadata contract, but the storage layout under ~/.agent-orchestrator/{hash}-{projectId}/sessions/{sessionId} also needs a clear ownership model.
3. Add terminal-specific rate limiting
Apply rate limits to:
- Terminal URL/token issuance
- WebSocket connection attempts
- Invalid session/token failures
- Repeated attach attempts to the same session
This reduces brute-force session enumeration, reconnect storms, and abuse against PTY / ttyd processes.
4. Integrate with the direct WS endpoint, not just ttyd
The direct xterm.js endpoint in packages/web/server/direct-terminal-ws.ts must use the same auth and ownership enforcement as the ttyd-backed server in packages/web/server/terminal-websocket.ts.
Recommended approach:
- Centralize terminal authorization in shared server-side logic
- Make both implementations consume the same verifier
- Keep the client contract consistent so
Terminal.tsxandDirectTerminal.tsxboth request authorized terminal access the same way
If only the iframe/ttyd path is hardened, the direct WebSocket endpoint remains a bypass.
Observability Gaps
There is some connection/error telemetry already, but it is not sufficient for security response.
Add:
- Auth success/failure events
- Ownership check failure events
- Rate-limit denials
- User identity or actor ID in terminal audit events
- Session ID plus project ID correlation for all terminal access attempts
- Alerts or dashboards for repeated invalid session/token usage
Also consider distinguishing:
- token issuance failures
- websocket auth failures
- ownership denials
- attach/spawn failures after authorization succeeds
Next Steps
- Define the terminal authorization model: authenticated dashboard user, session owner, and optional shared-access cases.
- Extend session metadata and/or surrounding session state so ownership is explicit and queryable.
- Implement a shared terminal auth verifier used by both
terminal-websocket.tsanddirect-terminal-ws.ts. - Update
Terminal.tsxandDirectTerminal.tsxto request authorized terminal access instead of connecting with onlysessionId. - Add rate limiting and security telemetry before exposing terminal endpoints beyond trusted local-only workflows.
Notes
packages/web/server/terminal-websocket.ts already contains a TODO calling out authentication, ownership verification, and rate limiting. This document expands that TODO into a concrete security issue and makes clear that the same requirements apply to the direct WebSocket terminal path as well.
Closing this as part of the migration cleanup for the ground-up rewrite of Agent Orchestrator.
This item was opened more than a month before the migration batch and the codebase has been replaced, so this thread no longer maps cleanly onto the current source tree.
If something here still needs tracking, please reopen this item or open a fresh one against the new tree. Thank you for contributing.