Repository navigation
fix(server): enforce authorization on MCP retries #37822
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 all 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 |
|---|---|---|
|
|
@@ -161,24 +161,30 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | |
| const launchedModel = | ||
| launched === null || launched.deletedAt !== null ? undefined : launched.modelSelection; | ||
| const replaying = launchedModel !== undefined; | ||
| const project = replaying | ||
| ? undefined | ||
| : yield* Project.ProjectService.pipe( | ||
| Effect.flatMap((projects) => projects.getById(projectId)), | ||
| Effect.mapError(unavailable), | ||
| Effect.flatMap( | ||
| Option.match({ | ||
| onNone: () => | ||
| Effect.fail( | ||
| new OrchestratorMcpFailure({ | ||
| code: "invalid_request", | ||
| message: "The project was not found.", | ||
| }), | ||
| ), | ||
| onSome: Effect.succeed, | ||
| }), | ||
| ), | ||
| ); | ||
| if (launched !== null && replaying && launched.projectId !== projectId) | ||
| return yield* new OrchestratorMcpFailure({ | ||
| code: "invalid_request", | ||
| message: "A launch retry must use the original project.", | ||
| }); | ||
| const project = | ||
| replaying && input.workspaceStrategy?.type !== "existing_worktree" | ||
| ? undefined | ||
| : yield* Project.ProjectService.pipe( | ||
| Effect.flatMap((projects) => projects.getById(projectId)), | ||
| Effect.mapError(unavailable), | ||
| Effect.flatMap( | ||
| Option.match({ | ||
| onNone: () => | ||
| Effect.fail( | ||
| new OrchestratorMcpFailure({ | ||
| code: "invalid_request", | ||
| message: "The project was not found.", | ||
| }), | ||
| ), | ||
| onSome: Effect.succeed, | ||
| }), | ||
| ), | ||
| ); | ||
|
Comment on lines
+169
to
+187
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. Move retry scope validation into the launch service. The transport now decides when to load the project, validates the worktree, and dispatches the launch. Put this sequence in the existing launch-domain service. Keep the transport responsible for decoding and error mapping. This gives retry validation and replay one service owner. As per coding guidelines, “A transport handler does three things: decode the request, call one service method, and map the service's typed errors.” As per path instructions, “multi-step dispatch belong[s] in services, not handlers.”
|
||
| if (project !== undefined && input.workspaceStrategy?.type === "existing_worktree") | ||
| yield* assertProjectWorktree(project.workspaceRoot, input.workspaceStrategy.worktreePath); | ||
| if (!replaying && input.modelSelection !== undefined) { | ||
|
|
@@ -189,7 +195,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | |
| yield* OrchestrationMcp.requireAdvertisedModel(provider, model); | ||
| } | ||
| const projectSettings = | ||
| project === undefined | ||
| replaying || project === undefined | ||
| ? undefined | ||
| : yield* ServerSettings.ServerSettingsService.pipe( | ||
| Effect.flatMap((settings) => settings.getSettings), | ||
|
|
||
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.
Reject a replayed launch whose thread belongs to another project.
Two overlapping retries with the same
clientRequestIdand differentprojectIdvalues can both pass the mismatch guard inhandlers.ts. Both read no thread shell before either launch commits. The key derives the thread id and command id, so the secondthread.createreplays the first request's stored events.Orchestratorchecks only the thread id on replay, not the project. The post-claim check atThreadLaunchService.ts:1337-1339comparesproject.idwithinput.projectId, which is the same value, so it cannot detect the replayed thread's project. The second request can return the first project's thread.Validate the claimed thread's project after the claim and before the initial-message dispatch. Read the thread shell for the claimed
threadId. Reject the launch when itsprojectIddiffers frominput.projectId, using the same "Project identity changed." error path used atThreadLaunchService.ts:1241-1247.