Skip to content

feat(microsoft-excel): add SharePoint drive support for Excel integration#4162

Merged
waleedlatif1 merged 17 commits intostagingfrom
waleedlatif1/excel-sharepoint-drive
Apr 15, 2026
Merged

feat(microsoft-excel): add SharePoint drive support for Excel integration#4162
waleedlatif1 merged 17 commits intostagingfrom
waleedlatif1/excel-sharepoint-drive

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add optional driveId parameter to all Microsoft Excel tools for SharePoint file access
  • Add cascading site/drive selectors in basic mode (site → document library → spreadsheet → sheet)
  • Add manual drive ID input in advanced mode
  • Create /api/tools/microsoft_excel/drives route to list SharePoint document libraries
  • Update file and sheet selectors to pass driveId context through the selector chain
  • Fully backward-compatible — OneDrive users unaffected when driveId is omitted

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 15, 2026 4:05am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 14, 2026

PR Summary

Medium Risk
Adds new SharePoint-specific inputs and a new API route while changing how Microsoft Graph URLs are constructed across read/write/table/worksheet operations; mistakes could break file access or expand request surface area.

Overview
Enables Microsoft Excel tools to operate on SharePoint document libraries by introducing an optional driveId and routing Graph calls through a shared getItemBasePath helper (switching between me/drive and drives/{driveId}).

Adds a new /api/tools/microsoft_excel/drives endpoint and microsoft.excel.drives selector to list SharePoint site drives, wires selector context to include driveId, and updates the Excel file/sheet selectors (and the Microsoft files search API) to accept and validate driveId.

Updates both legacy and v2 Excel blocks/UI to support a OneDrive vs SharePoint flow (site → drive → spreadsheet → sheet in basic mode, manual driveId in advanced mode) and documents the new driveId parameter for microsoft_excel_read/microsoft_excel_write.

Reviewed by Cursor Bugbot for commit def6e90. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

Adds optional SharePoint drive support to all Microsoft Excel tools by introducing a driveId parameter and a cascading site → library → file → sheet selector chain in the V2 block's basic mode. Security concerns from the previous review round (path traversal via siteId/driveId/spreadsheetId, stale driveId after switching back to OneDrive, and the fetchById bulk-fetch issue) are all addressed in the current commit.

Confidence Score: 5/5

Safe to merge — all previously flagged P0/P1 security and regression issues are resolved; only minor style/docs P2 items remain.

Prior rounds addressed path traversal (siteId/driveId/spreadsheetId validation), the stale driveId after source switch (dependsOn: fileSource), the OneDrive dependsOn regression (credential added to any-gates), and the fetchById bulk-fetch inefficiency. Remaining findings are a misplaced TSDoc block and missing docs entries for table_add/worksheet_add — neither blocks merge.

apps/docs/content/docs/en/tools/microsoft_excel.mdx (missing driveId docs for table_add / worksheet_add tools)

Important Files Changed

Filename Overview
apps/sim/tools/microsoft_excel/utils.ts Adds getItemBasePath with Graph ID validation and updates getSpreadsheetWebUrl to accept driveId; TSDoc comment for the function is misplaced above the GRAPH_ID_PATTERN constant.
apps/sim/app/api/tools/microsoft_excel/drives/route.ts New POST route to list/fetch SharePoint document libraries; validates siteId and driveId before URL interpolation, authorization and token refresh are properly handled.
apps/sim/blocks/blocks/microsoft_excel.ts Adds site/drive selector cascade in basic mode and manual driveId input in advanced mode; dependsOn arrays include credential in any-gate so OneDrive users remain unblocked.
apps/sim/hooks/selectors/registry.ts Adds microsoft.excel.drives selector with fetchById using direct single-drive lookup; driveId added to microsoft.excel and microsoft.excel.sheets query keys and fetchList params.
apps/docs/content/docs/en/tools/microsoft_excel.mdx Documents driveId for read and write tools but omits the same parameter from microsoft_excel_table_add and microsoft_excel_worksheet_add, which also gained driveId in this PR.

