Skip to content

fix(server): harden device channels, session cleanup, and agent tools - #1067

Queued
badcuban wants to merge 3 commits into
mainfrom
fix/device-server-audit
Queued

badcuban wants to merge 3 commits into
mainfrom
fix/device-server-audit

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Fixes server-side security, lifecycle, and reliability gaps in the Device panel (including the server review fixes that had stayed unmerged on feat/device-panel-server).

What was wrong

  • Device channel paths allowed control characters like \t/\n, letting WHATWG URL normalization traverse out of /vendor/serve-sim/helper/<id>/... with the hub's bearer token.
  • Several server lifecycle fixes (bound launcher override refusals, full teardown when turning agent access off, pendingReleases + dead-daemon PID checks, hub restart retry loop, stale-hub reaping, stdout-only token parsing, and strict WS channel registration/flow control) had not made it into main. A crashed agent-device daemon left sessions impossible to close.
  • Codex's default 60s MCP timeout aborted device_open during cold installs and simulator/emulator boots, iOS shake returned unsupported, Android permission reset silently revoked, and the app guide missed Round 2 device features.

How it's fixed

  • DeviceChannels: Reject control chars, whitespace, ?, #; tighten helper IDs to [A-Za-z0-9._-]+; assert canonical URL.pathname; validate WS subprotocols; register slots before dialing; hold strictly inside the 2 MiB window; fail slow before enqueuing oversized messages; allow the draining nextSeq at the 64-message limit; cap outbound bufferedAmount; keep surrogate pairs together; clean up handshake listeners.
  • DeviceService & LocalDeviceHost: Write claims.json (with pendingReleases) before mutating memory; check daemon PID liveness in releaseAgentSession and stopAgentDeviceDaemon; revoke launchers and agent-device.json under locks when agent access turns off (and re-check mid-boot); retry failed hub restarts with backoff and check hub liveness in currentHub; reap stale hubs at startup and shutdown; read hub token from stdout only and send Bearer on /readyz; register hub port before spawn and clear agent port only after stop; preserve a healthy hub's ready status when agent tool setup fails; guard settings watcher per change.
  • AgentDeviceShim: Refuse agent --session/-s/device/daemon override flags; strip --serial for Android cdp/connection; avoid matching positional -h on fill/type; write launchers atomically; hash non-plain IDs; forward signals; escape % on Windows.
  • Actions, Screenshots, Codex, Guide: Implement iOS shake via notifyutil; return unsupported for Android permission reset; use scoped temp files for Xcode 26 fallback screenshots; set Codex device MCP tool_timeout_sec=300; skip duplicate device listing in device_open; update device-tab guide topic and docs/design/devices.md.

Checks

  • vp fmt, vp lint (0 errors), vp run --cache '@threadlines/server#typecheck' (0 errors)
  • vp run --cache '@threadlines/server#test' Device (48/48 passed)
  • vp run --cache '@threadlines/server#test' PreviewTunnel (10/10 passed)
  • vp run --cache '@threadlines/server#test' guide (7/7 passed)
  • vp run --cache '@threadlines/server#test' codexAppServerArgs (3/3 passed)

Note: AgentDeviceShim.test.ts had an outdated assertion expecting open --session mine to override the bound session; updated to expect refusal per the bound-session requirement.

Lands the missing server review fixes from feat/device-panel-server alongside security and reliability fixes found in the live nightly audit:

- DeviceChannels: reject control characters and whitespace in device paths, tighten helper IDs to [A-Za-z0-9._-]+, verify canonical URL pathname, validate WS subprotocols, register WS channels before dialing the hub, stay inside the 2 MiB window, fail slow before enqueuing oversized messages, allow the draining nextSeq at the 64-message buffer limit, cap outbound bufferedAmount, keep UTF-16 surrogate pairs whole, and clean up handshake listeners.
- DeviceService & LocalDeviceHost: persist pendingReleases before updating in-memory claims, check daemon PID liveness before refusing session close, withdraw launchers and agent-device.json when agent access turns off (and re-check agent access before recording/binding), keep retrying failed hub restarts with backoff, verify hub liveness in currentHub, reap stale hubs on start and stop, read the hub token from stdout only with Bearer on /readyz, reserve own tool ports before spawn and clear agent port only after stop, and guard the settings watcher per change.
- AgentDeviceShim: refuse agent override flags (--session, -s, device/daemon flags), strip --serial for Android cdp/connection, stop matching positional -h on fill/type, write launchers atomically, hash non-plain IDs, forward SIGTERM/SIGINT, and escape % in Windows .cmd scripts.
- DeviceActions, DeviceHubOperations, Codex, Guide: implement iOS shake via notifyutil, reject Android permission reset instead of revoking, capture Xcode 26 fallback screenshots with a scoped temp file, set Codex device MCP tool_timeout_sec=300, drop redundant device listing on device_open, and update the device-tab guide topic.
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
threadlines Ready Ready Preview Nov 24, 2026 12:20am UTC

Request Review

# Conflicts:
#	apps/server/src/device/DeviceService.ts
TranscriptSelectionPopover focuses its note textarea inside requestAnimationFrame after Add note is clicked. On busy CI runners, userEvent.keyboard started typing before that frame ran, dropping characters or leaving the note empty so toggling Source dismissed it. Wait for the note input to have focus before typing.
@badcuban
badcuban added this pull request to the merge queue Nov 24, 2026
Any commits made after this event will not be merged.

This branch was successfully deployed

1 active deployment
Preview — e730c3c4 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant