Repository navigation
Description
Summary
When an adapter passes caller-supplied SessionOptions.resume into CLI argv as a separate token (or unguarded positional argument) without checking canonical ID shape or confirming the opened native session ID, a runtime whose --resume flag accepts an optional value or session title interprets options.resume as a CLI flag or title.
On Claude (packages/oar/src/runtimes/claude/launch.ts:42-47, packages/oar/src/runtimes/claude/session.ts:17,34, packages/oar/src/runtimes/claude/open-settings.ts:97-102,129-145 at main 7d0318ee), claudeSessionArgs passes ["--resume", sessionId] on plain resume and ["--resume", options.resume, "--fork-session", "--session-id", sessionId, ...] on fork as separate argv tokens (even though through on line 46 uses --resume-session-at=${through} specifically so dash-leading values cannot be parsed as flags), and claudeSession only runs confirmSessionId(sessionId) when options.fork !== undefined. Note that SessionOptions.resume is also reachable from external callers through oar mcp's run tool (packages/cli/src/mcp-tools.ts:53).
All live reproductions below ran on Linux x64 in isolated temporary HOME and workspace directories against local synthetic aimock HTTP providers with zero real credentials, accounts, or paid model calls.
Live Reproductions on Claude Code 2.1.326 and 2.1.328
1. CLI flag injection via options.resume on plain resume and fork
Claude's -r, --resume [value] takes an optional argument, and packages/oar/src/runtimes/claude/launch-args.ts:13-14 explicitly forbids -c and --continue ("OAR assigns the session id; use SessionOptions.resume with the id to continue"). Because claudeSessionArgs passes ["--resume", value] as two tokens, any dash-leading options.resume leaves --resume valueless and is parsed by Claude as a CLI flag:
- Plain resume hijack (
{ cwd, resume: "-c" }and{ cwd, resume: "--continue" }):
claudeRuntime.session(inst, { cwd, resume: "-c" })opens without error, attaches to and mutates the most recent saved session incwd(replaying its saved prompt/assistant history to the provider on the next turn), whilesession.id === "-c"and every emitted OAR record stampssessionId: "-c"even thoughsystem/init.session_idandget_statusreport the hijacked session's UUID. - Fork hijack (
{ cwd, resume: "-c", fork: {} }):
claudeRuntime.session(inst, { cwd, resume: "-c", fork: {} })spawnsclaude ... --resume -c --fork-session --session-id <new-uuid>.confirmSessionId(<new-uuid>)passes because--session-idassigns<new-uuid>to the forked transcript, and Claude silently forks the most recent saved session incwdinstead of failing on"-c". --flag=valuecontrol:
Passing--resume=-cprevents-cfrom being parsed as--continue; Claude exits immediately withError: --resume requires a valid session ID or session title when used with --print (-p). Provided value "-c" is not a UUID and does not match any session title.
2. Session title resolution (--name) and Session.id / record mismatch
Claude Code 2.1.326 and 2.1.328 resolve -p --resume <session-id|title> against saved session titles (SessionOptions.name / --name) as well as UUIDs:
- With a single saved session named
"UNIQUE_TITLE_ONE"(UUIDa1c1eea1-cb11-4dd0-be73-3481755f8074),claudeRuntime.session(inst, { cwd, resume: "UNIQUE_TITLE_ONE" })opens and mutatesa1c1eea1-...(replaying its transcript to the provider) while reportingsession.id === "UNIQUE_TITLE_ONE"and stampingsessionId: "UNIQUE_TITLE_ONE"on every OAR record (system/init.session_idreportsa1c1eea1-...). claudeRuntime.session(inst, { cwd, resume: "UNIQUE_TITLE_ONE", fork: {} })likewise resolves"UNIQUE_TITLE_ONE"by title and forksa1c1eea1-...into a new UUID.- When multiple saved sessions in
cwdshare the same title,--resume "<title>"fails startup listing their UUIDs (--resume "SOURCE_TITLE" matches 3 sessions...).
3. Missing-resume error drift for non-UUID values (open-settings.ts:97-101)
packages/oar/src/runtimes/claude/open-settings.ts:97-101 classifies SessionNotFoundError by matching native.errors[0].startsWith("No conversation found with session ID") (pinned by tests/fixtures/claude-missing-resume.json, which uses "claude-resume-secret-sentinel").
On live Claude Code 2.1.326 and 2.1.328:
- A missing canonical UUID (
"00000000-0000-4000-8000-000000000099") still emits"No conversation found with session ID: ..."and throwsSessionNotFoundError. - Any non-UUID string that matches no title (including
"claude-resume-secret-sentinel") now emits'Error: --resume requires a valid session ID or session title when used with --print (-p). Provided value "..." is not a UUID and does not match any session title.', soopen-settings.ts:102throws a plainErrorinstead ofSessionNotFoundError.
4. confirmSessionId redaction and error-cause gap (open-settings.ts:140-141)
Unlike confirm() (open-settings.ts:80,93-102), confirmSessionId throws new Error(refusal) directly without passing refusal through sessionCredentialRedactor(options) or attaching nativeErrorCause("get_status", ...).
Cross-Runtime Audit of the Class (SessionOptions.resume)
Checked all 14 core runtimes at 7d0318ee (static audit of all 14 plus live adversarial probes with "", "-c", "--continue", "--help", "UNIQUE_TITLE_ONE", and "id\0<secret>" across claude 2.1.326/2.1.328, codex 0.169.0/0.170.0, qwen 0.27.4, qoder 1.1.81, opencode 1.19.5, grok 1.0.70, kimi 2.6.3, factory 1.12.1, dsh 0.2.1-rc.5, pi-durable 1.5.2, and antigravity 1.5.11):
- OpenCode v1 (
packages/oar/src/runtimes/opencode/prompt-config.ts:77): Secondaryargvinstance whenoptions.systemPromptis combined withoptions.resume.query(command, ["export", options.resume, "--sanitize"], ...)spawnsopencode exportbefore opening ACP:resume: ""causesopencode 1.19.5exportto treatsessionIDas omitted, launch its interactive TUI (Select session to export), and hang for the full30_000 mstimeout beforeSIGTERM.resume: "-c"/"--continue"/"--help"is parsed as a yargs CLI flag byopencode export(--helpprints help text to stdout and failsJSON.parse).
- Qwen (
packages/oar/src/runtimes/qwen/launch.ts:16,qwen/session.ts:57) and Qoder (packages/oar/src/runtimes/qoder/launch.ts:52): Both also pass["--resume", sessionId]as two tokens inargv(on Qoder whenprotocol !== "daemon"). Liveqwen 0.27.4andqoder 1.1.81rejected all 6 adversarial inputs, andqwen/session.ts:57already verifiesnative?.session_id === sessionId, but using--resume=${sessionId}(or shared input validation) removes any reliance on native flag-parser details. - Codex, Grok, Kimi, Factory, DSH, Pi, Pi Durable, Antigravity, Cursor, Devin, CodeBuddy: Pass
resumeover structured JSON-RPC / SDK calls or validate session ID format before launch; all live probes rejected all 6 inputs without opening a session or leaking credentials.
Suggested Direction (Fix the Class)
- Guard CLI
resumearguments with one shared check (rejecting empty, NUL-containing, or dash-leading strings before spawning any child process, includingopencode/prompt-config.ts:77) and pass--resume=${...}inclaude/launch.ts:44,46(andqwen/launch.ts:16/qoder/launch.ts:52if supported by their parsers, verified against native binaries). - On Claude, enforce canonical session ID identity (either rejecting non-UUID
options.resumelike Codex or runningconfirmSessionId(sessionId)on plain resume as well as fork so title-resolved mismatches cannot slip through with a wrongSession.id), align non-UUID missing-resume handling withSessionNotFoundError, and wiresessionCredentialRedactor(options)+nativeErrorCauseintoconfirmSessionId. - Add a cross-runtime
SessionOptions.resumecontract test covering"","-c","--continue", and non-ID title strings across adapters.
Lookout opened this issue through Stamp · server
open-agent-runtime
Activity
fix(session): validate resume ids, pass --flag=value argv, and confir…