Skip to content

Commit bb93073

Browse files
committed
fix(uploads): treat backslash as a key separator and mirror dot-segment rejection in the file-utils mock
1 parent fc4966a commit bb93073

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎apps/sim/lib/uploads/utils/context-prefix.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ describe('tryInferContextFromKey', () => {
2222
})
2323

2424
it('does not classify a dot-segment key by a prefix it escapes', () => {
25-
for (const key of ['og-images/../workspace/ws/a.pdf', 'profile-pictures/./x', 'kb/..']) {
25+
for (const key of [
26+
'og-images/../workspace/ws/a.pdf',
27+
'og-images/..\\workspace\\ws/a.pdf',
28+
'profile-pictures/./x',
29+
'kb/..',
30+
]) {
2631
expect(tryInferContextFromKey(key)).toBeNull()
2732
}
2833
})

‎apps/sim/lib/uploads/utils/file.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,12 +1092,13 @@ export function sanitizeStorageMetadata(
10921092
}
10931093

10941094
/**
1095-
* Whether a storage key has a `.` or `..` path segment. Such a key is never one the platform
1096-
* builds, and URL-based providers (Azure Blob) collapse the segments into a different object,
1097-
* so it must not reach a provider or pass a prefix-based authorization check.
1095+
* Whether a storage key has a `.` or `..` path segment, splitting on `\` as well as `/`. Such a
1096+
* key is never one the platform builds, and URL-based providers (Azure Blob) collapse the
1097+
* segments into a different object, so it must not reach a provider or pass a prefix-based
1098+
* authorization check.
10981099
*/
10991100
export function hasDotSegment(key: string): boolean {
1100-
return key.split('/').some((segment) => segment === '.' || segment === '..')
1101+
return key.split(/[/\\]/).some((segment) => segment === '.' || segment === '..')
11011102
}
11021103

11031104
/**

‎packages/testing/src/mocks/file-utils.mock.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,12 @@ function isInternalFileUrl(fileUrl: string): boolean {
393393
return path.startsWith('/api/files/serve/')
394394
}
395395

396+
function hasDotSegment(key: string): boolean {
397+
return key.split(/[/\\]/).some((segment) => segment === '.' || segment === '..')
398+
}
399+
396400
function tryInferContextFromKey(key: string): MockStorageContext | null {
397-
if (!key) return null
401+
if (!key || hasDotSegment(key)) return null
398402
if (key.startsWith('kb/') || key.startsWith('knowledge-base/')) return 'knowledge-base'
399403
if (key.startsWith('chat/')) return 'chat'
400404
if (key.startsWith('copilot/')) return 'copilot'
@@ -662,9 +666,7 @@ export const fileUtilsMockFns = {
662666
}
663667
return sanitized
664668
}),
665-
mockHasDotSegment: vi.fn((key: string) =>
666-
key.split('/').some((segment) => segment === '.' || segment === '..')
667-
),
669+
mockHasDotSegment: vi.fn(hasDotSegment),
668670
mockSanitizeFileKey: vi.fn((key: string) => {
669671
if (!key.includes('/')) {
670672
throw new Error('File key must include a context prefix (e.g., kb/, workspace/, execution/)')

0 commit comments

Comments
 (0)