Repository navigation
feat(daemon): guard cross-worktree Git mutations #8687
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
Changes from 48 commits
2480163
2b0e8cd
107b5f6
b175cd7
2af7419
b1b7606
83428be
18e997a
ab1e3e2
45753e0
c14ffc4
7f66be6
b11585b
dfeb461
af36eca
8112fae
338e0c7
d9a3911
012d252
2bf64cd
0a58fe7
cbcde28
3a247f7
a1652cc
581d2bb
6b755d1
8baf7a7
0f970d4
8e46dba
089c3e3
a2736b8
cf2ea23
7f4746f
6273464
01587ab
2f0b99f
a2ae8bb
6deb8bd
a43faa8
1203072
e595f7b
70f5162
68eb534
3333331
636602c
5fc219d
6128e69
d95d87c
a5f8099
c7b6aa4
a0427ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -603,6 +603,8 @@ function sliceLineRange( | |
| */ | ||
| export interface BridgeClientSessionEntry { | ||
| sessionId: string; | ||
| workspaceCwd: string; | ||
| effectiveCwd: string; | ||
| events: EventBus; | ||
| artifacts: SessionArtifactStore; | ||
| recordingDegraded: boolean; | ||
|
|
@@ -1297,8 +1299,8 @@ export class BridgeClient implements Client { | |
| if ( | ||
| typeof sessionId !== 'string' || | ||
| sessionId.length === 0 || | ||
| typeof promptId !== 'string' || | ||
| promptId.length === 0 || | ||
| (promptId !== undefined && | ||
| (typeof promptId !== 'string' || promptId.length === 0)) || | ||
| typeof toolCallId !== 'string' || | ||
| toolCallId.length === 0 || | ||
| typeof toolName !== 'string' || | ||
|
|
@@ -1310,32 +1312,49 @@ export class BridgeClient implements Client { | |
| 'Invalid external tool guard request', | ||
| ); | ||
| } | ||
| // Context-less shell checks (subagents, cron turns, resumed background | ||
| // agents) carry no prompt binding; they are validated by session | ||
| // ownership alone. The host handler decides whether its policy can run | ||
| // without a live prompt. | ||
| const promptScoped = promptId !== undefined; | ||
| if (!this.ownsSession(sessionId)) { | ||
| throw RequestError.invalidParams( | ||
| undefined, | ||
| 'External tool guard session is not owned by this connection', | ||
| ); | ||
| } | ||
| const entry = this.resolveEntry(sessionId); | ||
| if (!entry || !entry.promptActive || entry.activePromptId !== promptId) { | ||
| if ( | ||
| !entry || | ||
|
Collaborator
Author
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. [Critical] R2-16: Prompt-less guard requests accept any sibling sessionId owned by the same multiplexed BridgeClient channel. Failure scenario: Context-less work originating in session A supplies session B's id; channel ownership passes, and the guard receives B's trusted effectiveCwd, allowing mutation of B's checkout. Suggested fix: Bind every context-less request to host-owned originating-session state rather than trusting a child-supplied sessionId. 中文说明无 prompt 的守卫请求会接受同一复用 失败场景:来自会话 A 的无上下文工作可提交会话 B 的 ID;通道所有权检查会通过,守卫随后使用 B 受信任的 建议修复:将每个无上下文请求绑定到宿主持有的发起会话状态,不要信任子进程提供的 — gpt-5.6-sol via Qwen Code /review (v0.21.9) |
||
| (promptScoped && | ||
| (!entry.promptActive || entry.activePromptId !== promptId)) | ||
| ) { | ||
|
Comment on lines
1326
to
+1331
Collaborator
Author
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. [Suggestion] R6-S3: On the new prompt-less path (promptScoped=false) both rejection messages reference a prompt the request does not carry: a missing entry is rejected with 'External tool guard prompt is not the active prompt' and a replaced entry with '…no longer active' — the actual cause is session-entry lifecycle. — Failure scenario: An operator diagnosing denied subagent/cron/resumed-agent shell calls is pointed at prompt binding when the cause is a missing or changed session entry. Suggested fix: When !promptScoped, use entry-scoped messages ('session has no live entry' / 'session entry changed during evaluation'). 中文说明新的无 prompt 路径(promptScoped=false)上,两条拒绝消息都在引用请求根本未携带的 prompt:条目缺失被拒为 'External tool guard prompt is not the active prompt',条目被替换被拒为 '…no longer active'——真实原因是会话条目生命周期。后果:排查子代理/cron/恢复后台代理 shell 调用被拒的运维会被引向 prompt 绑定而非会话条目状态。修复:!promptScoped 时改用会话条目语义的消息('session has no live entry' / 'session entry changed during evaluation')。 — qwen3.8-max via Qwen Code /review (v0.21.10) |
||
| throw RequestError.invalidParams( | ||
| undefined, | ||
| 'External tool guard prompt is not the active prompt', | ||
| ); | ||
| } | ||
| const invocationCwd = params['invocationCwd']; | ||
| const decision: unknown = await this.externalToolGuard({ | ||
| sessionId: entry.sessionId, | ||
| promptId: entry.activePromptId, | ||
| ...(promptScoped ? { promptId } : {}), | ||
| toolCallId, | ||
| toolName, | ||
| arguments: args, | ||
| effectiveCwd: entry.effectiveCwd, | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| // Forwarded verbatim and explicitly untrusted: the host policy decides | ||
| // whether it can establish this scope from state it owns. | ||
| ...(typeof invocationCwd === 'string' && invocationCwd.length > 0 | ||
|
Collaborator
Author
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. [Critical] R2-3: A child-reported invocationCwd is accepted by containment alone instead of being bound to the invoking agent's assigned worktree. Failure scenario: An agent assigned to worktree A reports sibling worktree B as invocationCwd; the daemon accepts the session-owned path and authorizes a mutating Git command against B. Suggested fix: Derive the invocation boundary from host-owned agent/session state and reject child-reported directories that do not exactly match that assignment. 中文说明子进程上报的 失败场景:分配到 worktree A 的 agent 可将兄弟 worktree B 上报为 建议修复:从宿主持有的 agent/session 状态推导调用边界,并拒绝与该分配不完全一致的子进程上报目录。 — gpt-5.6-sol via Qwen Code /review (v0.21.9)
Collaborator
Author
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. [Suggestion] R2-14: Bridge tests do not verify invocationCwd reaches the daemon handler together with effectiveCwd. Concrete cost: A transport regression can drop or rename invocationCwd while lower-layer guard tests remain green and worktree-pinned agents are checked against the wrong boundary. Suggested fix: Add a bridge-level regression test asserting both cwd fields and their session binding at the handler. 中文说明Bridge 测试没有验证 具体代价:传输层回归可能丢弃或重命名 建议修复:增加 bridge 层回归测试,在 handler 处断言两个 cwd 字段及其 session 绑定。 — gpt-5.6-sol via Qwen Code /review (v0.21.9) |
||
| ? { invocationCwd } | ||
| : {}), | ||
| }); | ||
| const currentEntry = this.resolveEntry(sessionId); | ||
| if ( | ||
| !this.ownsSession(sessionId) || | ||
| currentEntry !== entry || | ||
| !currentEntry.promptActive || | ||
| currentEntry.activePromptId !== promptId | ||
| (promptScoped && | ||
| (!currentEntry.promptActive || | ||
| currentEntry.activePromptId !== promptId)) | ||
| ) { | ||
| throw RequestError.invalidParams( | ||
| undefined, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.