Skip to content

Commit 3be18ca

Browse files
waleedlatif1claude
andcommitted
fix(microsoft-excel): use validateMicrosoftGraphId for driveId validation
SharePoint drive IDs use the format b!<base64-string> which contains ! characters rejected by validateAlphanumericId. Switch all driveId validation to validateMicrosoftGraphId which blocks path traversal and control characters while accepting valid Microsoft Graph identifiers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 326114d commit 3be18ca

4 files changed

Lines changed: 8 additions & 14 deletions

File tree

apps/sim/app/api/auth/oauth/microsoft/files/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { authorizeCredentialUse } from '@/lib/auth/credential-access'
4-
import { validateAlphanumericId } from '@/lib/core/security/input-validation'
4+
import { validateMicrosoftGraphId } from '@/lib/core/security/input-validation'
55
import { generateRequestId } from '@/lib/core/utils/request'
66
import { getCredential, refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
77

@@ -77,7 +77,7 @@ export async function GET(request: NextRequest) {
7777
// When driveId is provided (SharePoint), search within that specific drive.
7878
// Otherwise, search the user's personal OneDrive.
7979
if (driveId) {
80-
const driveIdValidation = validateAlphanumericId(driveId, 'driveId')
80+
const driveIdValidation = validateMicrosoftGraphId(driveId, 'driveId')
8181
if (!driveIdValidation.isValid) {
8282
return NextResponse.json({ error: driveIdValidation.error }, { status: 400 })
8383
}

apps/sim/app/api/tools/microsoft_excel/drives/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { authorizeCredentialUse } from '@/lib/auth/credential-access'
44
import {
5-
validateAlphanumericId,
5+
validateMicrosoftGraphId,
66
validateSharePointSiteId,
77
} from '@/lib/core/security/input-validation'
88
import { generateRequestId } from '@/lib/core/utils/request'
@@ -70,7 +70,7 @@ export async function POST(request: NextRequest) {
7070

7171
// Single-drive lookup when driveId is provided (used by fetchById)
7272
if (driveId) {
73-
const driveIdValidation = validateAlphanumericId(driveId, 'driveId')
73+
const driveIdValidation = validateMicrosoftGraphId(driveId, 'driveId')
7474
if (!driveIdValidation.isValid) {
7575
return NextResponse.json({ error: driveIdValidation.error }, { status: 400 })
7676
}

apps/sim/app/api/tools/microsoft_excel/sheets/route.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { authorizeCredentialUse } from '@/lib/auth/credential-access'
4-
import {
5-
validateAlphanumericId,
6-
validateMicrosoftGraphId,
7-
} from '@/lib/core/security/input-validation'
4+
import { validateMicrosoftGraphId } from '@/lib/core/security/input-validation'
85
import { generateRequestId } from '@/lib/core/utils/request'
96
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
107

@@ -72,7 +69,7 @@ export async function GET(request: NextRequest) {
7269
}
7370

7471
if (driveId) {
75-
const driveIdValidation = validateAlphanumericId(driveId, 'driveId')
72+
const driveIdValidation = validateMicrosoftGraphId(driveId, 'driveId')
7673
if (!driveIdValidation.isValid) {
7774
return NextResponse.json({ error: driveIdValidation.error }, { status: 400 })
7875
}

apps/sim/tools/microsoft_excel/utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
validateAlphanumericId,
4-
validateMicrosoftGraphId,
5-
} from '@/lib/core/security/input-validation'
2+
import { validateMicrosoftGraphId } from '@/lib/core/security/input-validation'
63
import type { ExcelCellValue } from '@/tools/microsoft_excel/types'
74

85
const logger = createLogger('MicrosoftExcelUtils')
@@ -19,7 +16,7 @@ export function getItemBasePath(spreadsheetId: string, driveId?: string): string
1916
}
2017

2118
if (driveId) {
22-
const driveValidation = validateAlphanumericId(driveId, 'driveId')
19+
const driveValidation = validateMicrosoftGraphId(driveId, 'driveId')
2320
if (!driveValidation.isValid) {
2421
throw new Error(driveValidation.error)
2522
}

0 commit comments

Comments
 (0)