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
3 changes: 2 additions & 1 deletion apps/sim/app/api/auth/oauth/microsoft/files/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { authorizeCredentialUse } from '@/lib/auth/credential-access'
import { validatePathSegment } from '@/lib/core/security/input-validation'
import { generateRequestId } from '@/lib/core/utils/request'
import { getCredential, refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
import { GRAPH_ID_PATTERN } from '@/tools/microsoft_excel/utils'

export const dynamic = 'force-dynamic'

Expand Down Expand Up @@ -79,7 +80,7 @@ export async function GET(request: NextRequest) {
if (driveId) {
const driveIdValidation = validatePathSegment(driveId, {
paramName: 'driveId',
customPattern: /^[a-zA-Z0-9!_-]+$/,
customPattern: GRAPH_ID_PATTERN,
})
if (!driveIdValidation.isValid) {
return NextResponse.json({ error: driveIdValidation.error }, { status: 400 })
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/tools/microsoft_excel/drives/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { authorizeCredentialUse } from '@/lib/auth/credential-access'
import { validatePathSegment, validateSharePointSiteId } from '@/lib/core/security/input-validation'
import { generateRequestId } from '@/lib/core/utils/request'
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
import { GRAPH_ID_PATTERN } from '@/tools/microsoft_excel/utils'

export const dynamic = 'force-dynamic'

Expand Down Expand Up @@ -69,7 +70,7 @@ export async function POST(request: NextRequest) {
if (driveId) {
const driveIdValidation = validatePathSegment(driveId, {
paramName: 'driveId',
customPattern: /^[a-zA-Z0-9!_-]+$/,
customPattern: GRAPH_ID_PATTERN,
})
if (!driveIdValidation.isValid) {
return NextResponse.json({ error: driveIdValidation.error }, { status: 400 })
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/tools/microsoft_excel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import type { ExcelCellValue } from '@/tools/microsoft_excel/types'

const logger = createLogger('MicrosoftExcelUtils')

/** Pattern for Microsoft Graph item/drive IDs: alphanumeric, hyphens, underscores, and ! (for SharePoint b!<base64> format) */
export const GRAPH_ID_PATTERN = /^[a-zA-Z0-9!_-]+$/

/**
* Returns the Graph API base path for an Excel item.
* When driveId is provided, uses /drives/{driveId}/items/{itemId} (SharePoint/shared drives).
* When driveId is omitted, uses /me/drive/items/{itemId} (personal OneDrive).
*/
/** Pattern for Microsoft Graph item/drive IDs: alphanumeric, hyphens, underscores, and ! (for SharePoint b!<base64> format) */
const GRAPH_ID_PATTERN = /^[a-zA-Z0-9!_-]+$/

export function getItemBasePath(spreadsheetId: string, driveId?: string): string {
const spreadsheetValidation = validatePathSegment(spreadsheetId, {
paramName: 'spreadsheetId',
Expand Down
Loading