Skip to content

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

Open
waleedlatif1 wants to merge 12 commits intostagingfrom
waleedlatif1/excel-sharepoint-drive
Open

feat(microsoft-excel): add SharePoint drive support for Excel integration#4162
waleedlatif1 wants to merge 12 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 2:53am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 14, 2026

PR Summary

Medium Risk
Extends Microsoft Graph requests and selector plumbing to support SharePoint drives, which could affect file/sheet discovery and tool execution paths if driveId handling is incorrect. Changes are additive and gated by optional params, but touch multiple API routes and tool URL construction.

Overview
Adds optional SharePoint driveId support across Microsoft Excel tooling and selectors so workflows can read/write SharePoint-hosted workbooks in addition to personal OneDrive.

Introduces a new POST /api/tools/microsoft_excel/drives endpoint (with input validation) to list SharePoint document libraries for a selected site, and updates the Excel file and sheet selectors plus block UI to support a cascading SharePoint flow (site → document library → spreadsheet → sheet) while keeping OneDrive behavior as the default.

Refactors Excel tool URL generation to use a shared getItemBasePath() helper that validates IDs and switches Graph paths between me/drive and drives/{driveId}, and updates docs to document the new driveId parameter for microsoft_excel_read/microsoft_excel_write.

Reviewed by Cursor Bugbot for commit 3be18ca. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR adds optional SharePoint drive support to all Microsoft Excel tools by introducing a driveId parameter that routes requests through /drives/{driveId}/items/ instead of /me/drive/items/ for personal OneDrive. The V2 block gets a cascading site → drive → spreadsheet → sheet selector chain in basic mode, and a manual drive ID input in advanced mode. Prior security concerns (path traversal via unvalidated siteId/driveId/spreadsheetId, bulk-fetch in fetchById, and OneDrive user lock-out via the dependsOn gate) are all addressed in this revision.

Confidence Score: 5/5

Safe to merge — all prior P0/P1 concerns (path traversal, OneDrive lock-out, bulk fetchById) are resolved; one P2 edge case remains in advanced mode.

All previously-flagged security and regression issues are addressed. The single remaining finding is a P2: manualDriveId lacks dependsOn: ['fileSource'], which can leave a stale driveId in advanced mode when a user switches between SharePoint and OneDrive — a visible API failure rather than silent data corruption, and only reachable by power users in advanced mode.

apps/sim/blocks/blocks/microsoft_excel.ts — the manualDriveId subblock definition

Important Files Changed

Filename Overview
apps/sim/blocks/blocks/microsoft_excel.ts Adds fileSource dropdown, siteSelector, driveSelector, and manualDriveId to V2 block; manualDriveId is missing dependsOn: ['fileSource'] which can leave a stale driveId when user switches to OneDrive in advanced mode.
apps/sim/app/api/tools/microsoft_excel/drives/route.ts New POST route that lists SharePoint document libraries; validates siteId and driveId, handles single-drive fetchById via driveId in body, proper auth and error handling.
apps/sim/hooks/selectors/registry.ts Adds microsoft.excel.drives selector with fetchList and fetchById; propagates driveId context to microsoft.excel and microsoft.excel.sheets selectors for drive-scoped file/sheet lookups.
apps/sim/tools/microsoft_excel/utils.ts Adds getItemBasePath helper that validates spreadsheetId and driveId via validateMicrosoftGraphId before constructing Graph API paths; updates getSpreadsheetWebUrl to accept optional driveId.
apps/sim/app/api/auth/oauth/microsoft/files/route.ts Adds optional driveId query param with validateMicrosoftGraphId guard; routes file search to SharePoint drive or personal OneDrive accordingly.
apps/sim/app/api/tools/microsoft_excel/sheets/route.ts Validates spreadsheetId and driveId with validateMicrosoftGraphId; builds correct Graph API path for SharePoint vs OneDrive worksheet lookups.

Sequence Diagram

sequenceDiagram
    participant UI as V2 Block (basic)
    participant SR as Selector Registry
    participant SP as /api/auth/oauth/microsoft/files
    participant DR as /api/tools/microsoft_excel/drives
    participant SH as /api/tools/microsoft_excel/sheets
    participant GR as Microsoft Graph API

    UI->>SR: fileSource=sharepoint → siteSelector
    SR->>GR: GET /sites?search=...
    GR-->>SR: site list
    SR-->>UI: sites

    UI->>SR: siteId set → driveSelector
    SR->>DR: POST {siteId}
    DR->>GR: GET /sites/{siteId}/drives
    GR-->>DR: drive list
    DR-->>SR: drives
    SR-->>UI: document libraries

    UI->>SR: driveId set → spreadsheetId selector
    SR->>SP: GET ?driveId=...
    SP->>GR: GET /drives/{driveId}/root/search(...)
    GR-->>SP: files
    SP-->>SR: Excel files
    SR-->>UI: spreadsheets

    UI->>SR: spreadsheetId set → sheetName selector
    SR->>SH: GET ?spreadsheetId=...&driveId=...
    SH->>GR: GET /drives/{driveId}/items/{spreadsheetId}/workbook/worksheets
    GR-->>SH: worksheets
    SH-->>SR: sheets
    SR-->>UI: sheet names
Loading

Reviews (8): Last reviewed commit: "fix(microsoft-excel): use validateMicros..." | 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
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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f18af3c. Configure here.

…rePoint visibility

Replace always-visible optional SharePoint fields with a File Source
dropdown (OneDrive/SharePoint) that conditionally shows site and drive
selectors. OneDrive users see zero extra fields (default). SharePoint
users switch the dropdown and get the full cascade.
Make fileSource dropdown mode:'both' so it appears in basic and advanced
modes. Add condition to manualDriveId to match driveSelector's condition,
satisfying the canonical pair consistency test.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

… support

- Clear stale driveId/siteId/spreadsheetId when fileSource changes by adding
  fileSource to dependsOn arrays for siteSelector, driveSelector, and
  spreadsheetId selectors
- Reorder manualDriveId before manualSpreadsheetId in advanced mode for
  logical top-down flow
- Validate spreadsheetId with validateMicrosoftGraphId in getItemBasePath()
  and sheets route to close injection vector (uses permissive validator that
  accepts ! chars in OneDrive item 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

…tion

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>
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

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 3be18ca. Configure here.

… 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>
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