Skip to content

Commit d6feccb

Browse files
committed
fix(storage): review round 2 — route chat authz and execution-URL detection through getStorageConfig
- getChatStorageConfig delegates to getStorageConfig('chat') (identical for S3/Azure, picks up the GCS general-bucket fallback instead of reading the raw chat config and rejecting valid chat files) - parse route resolves the execution bucket via getStorageConfig('execution') for all providers, so GCS execution files in the fallback bucket are still recognized as our own objects
1 parent 524722a commit d6feccb

3 files changed

Lines changed: 15 additions & 45 deletions

File tree

apps/sim/app/api/files/authorization.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ vi.mock('@/lib/uploads', () => ({
2727
}))
2828

2929
vi.mock('@/lib/uploads/config', () => ({
30-
BLOB_CHAT_CONFIG: {},
31-
S3_CHAT_CONFIG: {},
30+
getStorageConfig: vi.fn(() => ({})),
3231
}))
3332

3433
vi.mock('@/lib/uploads/server/metadata', () => ({

apps/sim/app/api/files/authorization.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { and, eq, isNull } from 'drizzle-orm'
66
import { NextResponse } from 'next/server'
77
import { getFileMetadata } from '@/lib/uploads'
88
import type { StorageContext } from '@/lib/uploads/config'
9-
import { BLOB_CHAT_CONFIG, S3_CHAT_CONFIG } from '@/lib/uploads/config'
109
import type { StorageConfig } from '@/lib/uploads/core/storage-client'
1110
import { getFileMetadataByKey } from '@/lib/uploads/server/metadata'
1211
import { inferContextFromKey } from '@/lib/uploads/utils/file-utils'
@@ -781,30 +780,6 @@ export async function assertToolFileAccess(
781780
* Get chat storage configuration based on current storage provider
782781
*/
783782
async function getChatStorageConfig(): Promise<StorageConfig> {
784-
const { USE_S3_STORAGE, USE_BLOB_STORAGE, USE_GCS_STORAGE } = await import('@/lib/uploads/config')
785-
786-
if (USE_BLOB_STORAGE) {
787-
return {
788-
containerName: BLOB_CHAT_CONFIG.containerName,
789-
accountName: BLOB_CHAT_CONFIG.accountName,
790-
accountKey: BLOB_CHAT_CONFIG.accountKey,
791-
connectionString: BLOB_CHAT_CONFIG.connectionString,
792-
}
793-
}
794-
795-
if (USE_S3_STORAGE) {
796-
return {
797-
bucket: S3_CHAT_CONFIG.bucket,
798-
region: S3_CHAT_CONFIG.region,
799-
}
800-
}
801-
802-
if (USE_GCS_STORAGE) {
803-
const { GCS_CHAT_CONFIG } = await import('@/lib/uploads/config')
804-
return {
805-
bucket: GCS_CHAT_CONFIG.bucket,
806-
}
807-
}
808-
809-
return {}
783+
const { getStorageConfig } = await import('@/lib/uploads/config')
784+
return getStorageConfig('chat')
810785
}

apps/sim/app/api/files/parse/route.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -489,28 +489,24 @@ async function handleExternalUrl(
489489
try {
490490
logger.info('Fetching external URL:', url)
491491

492-
const {
493-
S3_EXECUTION_FILES_CONFIG,
494-
BLOB_EXECUTION_FILES_CONFIG,
495-
GCS_EXECUTION_FILES_CONFIG,
496-
USE_S3_STORAGE,
497-
USE_BLOB_STORAGE,
498-
USE_GCS_STORAGE,
499-
} = await import('@/lib/uploads/config')
492+
const { getStorageConfig, USE_S3_STORAGE, USE_BLOB_STORAGE, USE_GCS_STORAGE } = await import(
493+
'@/lib/uploads/config'
494+
)
495+
const executionConfig = getStorageConfig('execution')
500496

501497
let isExecutionFile = false
502498
try {
503499
const parsedUrl = new URL(url)
504500

505-
if (USE_S3_STORAGE && S3_EXECUTION_FILES_CONFIG.bucket) {
506-
const bucketInHost = parsedUrl.hostname.startsWith(S3_EXECUTION_FILES_CONFIG.bucket)
507-
const bucketInPath = parsedUrl.pathname.startsWith(`/${S3_EXECUTION_FILES_CONFIG.bucket}/`)
501+
if (USE_S3_STORAGE && executionConfig.bucket) {
502+
const bucketInHost = parsedUrl.hostname.startsWith(executionConfig.bucket)
503+
const bucketInPath = parsedUrl.pathname.startsWith(`/${executionConfig.bucket}/`)
508504
isExecutionFile = bucketInHost || bucketInPath
509-
} else if (USE_BLOB_STORAGE && BLOB_EXECUTION_FILES_CONFIG.containerName) {
510-
isExecutionFile = url.includes(`/${BLOB_EXECUTION_FILES_CONFIG.containerName}/`)
511-
} else if (USE_GCS_STORAGE && GCS_EXECUTION_FILES_CONFIG.bucket) {
512-
const bucketInHost = parsedUrl.hostname.startsWith(`${GCS_EXECUTION_FILES_CONFIG.bucket}.`)
513-
const bucketInPath = parsedUrl.pathname.startsWith(`/${GCS_EXECUTION_FILES_CONFIG.bucket}/`)
505+
} else if (USE_BLOB_STORAGE && executionConfig.containerName) {
506+
isExecutionFile = url.includes(`/${executionConfig.containerName}/`)
507+
} else if (USE_GCS_STORAGE && executionConfig.bucket) {
508+
const bucketInHost = parsedUrl.hostname.startsWith(`${executionConfig.bucket}.`)
509+
const bucketInPath = parsedUrl.pathname.startsWith(`/${executionConfig.bucket}/`)
514510
isExecutionFile = bucketInHost || bucketInPath
515511
}
516512
} catch (error) {

0 commit comments

Comments
 (0)