Skip to content

Commit 601f58c

Browse files
committed
use helper for internal route check
1 parent 9fc6378 commit 601f58c

File tree

6 files changed

+42
-34
lines changed

6 files changed

+42
-34
lines changed

apps/sim/app/api/tools/mistral/parse/route.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { checkHybridAuth } from '@/lib/auth/hybrid'
55
import { generateRequestId } from '@/lib/core/utils/request'
66
import { getBaseUrl } from '@/lib/core/utils/urls'
77
import { StorageService } from '@/lib/uploads'
8-
import { extractStorageKey, inferContextFromKey } from '@/lib/uploads/utils/file-utils'
8+
import {
9+
extractStorageKey,
10+
inferContextFromKey,
11+
isInternalFileUrl,
12+
} from '@/lib/uploads/utils/file-utils'
913
import { verifyFileAccess } from '@/app/api/files/authorization'
1014

1115
export const dynamic = 'force-dynamic'
@@ -47,13 +51,13 @@ export async function POST(request: NextRequest) {
4751

4852
logger.info(`[${requestId}] Mistral parse request`, {
4953
filePath: validatedData.filePath,
50-
isWorkspaceFile: validatedData.filePath.includes('/api/files/serve/'),
54+
isWorkspaceFile: isInternalFileUrl(validatedData.filePath),
5155
userId,
5256
})
5357

5458
let fileUrl = validatedData.filePath
5559

56-
if (validatedData.filePath?.includes('/api/files/serve/')) {
60+
if (isInternalFileUrl(validatedData.filePath)) {
5761
try {
5862
const storageKey = extractStorageKey(validatedData.filePath)
5963

apps/sim/app/api/tools/pulse/parse/route.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { checkHybridAuth } from '@/lib/auth/hybrid'
55
import { generateRequestId } from '@/lib/core/utils/request'
66
import { getBaseUrl } from '@/lib/core/utils/urls'
77
import { StorageService } from '@/lib/uploads'
8-
import { extractStorageKey, inferContextFromKey } from '@/lib/uploads/utils/file-utils'
8+
import {
9+
extractStorageKey,
10+
inferContextFromKey,
11+
isInternalFileUrl,
12+
} from '@/lib/uploads/utils/file-utils'
913
import { verifyFileAccess } from '@/app/api/files/authorization'
1014

1115
export const dynamic = 'force-dynamic'
@@ -48,13 +52,13 @@ export async function POST(request: NextRequest) {
4852

4953
logger.info(`[${requestId}] Pulse parse request`, {
5054
filePath: validatedData.filePath,
51-
isWorkspaceFile: validatedData.filePath.includes('/api/files/serve/'),
55+
isWorkspaceFile: isInternalFileUrl(validatedData.filePath),
5256
userId,
5357
})
5458

5559
let fileUrl = validatedData.filePath
5660

57-
if (validatedData.filePath?.includes('/api/files/serve/')) {
61+
if (isInternalFileUrl(validatedData.filePath)) {
5862
try {
5963
const storageKey = extractStorageKey(validatedData.filePath)
6064
const context = inferContextFromKey(storageKey)

apps/sim/app/api/tools/reducto/parse/route.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { checkHybridAuth } from '@/lib/auth/hybrid'
55
import { generateRequestId } from '@/lib/core/utils/request'
66
import { getBaseUrl } from '@/lib/core/utils/urls'
77
import { StorageService } from '@/lib/uploads'
8-
import { extractStorageKey, inferContextFromKey } from '@/lib/uploads/utils/file-utils'
8+
import {
9+
extractStorageKey,
10+
inferContextFromKey,
11+
isInternalFileUrl,
12+
} from '@/lib/uploads/utils/file-utils'
913
import { verifyFileAccess } from '@/app/api/files/authorization'
1014

1115
export const dynamic = 'force-dynamic'
@@ -44,13 +48,13 @@ export async function POST(request: NextRequest) {
4448

4549
logger.info(`[${requestId}] Reducto parse request`, {
4650
filePath: validatedData.filePath,
47-
isWorkspaceFile: validatedData.filePath.includes('/api/files/serve/'),
51+
isWorkspaceFile: isInternalFileUrl(validatedData.filePath),
4852
userId,
4953
})
5054

5155
let fileUrl = validatedData.filePath
5256

53-
if (validatedData.filePath?.includes('/api/files/serve/')) {
57+
if (isInternalFileUrl(validatedData.filePath)) {
5458
try {
5559
const storageKey = extractStorageKey(validatedData.filePath)
5660
const context = inferContextFromKey(storageKey)

apps/sim/app/api/tools/textract/parse/route.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import {
99
validateS3BucketName,
1010
} from '@/lib/core/security/input-validation'
1111
import { generateRequestId } from '@/lib/core/utils/request'
12-
import { getBaseUrl } from '@/lib/core/utils/urls'
1312
import { StorageService } from '@/lib/uploads'
14-
import { extractStorageKey, inferContextFromKey } from '@/lib/uploads/utils/file-utils'
13+
import {
14+
extractStorageKey,
15+
inferContextFromKey,
16+
isInternalFileUrl,
17+
} from '@/lib/uploads/utils/file-utils'
1518
import { verifyFileAccess } from '@/app/api/files/authorization'
1619

1720
export const dynamic = 'force-dynamic'
@@ -423,10 +426,7 @@ export async function POST(request: NextRequest) {
423426

424427
let fileUrl = validatedData.filePath
425428

426-
const isInternalFilePath =
427-
validatedData.filePath?.startsWith('/api/files/serve/') ||
428-
(validatedData.filePath?.startsWith('/') &&
429-
validatedData.filePath?.includes('/api/files/serve/'))
429+
const isInternalFilePath = validatedData.filePath && isInternalFileUrl(validatedData.filePath)
430430

431431
if (isInternalFilePath) {
432432
try {
@@ -463,21 +463,18 @@ export async function POST(request: NextRequest) {
463463
)
464464
}
465465
} else if (validatedData.filePath?.startsWith('/')) {
466-
if (!validatedData.filePath.startsWith('/api/files/serve/')) {
467-
logger.warn(`[${requestId}] Invalid internal path`, {
468-
userId,
469-
path: validatedData.filePath.substring(0, 50),
470-
})
471-
return NextResponse.json(
472-
{
473-
success: false,
474-
error: 'Invalid file path. Only uploaded files are supported for internal paths.',
475-
},
476-
{ status: 400 }
477-
)
478-
}
479-
const baseUrl = getBaseUrl()
480-
fileUrl = `${baseUrl}${validatedData.filePath}`
466+
// Reject arbitrary absolute paths that don't contain /api/files/serve/
467+
logger.warn(`[${requestId}] Invalid internal path`, {
468+
userId,
469+
path: validatedData.filePath.substring(0, 50),
470+
})
471+
return NextResponse.json(
472+
{
473+
success: false,
474+
error: 'Invalid file path. Only uploaded files are supported for internal paths.',
475+
},
476+
{ status: 400 }
477+
)
481478
} else {
482479
const urlValidation = validateExternalUrl(fileUrl, 'Document URL')
483480
if (!urlValidation.isValid) {

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/file-upload/file-upload.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ export function FileUpload({
9090
* Checks if a file's MIME type matches the accepted types
9191
* Supports exact matches, wildcard patterns (e.g., 'image/*'), and '*' for all types
9292
*/
93-
const isFileTypeAccepted = (fileType: string, accepted: string): boolean => {
93+
const isFileTypeAccepted = (fileType: string | undefined, accepted: string): boolean => {
9494
if (accepted === '*') return true
95+
if (!fileType) return false
9596

9697
const acceptedList = accepted.split(',').map((t) => t.trim().toLowerCase())
9798
const normalizedFileType = fileType.toLowerCase()

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/editor.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ export function Editor() {
129129
blockSubBlockValues,
130130
canonicalIndex
131131
)
132-
const displayAdvancedOptions = userPermissions.canEdit
133-
? advancedMode
134-
: advancedMode || advancedValuesPresent
132+
const displayAdvancedOptions = advancedMode || advancedValuesPresent
135133

136134
const hasAdvancedOnlyFields = useMemo(() => {
137135
for (const subBlock of subBlocksForCanonical) {

0 commit comments

Comments
 (0)