Skip to content

fix(oauth): bind update access to selected credential - #6999

Open
BillLeoutsakosvl346 wants to merge 4 commits into
stagingfrom
fix/slack-update-access
Open

fix(oauth): bind update access to selected credential#6999
BillLeoutsakosvl346 wants to merge 4 commits into
stagingfrom
fix/slack-update-access

Conversation

@BillLeoutsakosvl346

@BillLeoutsakosvl346 BillLeoutsakosvl346 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Bind existing-credential reauthorization to the exact selected OAuth credential before redirecting. This makes the callback use the established draft reconnect path instead of relying on provider account-ID matching, which can leave a legacy Slack credential pointing at its old account after Update access.

The change is provider-agnostic and applies to workflow credential selectors, tool-input credential selectors, and knowledge connectors. Provider-only Copilot reauthorization remains unchanged.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • bun run --cwd apps/sim test 'app/workspace/[workspaceId]/components/connect-oauth-modal/connect-oauth-modal.test.tsx' lib/credentials/draft-processor.test.ts lib/credentials/draft-hooks.test.ts (18 tests passed)
  • bun run --cwd apps/sim type-check
  • Changed-file Biome check
  • Chrome-controlled local app verification with a disposable localhost-only Slack credential whose stored scope was chat:write:
    • Confirmed the Slack block displayed Additional permissions required and Update access.
    • Confirmed the existing Connect Slack permission modal rendered without visual regressions.
    • Confirmed POST /api/credentials/draft created draft 7e70aa5f-afc3-42df-95b4-5ed144dd5748 for workspace 6762b941-0cb8-4787-918d-c8ac76d501b4, provider slack, selected credential ea789bd4-17c9-4a8f-80fd-123456789004, and display name Local incomplete Slack.
    • Confirmed the subsequent POST /api/auth/oauth2/link was attempted. The local run used port 3001 because port 3000 was occupied by another worktree, so Better Auth rejected the local origin before any Slack redirect. The focused modal test separately verifies that the returned draft ID is forwarded into this link call.
    • Removed the disposable workflow, account, credential, draft, and any matching audit rows afterward.

No live Slack OAuth flow was completed, no real grant or credential was modified, and no provider configuration was changed.

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)

Screenshots/Videos

Not applicable: no visual changes are intended. Chrome verification confirmed the existing warning and modal presentation.

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 23, 2026 1:47am

Request Review

@cursor

cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches OAuth reauthorization and credential-draft handoff, which can mis-bind tokens if wrong. The change is a targeted fail-closed fix with tests and does not alter provider-only Copilot reauth.

Overview
Update access / reconnect now targets the selected credential, not whatever account ID the provider returns after OAuth.

ConnectOAuthModal reauthorize mode accepts reconnectTarget and creates a credential-bound draft before launching OAuth. The callback then uses the existing reconnect-draft path (handleReconnectCredential) even when Slack (or similar) issues a new account identity. Provider-only reauth without a target (e.g. Copilot) still skips draft creation.

Workflow credential selectors, tool-input selectors, and knowledge connectors pass the resolved credential’s id, name, and actual provider. The modal only mounts when that credential is still present; if it disappears while open, return context is cleared and reconnect is disabled rather than falling back to a generic provider launch.

Reviewed by Cursor Bugbot for commit e0dc30f. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR binds OAuth reauthorization to the exact selected credential through the existing draft reconnect path.

  • Creates a credential-specific draft before launching reauthorization.
  • Uses the resolved credential provider and identity for workflow selectors, tool-input selectors, and knowledge connectors.
  • Makes knowledge-connector reconnect fail closed when its stored credential cannot be resolved.
  • Adds focused coverage for draft creation, launch ordering, provider binding, and unresolved credentials.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/components/connect-oauth-modal/connect-oauth-modal.tsx Reauthorization now creates and forwards an exact-credential draft before launching OAuth.
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/connectors-section/connectors-section.tsx Knowledge-connector reconnect resolves the stored credential, uses its provider and identity, and fails closed when resolution fails.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/credential-selector/credential-selector.tsx Workflow credential reauthorization now supplies the selected credential as the reconnect target.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/components/tools/credential-selector.tsx Tool-input credential reauthorization now supplies the selected credential as the reconnect target.
apps/sim/app/workspace/[workspaceId]/components/connect-oauth-modal/connect-oauth-modal.test.tsx Adds focused tests for exact draft binding, launch suppression on draft failure, and provider-only behavior.
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/connectors-section/connectors-section.test.tsx Adds coverage for unresolved credentials, custom-provider identity, and credential disappearance while the modal is open.
apps/sim/lib/credentials/draft-processor.test.ts Verifies that an exact Slack reconnect draft updates its bound credential regardless of changed account identity.

Sequence Diagram

sequenceDiagram
  participant UI as Credential UI
  participant Draft as Credential Draft API
  participant OAuth as OAuth Launch/Callback
  participant Processor as Draft Processor
  participant Credential as Selected Credential
  UI->>Draft: Create draft with provider and credential ID
  Draft-->>UI: Return draft ID
  UI->>OAuth: Launch reauthorization with draft ID
  OAuth->>Processor: Callback with draft and new account ID
  Processor->>Credential: Rebind exact selected credential
Loading

Reviews (4): Last reviewed commit: "fix(oauth): clear stale connector return..." | Re-trigger Greptile

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

Addressed both provider-binding findings in 36fe7d0, added focused regression coverage, and reran the focused suite, Biome, and type-check.

@greptile
@cursor review

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

Addressed the stale OAuth return-context finding in 1014ba6 with focused lifecycle coverage; all 27 focused tests, Biome, and type-check pass.

@greptile
@cursor review

@icecrasher321

Copy link
Copy Markdown
Collaborator

bugbot run

@icecrasher321

Copy link
Copy Markdown
Collaborator

@greptile

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author
Screen.Recording.2026-08-22.at.6.38.59.PM.mov

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 using high effort 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 e0dc30f. Configure here.

consumeOAuthReturnContext()
setShowOAuthModal(false)
}
}, [showOAuthModal, selectedId, selectedCredential])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Premature OAuth reauth cleanup

Medium Severity

The new cleanup effect treats a temporarily unresolved credential as deleted. selectedCredential is derived from a credentials list that defaults to [] whenever the query has no cached data, and the effect never checks credentialsLoading. In the tool selector, workflowId enters the query key only after workflowMap loads, so an open reauth modal can briefly lose selectedCredential, consume the OAuth return context, and close mid-flow.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e0dc30f. 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.

2 participants