Skip to content

Commit 6e642fc

Browse files
committed
address more bugbot comments
1 parent 1c857cd commit 6e642fc

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

apps/sim/app/api/tools/google_vault/download-export-file/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const logger = createLogger('GoogleVaultDownloadExportFileAPI')
1515

1616
const GoogleVaultDownloadExportFileSchema = z.object({
1717
accessToken: z.string().min(1, 'Access token is required'),
18-
matterId: z.string().min(1, 'Matter ID is required'),
1918
bucketName: z.string().min(1, 'Bucket name is required'),
2019
objectName: z.string().min(1, 'Object name is required'),
2120
fileName: z.string().optional().nullable(),

apps/sim/app/api/tools/onedrive/upload/route.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
33
import * as XLSX from 'xlsx'
44
import { z } from 'zod'
55
import { checkInternalAuth } from '@/lib/auth/hybrid'
6+
import { validateMicrosoftGraphId } from '@/lib/core/security/input-validation'
67
import { secureFetchWithValidation } from '@/lib/core/security/input-validation.server'
78
import { generateRequestId } from '@/lib/core/utils/request'
89
import { RawFileInputSchema } from '@/lib/uploads/utils/file-schemas'
@@ -57,28 +58,6 @@ interface ExcelRangeData {
5758
values?: unknown[][]
5859
}
5960

60-
/** Validates Microsoft Graph item IDs (alphanumeric with some special chars) */
61-
function validateMicrosoftGraphId(
62-
id: string,
63-
paramName: string
64-
): { isValid: boolean; error?: string } {
65-
// Microsoft Graph IDs are typically alphanumeric, may include hyphens and exclamation marks
66-
const validIdPattern = /^[a-zA-Z0-9!-]+$/
67-
if (!validIdPattern.test(id)) {
68-
return {
69-
isValid: false,
70-
error: `Invalid ${paramName}: contains invalid characters`,
71-
}
72-
}
73-
if (id.length > 256) {
74-
return {
75-
isValid: false,
76-
error: `Invalid ${paramName}: exceeds maximum length`,
77-
}
78-
}
79-
return { isValid: true }
80-
}
81-
8261
export async function POST(request: NextRequest) {
8362
const requestId = generateRequestId()
8463

apps/sim/tools/microsoft_teams/server-utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ export async function uploadFilesForTeamsMessage(params: {
117117
})
118118

119119
// Get file details for attachment reference
120-
const fileDetailsUrl = `https://graph.microsoft.com/v1.0/me/drive/items/${uploadedFile.id}?$select=id,name,webDavUrl,eTag,size`
120+
// Note: webDavUrl requires 'select' without the '$' prefix to be reliably returned
121+
const fileDetailsUrl = `https://graph.microsoft.com/v1.0/me/drive/items/${uploadedFile.id}?select=id,name,webDavUrl,eTag,size`
121122

122123
const fileDetailsResponse = await secureFetchWithValidation(
123124
fileDetailsUrl,
@@ -144,13 +145,21 @@ export async function uploadFilesForTeamsMessage(params: {
144145
eTag: fileDetails.eTag,
145146
})
146147

148+
// Validate webDavUrl is present (required for Teams attachment references)
149+
if (!fileDetails.webDavUrl) {
150+
log.error(`[${requestId}] webDavUrl missing from file details`, { fileId: uploadedFile.id })
151+
throw new Error(
152+
`Failed to get file URL for attachment "${file.name}". The file was uploaded but Teams attachment reference could not be created.`
153+
)
154+
}
155+
147156
// Create attachment reference
148157
const attachmentId = fileDetails.eTag?.match(/\{([a-f0-9-]+)\}/i)?.[1] || fileDetails.id
149158

150159
attachments.push({
151160
id: attachmentId,
152161
contentType: 'reference',
153-
contentUrl: fileDetails.webDavUrl!,
162+
contentUrl: fileDetails.webDavUrl,
154163
name: file.name,
155164
})
156165

0 commit comments

Comments
 (0)