-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Drop poisoned shell-wrapper restore commands #6012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1889,6 +1889,32 @@ final class SessionPersistenceTests: XCTestCase { | |
| } | ||
|
|
||
| final class SocketListenerAcceptPolicyTests: XCTestCase { | ||
| func testPersistedAgentSnapshotDropsShellWrapperLaunchCommandWhenRenderingResume() { | ||
| let snapshot = SessionRestorableAgentSnapshot( | ||
| kind: .codex, | ||
| sessionId: "codex-session-123", | ||
| workingDirectory: "/tmp/repo", | ||
| launchCommand: AgentLaunchCommandSnapshot( | ||
| launcher: "codex", | ||
| executablePath: "bash", | ||
| arguments: [ | ||
| "bash", | ||
| "-c", | ||
| "payload=\"$1\"; shift; \"$@\" <\"$payload\" &", | ||
| ], | ||
| workingDirectory: "/tmp/dispatch-shell", | ||
| environment: ["CODEX_HOME": "/tmp/codex"], | ||
| capturedAt: 123, | ||
| source: "process" | ||
| ) | ||
| ) | ||
|
|
||
| XCTAssertEqual( | ||
| snapshot.resumeCommand, | ||
| "{ cd -- '/tmp/repo' 2>/dev/null || [ ! -d '/tmp/repo' ]; } && 'codex' 'resume' 'codex-session-123'" | ||
| ) | ||
| } | ||
|
|
||
| func testClaudeResumeCommandRoutesThroughWrapperInsteadOfCapturedRealBinary() { | ||
| // The captured launch executable is the real claude binary | ||
| // (CMUX_AGENT_LAUNCH_EXECUTABLE). Resuming with it directly bypasses | ||
|
Comment on lines
1994
to
2025
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
@@ -5796,6 +5822,88 @@ extension SessionPersistenceTests { | |
| ) | ||
| } | ||
|
|
||
| @MainActor | ||
| func testRestoreDropsPoisonedAgentHookShellWrapperResumeBindingAndUsesAgentSnapshot() throws { | ||
| try withAutoResumeAgentSessionsEnabled { | ||
| let source = Workspace() | ||
| let sourcePanelId = try XCTUnwrap(source.focusedPanelId) | ||
| let sessionId = "019eba43-1e37-78d2-98df-d1983200273d" | ||
| let sourceIndex = try makeRestorableAgentIndex( | ||
| workspaceId: source.id, | ||
| panelId: sourcePanelId, | ||
| sessionId: sessionId, | ||
| arguments: [ | ||
| "/usr/local/bin/codex", | ||
| "--yolo", | ||
| ] | ||
| ) | ||
| let bindingIndex = SurfaceResumeBindingIndex(bindingsByPanel: [ | ||
| SurfaceResumeBindingIndex.PanelKey(workspaceId: source.id, panelId: sourcePanelId): SurfaceResumeBindingSnapshot( | ||
| name: "Codex", | ||
| kind: "codex", | ||
| command: "{ cd -- '/Users/lawrence/fun/cmuxterm-hq' 2>/dev/null || [ ! -d '/Users/lawrence/fun/cmuxterm-hq' ]; } && 'bash' 'resume' '\(sessionId)' '-c' 'payload=\"$1\"; shift; \"$@\" <\"$payload\" &'", | ||
| cwd: "/Users/lawrence/fun/cmuxterm-hq", | ||
| checkpointId: sessionId, | ||
| source: "agent-hook", | ||
| autoResume: true, | ||
| updatedAt: 10 | ||
| ), | ||
| ]) | ||
| let snapshot = source.sessionSnapshot( | ||
| includeScrollback: false, | ||
| restorableAgentIndex: sourceIndex, | ||
| surfaceResumeBindingIndex: bindingIndex | ||
| ) | ||
|
|
||
| let restored = Workspace() | ||
| restored.restoreSessionSnapshot(snapshot) | ||
| let restoredPanelId = try XCTUnwrap(restored.focusedPanelId) | ||
| let restoredPanel = try XCTUnwrap(restored.terminalPanel(for: restoredPanelId)) | ||
| let payload = try restoredStartupPayload(for: restoredPanel) | ||
|
|
||
| XCTAssertTrue(payload.contains("/usr/local/bin/codex"), payload) | ||
| XCTAssertTrue(payload.contains("resume"), payload) | ||
| XCTAssertTrue(payload.contains(sessionId), payload) | ||
| XCTAssertTrue(payload.contains("--yolo"), payload) | ||
| XCTAssertFalse(payload.contains("'bash' 'resume'"), payload) | ||
| XCTAssertNil(restored.sessionSnapshot(includeScrollback: false).panels.first?.terminal?.resumeBinding) | ||
| } | ||
| } | ||
|
|
||
| @MainActor | ||
| func testRestoreDropsPoisonedAgentHookShellWrapperResumeBindingWithoutAgentSnapshot() throws { | ||
| try withAutoResumeAgentSessionsEnabled { | ||
| let source = Workspace() | ||
| let sourcePanelId = try XCTUnwrap(source.focusedPanelId) | ||
| let sessionId = "019eb982-d798-7123-aa2b-93326ff3bd08" | ||
| let bindingIndex = SurfaceResumeBindingIndex(bindingsByPanel: [ | ||
| SurfaceResumeBindingIndex.PanelKey(workspaceId: source.id, panelId: sourcePanelId): SurfaceResumeBindingSnapshot( | ||
| name: "Codex", | ||
| kind: "codex", | ||
| command: "{ cd -- '/Users/lawrence/fun/cmuxterm-hq' 2>/dev/null || [ ! -d '/Users/lawrence/fun/cmuxterm-hq' ]; } && 'sh' 'resume' '\(sessionId)' '-c' 'payload=\"$1\"; shift; \"$@\" <\"$payload\" &'", | ||
| cwd: "/Users/lawrence/fun/cmuxterm-hq", | ||
| checkpointId: sessionId, | ||
| source: "agent-hook", | ||
| autoResume: true, | ||
| updatedAt: 10 | ||
| ), | ||
| ]) | ||
| let snapshot = source.sessionSnapshot( | ||
| includeScrollback: false, | ||
| surfaceResumeBindingIndex: bindingIndex | ||
| ) | ||
|
|
||
| let restored = Workspace() | ||
| restored.restoreSessionSnapshot(snapshot) | ||
| let restoredPanelId = try XCTUnwrap(restored.focusedPanelId) | ||
| let restoredPanel = try XCTUnwrap(restored.terminalPanel(for: restoredPanelId)) | ||
|
|
||
| XCTAssertNil(restoredPanel.surface.debugInitialCommand()) | ||
| XCTAssertFalse(restoredPanel.surface.debugInitialInputMetadata().hasInitialInput) | ||
| XCTAssertNil(restored.sessionSnapshot(includeScrollback: false).panels.first?.terminal?.resumeBinding) | ||
| } | ||
| } | ||
|
|
||
| @MainActor | ||
| func testRestoreScopesSurfaceResumeBindingEnvironmentToInitialInput() throws { | ||
| let source = Workspace() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fishincluded in shell set may cause false positivesfishis listed alongside traditional POSIX shells, butfish resume <session>is a plausible legitimate invocation for a user whose agent-hook command genuinely calls a Fish script namedresume. BecauseagentHookBindingLooksLikeShellWrapperResumeonly fires forisAgentHookBindingbindings, the blast radius is narrow, butfishdoes not appear in the original poisoned binding pattern described in the PR (bash resume …) and adding it increases the heuristic surface without a concrete motivating case.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!