Skip to content

Commit 0431370

Browse files
committed
fix(copilot): re-resolve workspace access after the download instead of reusing it
The pre-download access check cannot stand in for the write-time one: the fetch in between can be long, and a permission revoked during it must still block the write. create_file keeps the reuse, where nothing awaits between the two.
1 parent e78cdff commit 0431370

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

apps/sim/lib/copilot/tools/server/files/download-to-workspace-file.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ export const downloadToWorkspaceFileServerTool: BaseServerTool<
152152
if (!workspaceId) {
153153
return { success: false, message: 'Workspace ID is required' }
154154
}
155-
const workspaceAccess = await ensureWorkspaceAccess(workspaceId, context.userId, 'write')
155+
// Intentionally not reused for the write below: the download in between can be long, so the
156+
// writer re-resolves access at write time and a revocation mid-download blocks the write.
157+
await ensureWorkspaceAccess(workspaceId, context.userId, 'write')
156158

157159
try {
158160
assertServerToolNotAborted(context)
@@ -192,7 +194,6 @@ export const downloadToWorkspaceFileServerTool: BaseServerTool<
192194
const written = await writeWorkspaceFileByPath({
193195
workspaceId,
194196
userId: context.userId,
195-
workspaceAccess,
196197
target: {
197198
path: outputPath,
198199
mode: outputFile?.mode ?? 'create',

0 commit comments

Comments
 (0)