-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Simplify OAuth scopes #3218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify OAuth scopes #3218
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughRenamed an OAuth validator, removed workspace-related OAuth scopes and filtered them during request validation, threaded a token through withWorkspace and a Stripe PATCH route with token-based checks, added a script to strip workspace scopes from tokens, adjusted OAuth URL scope usage, and fixed a few types/comments and UI text. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Route as Stripe PATCH Route
participant Auth as withWorkspace
participant TokenStore as Token Cache / DB
participant Install as Installations DB
Client->>Route: PATCH /api/stripe/integration (req, session, token)
Route->>Auth: enter withWorkspace(handler) with (req, session, token)
Auth->>TokenStore: resolve token (if present)
TokenStore-->>Auth: TokenCacheItem | null
Auth->>Auth: include token in handler args
Auth->>Install: fetch installation by token.installationId
Install-->>Auth: installation
Auth->>Route: invoke handler with token + installation
Route->>Install: validate installation.integrationId == STRIPE_INTEGRATION_ID
alt valid
Route->>Install: perform update
Install-->>Route: success
Route-->>Client: 200 OK
else invalid
Route-->>Client: 403 Forbidden
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (11)
💤 Files with no reviewable changes (2)
🧰 Additional context used🧠 Learnings (5)📚 Learning: 2025-09-17T02:53:28.359ZApplied to files:
📚 Learning: 2025-10-17T08:18:19.278ZApplied to files:
📚 Learning: 2025-10-15T01:05:43.266ZApplied to files:
📚 Learning: 2025-06-04T15:09:51.562ZApplied to files:
📚 Learning: 2025-12-08T09:44:28.429ZApplied to files:
🧬 Code graph analysis (4)apps/web/lib/auth/workspace.ts (1)
apps/web/app/app.dub.co/(auth)/oauth/authorize/authorize-form.tsx (1)
apps/web/app/(ee)/api/stripe/integration/route.ts (2)
apps/web/app/app.dub.co/(auth)/oauth/authorize/page.tsx (1)
🔇 Additional comments (11)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
….write' instead of 'workspaces.write'; add script to remove deprecated workspace scopes from tokens.
…on checks; remove 'workspaces.settings.write' scope from various files to streamline permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/stripe/integration/route.ts (1)
118-128: Apply consistent token-based authorization to Shopify integration endpoint.The Stripe integration route correctly implements token-based authorization requiring a valid Stripe
installationId(lines 27-48), replacing the broaderrequiredPermissions: ["workspaces.write"]check. This is more secure and appropriate for integration-specific endpoints.However, the Shopify integration callback route (
apps/web/app/(ee)/api/shopify/integration/callback/route.ts, line 88) still usesrequiredPermissions: ["workspaces.write"]without the corresponding token-based check. Both endpoints perform similar operations (updating workspace integration configuration) and should follow the same authorization pattern.Update Shopify integration callback to use the same token-based
installationIdvalidation as Stripe, or document why they differ.
🧹 Nitpick comments (1)
apps/web/lib/zod/schemas/oauth.ts (1)
60-64: Track removal of workspace scope filtering as technical debt.The workspace scope filtering is a temporary workaround to prevent validation errors during the migration period. Consider creating a tracking issue to remove this filter once all existing integrations have been updated.
Would you like me to open an issue to track the removal of this workaround after the migration is complete?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/web/app/(ee)/api/stripe/integration/route.ts(1 hunks)apps/web/lib/auth/workspace.ts(3 hunks)apps/web/lib/zod/schemas/oauth.ts(1 hunks)apps/web/scripts/remove-workspace-scopes.ts(1 hunks)packages/prisma/schema/token.prisma(1 hunks)packages/stripe-app/src/utils/oauth.ts(0 hunks)
💤 Files with no reviewable changes (1)
- packages/stripe-app/src/utils/oauth.ts
✅ Files skipped from review due to trivial changes (1)
- packages/prisma/schema/token.prisma
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-17T02:53:28.359Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2839
File: apps/web/lib/integrations/hubspot/schema.ts:5-12
Timestamp: 2025-09-17T02:53:28.359Z
Learning: HubSpot's OAuth token response returns `scopes` as an array of strings, not as a space-delimited string. The schema `scopes: z.array(z.string())` in hubSpotAuthTokenSchema is correct for HubSpot's actual API response format.
Applied to files:
apps/web/lib/zod/schemas/oauth.ts
📚 Learning: 2025-10-17T08:18:19.278Z
Learnt from: devkiran
Repo: dubinc/dub PR: 0
File: :0-0
Timestamp: 2025-10-17T08:18:19.278Z
Learning: In the apps/web codebase, `@/lib/zod` should only be used for places that need OpenAPI extended zod schema. All other places should import from the standard `zod` package directly using `import { z } from "zod"`.
Applied to files:
apps/web/lib/zod/schemas/oauth.ts
🧬 Code graph analysis (4)
apps/web/lib/auth/workspace.ts (1)
apps/web/lib/auth/token-cache.ts (1)
TokenCacheItem(25-25)
apps/web/scripts/remove-workspace-scopes.ts (1)
packages/prisma/index.ts (1)
prisma(3-9)
apps/web/app/(ee)/api/stripe/integration/route.ts (2)
apps/web/lib/api/errors.ts (1)
DubApiError(58-75)packages/prisma/index.ts (1)
prisma(3-9)
apps/web/lib/zod/schemas/oauth.ts (1)
apps/web/lib/api/oauth/constants.ts (1)
OAUTH_SCOPES(21-34)
🔇 Additional comments (5)
apps/web/scripts/remove-workspace-scopes.ts (1)
25-46: LGTM! Good error handling and edge case management.The scope filtering logic correctly:
- Handles null scopes (Line 28)
- Removes all workspaces.* scopes using startsWith check
- Sets scopes to null when no scopes remain
- Uses Promise.allSettled to handle failures gracefully
apps/web/lib/zod/schemas/oauth.ts (2)
49-51: LGTM! More correct handling of optional scope parameter.Changing from
nullable()tonullish()properly handles cases where the scope parameter is omitted entirely (undefined) in addition to being explicitly null. This aligns better with OAuth 2.0 specification where scope is an optional parameter.
67-69: LGTM! Improved error message clarity.The updated error message "One or more provided OAuth scopes are invalid or unsupported." is more informative than the previous "Invalid scopes" and helps developers understand the validation failure.
apps/web/lib/auth/workspace.ts (1)
35-55: LGTM! Clean token propagation through handler chain.The changes correctly thread the
tokenparameter through the workspace authentication flow:
- Declared at line 116 with proper type
TokenCacheItem | null- Populated during token authentication (existing logic)
- Passed to downstream handler at line 469
This enables downstream handlers to access token information for authorization decisions, such as the Stripe integration route that validates installation IDs.
Also applies to: 116-116, 461-470
apps/web/app/(ee)/api/stripe/integration/route.ts (1)
27-48: LGTM! Defense-in-depth token validation.The token-based installation validation correctly:
- Verifies the request has a token with an installation ID (lines 27-32)
- Confirms the installation exists and belongs to Stripe integration (lines 34-48)
- Returns clear forbidden errors for unauthorized access
This ensures only requests from the Stripe integration can update the Stripe Connect account, preventing misuse from other integrations or generic workspace tokens.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Summary by CodeRabbit
Bug Fixes
Changes
Chores
Security
✏️ Tip: You can customize this high-level summary in your review settings.