Skip to content

Commit 35bc843

Browse files
committed
fix(file-serve): remove user-controlled context param from authenticated path
The `?context` query param was still being passed to `handleCloudProxy` in the authenticated code path, allowing any logged-in user to spoof context as `profile-pictures` and bypass ownership checks in `verifyFileAccess`. Now always use `inferContextFromKey` from the server-controlled key prefix.
1 parent c5ecc19 commit 35bc843

File tree

1 file changed

+3
-12
lines changed
  • apps/sim/app/api/files/serve/[...path]

1 file changed

+3
-12
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export async function GET(
106106
return await handleLocalFilePublic(fullPath)
107107
}
108108

109-
const contextParam = request.nextUrl.searchParams.get('context')
110109
const raw = request.nextUrl.searchParams.get('raw') === '1'
111110

112111
const authResult = await checkSessionOrInternalAuth(request, { requireWorkflowId: false })
@@ -122,7 +121,7 @@ export async function GET(
122121
const userId = authResult.userId
123122

124123
if (isUsingCloudStorage()) {
125-
return await handleCloudProxy(cloudKey, userId, contextParam, raw)
124+
return await handleCloudProxy(cloudKey, userId, raw)
126125
}
127126

128127
return await handleLocalFile(cloudKey, userId, raw)
@@ -194,19 +193,11 @@ async function handleLocalFile(
194193
async function handleCloudProxy(
195194
cloudKey: string,
196195
userId: string,
197-
contextParam?: string | null,
198196
raw = false
199197
): Promise<NextResponse> {
200198
try {
201-
let context: StorageContext
202-
203-
if (contextParam) {
204-
context = contextParam as StorageContext
205-
logger.info(`Using explicit context: ${context} for key: ${cloudKey}`)
206-
} else {
207-
context = inferContextFromKey(cloudKey)
208-
logger.info(`Inferred context: ${context} from key pattern: ${cloudKey}`)
209-
}
199+
const context = inferContextFromKey(cloudKey)
200+
logger.info(`Inferred context: ${context} from key pattern: ${cloudKey}`)
210201

211202
const hasAccess = await verifyFileAccess(
212203
cloudKey,

0 commit comments

Comments
 (0)