Sequence Diagram

sequenceDiagram
    participant UI as Block UI
    participant Sites as sharepoint.sites selector
    participant Drives as microsoft.excel.drives selector
    participant Files as microsoft.excel selector
    participant Sheets as microsoft.excel.sheets selector
    participant DrivesAPI as /api/tools/microsoft_excel/drives
    participant FilesAPI as /api/auth/oauth/microsoft/files
    participant SheetsAPI as /api/tools/microsoft_excel/sheets
    participant Graph as Microsoft Graph API

    UI->>Sites: Select SharePoint site (→ siteId context)
    Sites->>Graph: GET /sites?search=...
    Graph-->>Sites: site list
    UI->>Drives: Select document library (→ driveId context)
    Drives->>DrivesAPI: POST {credential, siteId}
    DrivesAPI->>Graph: GET /sites/{siteId}/drives
    Graph-->>DrivesAPI: drives list
    DrivesAPI-->>Drives: [{id, name}]
    UI->>Files: Select spreadsheet (→ spreadsheetId context)
    Files->>FilesAPI: GET ?credentialId&driveId&query
    FilesAPI->>Graph: GET /drives/{driveId}/root/search(q='...')
    Graph-->>FilesAPI: file list
    FilesAPI-->>Files: [{id, name}]
    UI->>Sheets: Select sheet (→ sheetName)
    Sheets->>SheetsAPI: GET ?credentialId&spreadsheetId&driveId
    SheetsAPI->>Graph: GET /drives/{driveId}/items/{spreadsheetId}/workbook/worksheets
    Graph-->>SheetsAPI: worksheet list
    SheetsAPI-->>Sheets: [{id, name}]
Loading

Reviews (11): Last reviewed commit: "lint" | Re-trigger Greptile

- Validate siteId/driveId format in drives route to prevent path traversal
- Use direct single-drive endpoint for fetchById instead of filtering full list
- Fix dependsOn on sheet/spreadsheet selectors so driveId flows into context
- Fix NextRequest type in drives route for build compatibility
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cusror review

Add regex validation for driveId query param in the Microsoft OAuth
files route to prevent path traversal, matching the drives route.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

…sheets route

- Add credential to any[] arrays so OneDrive users (no drive selected)
  still pass the dependsOn gate while driveSelector remains in the
  dependency list for context flow to SharePoint users
- Add /^[\w-]+$/ validation for driveId in sheets API route
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Add regex validation for driveId at the shared utility level to prevent
path traversal through the tool execution path, which bypasses the
API route validators.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Replace inline regex validation with platform validators from
@/lib/core/security/input-validation:
- validateSharePointSiteId for siteId in drives route
- validateAlphanumericId for driveId in drives, sheets, files routes
  and getItemBasePath utility
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

… driveId/spreadsheetId

Replace validateMicrosoftGraphId with validatePathSegment using a custom
pattern ^[a-zA-Z0-9!_-]+$ for all URL-interpolated IDs. validatePathSegment
blocks /, \, path traversal, and null bytes before checking the pattern,
preventing URL-modifying characters like ?, #, & from altering the Graph
API endpoint. The pattern allows ! for SharePoint b!<base64> drive IDs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Move driveId subBlock before manualSpreadsheetId in the legacy v1 block
to match the logical top-down flow (Drive ID → Spreadsheet ID), consistent
with the v2 block ordering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add dependsOn: ['fileSource'] to manualDriveId so its value is cleared
when switching from SharePoint back to OneDrive. Without this, the stale
driveId would still be serialized and forwarded to getItemBasePath,
routing through the SharePoint drive path instead of me/drive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

…ove duplication

Replace inline URL construction and validation logic with the shared
getItemBasePath utility, eliminating duplicated GRAPH_ID_PATTERN regex
and conditional URL building.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1 waleedlatif1 merged commit 8009578 into staging Apr 15, 2026
13 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/excel-sharepoint-drive branch April 15, 2026 04:10
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit def6e90. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant