Skip to content

Commit 6f43fc9

Browse files
waleedlatif1claude
andcommitted
fix: prevent auth bypass via user-controlled context query param in file serve
The /api/files/serve endpoint trusted a user-supplied `context` query parameter to skip authentication. An attacker could append `?context=profile-pictures` to any file URL and download files without auth. Now the public access gate checks the key prefix instead of the query param, and `og-images/` is added to `inferContextFromKey`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bf60670 commit 6f43fc9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

apps/sim/app/api/files/serve/[...path]/route.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ export async function GET(
9797
const contextParam = request.nextUrl.searchParams.get('context')
9898
const raw = request.nextUrl.searchParams.get('raw') === '1'
9999

100-
const context = contextParam || (isCloudPath ? inferContextFromKey(cloudKey) : undefined)
100+
const isPublicByKeyPrefix =
101+
cloudKey.startsWith('profile-pictures/') || cloudKey.startsWith('og-images/')
101102

102-
if (context === 'profile-pictures' || context === 'og-images') {
103+
if (isPublicByKeyPrefix) {
104+
const context = inferContextFromKey(cloudKey)
103105
logger.info(`Serving public ${context}:`, { cloudKey })
104106
if (isUsingCloudStorage() || isCloudPath) {
105107
return await handleCloudProxyPublic(cloudKey, context)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,11 @@ export function inferContextFromKey(key: string): StorageContext {
419419
if (key.startsWith('execution/')) return 'execution'
420420
if (key.startsWith('workspace/')) return 'workspace'
421421
if (key.startsWith('profile-pictures/')) return 'profile-pictures'
422+
if (key.startsWith('og-images/')) return 'og-images'
422423
if (key.startsWith('logs/')) return 'logs'
423424

424425
throw new Error(
425-
`File key must start with a context prefix (kb/, chat/, copilot/, execution/, workspace/, profile-pictures/, or logs/). Got: ${key}`
426+
`File key must start with a context prefix (kb/, chat/, copilot/, execution/, workspace/, profile-pictures/, og-images/, or logs/). Got: ${key}`
426427
)
427428
}
428429

0 commit comments

Comments
 (0)