Skip to content

Commit 3e1bdbc

Browse files
committed
Address PR review feedback (#5615)
- Reject chat uploads that belong to another workspace - Add regression coverage for media upload ownership
1 parent 5ac760f commit 3e1bdbc

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

apps/sim/lib/copilot/tools/server/media/file-paths.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
validateMediaOutputFile,
2929
} from '@/lib/copilot/tools/server/media/file-paths'
3030

31-
const FILE_RECORD = { id: 'wf_file', name: 'portrait.png' }
31+
const FILE_RECORD = { id: 'wf_file', name: 'portrait.png', workspaceId: 'workspace-1' }
3232

3333
describe('media file paths', () => {
3434
beforeEach(() => {
@@ -65,6 +65,20 @@ describe('media file paths', () => {
6565
expect(mocks.resolveChatUpload).toHaveBeenCalledWith('My%20Portrait.png', 'chat-1')
6666
})
6767

68+
it('rejects uploads from a different workspace', async () => {
69+
mocks.resolveChatUpload.mockResolvedValue({ ...FILE_RECORD, workspaceId: 'workspace-2' })
70+
71+
await expect(
72+
resolveMediaInputFile({
73+
workspaceId: 'workspace-1',
74+
chatId: 'chat-1',
75+
path: 'uploads/My%20Portrait.png',
76+
})
77+
).rejects.toThrow(
78+
'Upload does not belong to the current workspace: "uploads/My%20Portrait.png"'
79+
)
80+
})
81+
6882
it('rejects unresolved inputs instead of dropping them', async () => {
6983
mocks.resolveWorkspaceFileReference.mockResolvedValue(null)
7084

apps/sim/lib/copilot/tools/server/media/file-paths.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export async function resolveMediaInputFile(args: {
5757
throw new Error(`Chat context is required for upload input: ${path}`)
5858
}
5959
file = await resolveChatUpload(filename, args.chatId)
60+
if (file && file.workspaceId !== args.workspaceId) {
61+
throw new Error(`Upload does not belong to the current workspace: "${path}"`)
62+
}
6063
} else {
6164
file = await resolveWorkspaceFileReference(args.workspaceId, path)
6265
}

apps/sim/lib/copilot/tools/server/media/media-tools-validation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const UPLOAD_RECORD = {
3838
id: 'wf_upload',
3939
name: 'start.png',
4040
type: 'image/png',
41+
workspaceId: 'workspace-1',
4142
storageContext: 'mothership',
4243
}
4344

0 commit comments

Comments
 (0)