Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions apps/sim/app/api/files/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ export async function POST(request: NextRequest) {
const uploadResults = []

for (const file of files) {
const originalName = file.name
if (!originalName) {
throw new InvalidRequestError('File name is missing')
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default filename 'untitled' always fails extension validation

High Severity

The default filename 'untitled' has no file extension, so validateFileExtension('untitled') will always return false — it splits on '.', gets 'untitled' as the "extension", and that's not in ALLOWED_EXTENSIONS. This means when a file has no name (the exact scenario this PR is fixing), the upload is rejected with a confusing error: "File type 'untitled' is not allowed" instead of proceeding with the default name. The previous behavior at least gave a clear "File name is missing" error. The workspace files route doesn't have this problem since it has no extension check.

Fix in Cursor Fix in Web

const originalName = file.name || 'untitled'

if (!validateFileExtension(originalName)) {
const extension = originalName.split('.').pop()?.toLowerCase() || 'unknown'
Expand Down
5 changes: 1 addition & 4 deletions apps/sim/app/api/workspaces/[id]/files/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
return NextResponse.json({ error: 'No file provided' }, { status: 400 })
}

const fileName = rawFile.name
if (!fileName) {
return NextResponse.json({ error: 'File name is missing' }, { status: 400 })
}
const fileName = rawFile.name || 'untitled'

const maxSize = 100 * 1024 * 1024
if (rawFile.size > maxSize) {
Expand Down
Loading