Skip to content

Never signal a recycled bridge PID, and wait for the bridge's teardown before SIGKILL - #485

Open
jancurn wants to merge 1 commit into
mainfrom
claude/next-security-issue-skfeaa
Open

jancurn wants to merge 1 commit into
mainfrom
claude/next-security-issue-skfeaa

Conversation

@jancurn

@jancurn jancurn commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

A restart or close could kill an unrelated process: sessions.json remembers each bridge by PID, the OS recycles PIDs after a reboot, and stopBridge() SIGTERMed/SIGKILLed whatever had that number once the socket did not answer. The old bridge was also force-killed one second after SIGTERM, before its HTTP DELETE or the SDK's stdio child shutdown could finish, orphaning the child.

  • New src/lib/bridge-process.ts: a PID is signalled only after it is confirmed to be the session's bridge (its IPC socket answers, or its command line names the bridge script followed by the session name)
  • stopBridge, ensureBridgeReady and consolidateSessions treat a recycled or dead PID as a crashed bridge, so the session reconnects and the stranger is left alone
  • stopBridge polls for exit for up to 10 s (the bridge's own teardown budget) before SIGKILL
  • Unit tests with real sockets and processes, plus test/e2e/suites/basic/bridge-pid-reuse.test.sh

Fixes M5 and M6 of docs/security-review-2026-09.md. Refs #427 (the self-exiting superseded bridge this builds on). A separate resumed-session bug found on the way is filed as #484.

🤖 Generated with Claude Code

https://claude.ai/code/session_015KycPokdVYqq2t5iGAiDxY

…n before SIGKILL

sessions.json remembers each bridge by PID, and the CLI trusted that number:
after a reboot (or a PID wrap) it belongs to whatever the OS started next, and
`process.kill(pid, 0)` says "alive", so a command on a stale session failed to
reach the socket and SIGTERMed/SIGKILLed an unrelated process on its way to a
restart. The old bridge was also force-killed one second after SIGTERM, before
it could finish the HTTP DELETE that ends the server-side session or the SDK's
close-stdin → SIGTERM → SIGKILL escalation for a stdio child, orphaning it.

New `identifyBridgeProcess()` (src/lib/bridge-process.ts) runs before any PID
is signalled or trusted: it connects to the PID-specific IPC socket (a Windows
named pipe cannot outlive its process; on Unix the stale file is probed, not
trusted) and, when nothing listens there, reads the process command line
(/proc/<pid>/cmdline on Linux, ps elsewhere), which must name the bridge script
immediately followed by the session name. stopBridge(), ensureBridgeReady() and
consolidateSessions() treat a recycled or dead PID as a crashed bridge, so the
session reconnects and the stranger is left alone. stopBridge() then polls for
up to 10 s — the bridge's own teardown budget — before SIGKILL.

Fixes M5 and M6 of docs/security-review-2026-09.md. Covered by unit tests with
real sockets and processes and by test/e2e/suites/basic/bridge-pid-reuse.test.sh.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015KycPokdVYqq2t5iGAiDxY
@jancurn jancurn changed the title Prevent signalling recycled PIDs and ensure graceful bridge shutdown Never signal a recycled bridge PID, and wait for the bridge's teardown before SIGKILL Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant