Skip to content

Commit c508a0d

Browse files
waleedlatif1claude
andcommitted
fix(uploads): allow image/video/audio attachments in mothership presigned route
The mothership branch of the presigned upload route called validateFileType, which only permits SUPPORTED_DOCUMENT_EXTENSIONS — rejecting PNG screenshots and other media users have always been able to attach via the legacy /api/files/upload mothership branch. Introduce validateAttachmentFileType, backed by the union of document, code, image, audio, and video extensions, and wire it into the mothership branch. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1d3ca79 commit c508a0d

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { generateExecutionFileKey } from '@/lib/uploads/contexts/execution/utils
1111
import { generateWorkspaceFileKey } from '@/lib/uploads/contexts/workspace/workspace-file-manager'
1212
import { generatePresignedUploadUrl, hasCloudStorage } from '@/lib/uploads/core/storage-service'
1313
import { isImageFileType } from '@/lib/uploads/utils/file-utils'
14-
import { validateFileType } from '@/lib/uploads/utils/validation'
14+
import { validateAttachmentFileType, validateFileType } from '@/lib/uploads/utils/validation'
1515
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
1616
import { createErrorResponse } from '@/app/api/files/utils'
1717

@@ -141,7 +141,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
141141
)
142142
}
143143

144-
const fileValidationError = validateFileType(fileName, contentType)
144+
const fileValidationError = validateAttachmentFileType(fileName)
145145
if (fileValidationError) {
146146
throw new ValidationError(fileValidationError.message)
147147
}

apps/sim/lib/uploads/utils/validation.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,37 @@ export interface FileValidationError {
219219
supportedTypes: string[]
220220
}
221221

222+
export const SUPPORTED_ATTACHMENT_EXTENSIONS = [
223+
...SUPPORTED_DOCUMENT_EXTENSIONS,
224+
...SUPPORTED_CODE_EXTENSIONS,
225+
...SUPPORTED_IMAGE_EXTENSIONS,
226+
...SUPPORTED_AUDIO_EXTENSIONS,
227+
...SUPPORTED_VIDEO_EXTENSIONS,
228+
] as const
229+
230+
export type SupportedAttachmentExtension = (typeof SUPPORTED_ATTACHMENT_EXTENSIONS)[number]
231+
232+
/**
233+
* Validate that a file's extension is allowed as a chat/mothership attachment.
234+
*
235+
* Permits documents, code, images, audio, and video — anything users would
236+
* reasonably attach to a chat message. Rejects executables and unknown types.
237+
*/
238+
export function validateAttachmentFileType(fileName: string): FileValidationError | null {
239+
const raw = extractExtension(fileName)
240+
const extension = isAlphanumericExtension(raw) ? raw : ''
241+
242+
if (!SUPPORTED_ATTACHMENT_EXTENSIONS.includes(extension as SupportedAttachmentExtension)) {
243+
return {
244+
code: 'UNSUPPORTED_FILE_TYPE',
245+
message: `Unsupported file type${extension ? `: ${extension}` : ` for "${fileName}"`}. Supported types include documents, code, images, audio, and video.`,
246+
supportedTypes: [...SUPPORTED_ATTACHMENT_EXTENSIONS],
247+
}
248+
}
249+
250+
return null
251+
}
252+
222253
/**
223254
* Validate if a file type is supported for document processing
224255
*/

0 commit comments

Comments
 (0)