Conversation
Add Discord as a new platform integration following the same architecture as the existing Slack integration. This includes the OAuth2 flow for adding the bot to a Discord server, storing guild information in the shared platform_integrations table, and full frontend UI for both personal and organization-level integrations. Bot implementation will follow in a subsequent PR.
Code Review SummaryStatus: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (18 files)
|
d907a68 to
0b8e8ed
Compare
|
Unblocking, please at least verify the OAuth comments and the authentication. |
The state parameter was a plain, guessable string (user_id/org_id), allowing authorization code injection attacks. Sign it with HMAC-SHA256 using NEXTAUTH_SECRET and embed the initiating user's ID so the callback can verify the flow wasn't tampered with.
The signed OAuth state payload previously only contained { owner, uid },
making it deterministic and valid indefinitely. A leaked state token
(via logs, referrer headers, browser history) could be replayed at any
time by the same authenticated user context.
Add an issued-at timestamp (iat) with a 10-minute TTL and a 128-bit
random nonce to each state token. Verification now rejects tokens that
are expired, have future timestamps, or lack the new fields.
| // 1. Verify user authentication | ||
| const { user, authFailedResponse } = await getUserFromAuth({ adminOnly: false }); | ||
| if (authFailedResponse) { | ||
| return NextResponse.redirect(new URL('/users/sign_in', APP_URL)); |
There was a problem hiding this comment.
WARNING: Auth redirect drops OAuth callback context, causing non-recoverable install failures for signed-out users.
When getUserFromAuth fails, this redirects to /users/sign_in without preserving the current callback URL (code/state). If a user’s session expires between initiating OAuth and callback, they authenticate successfully but cannot resume the install because the authorization code/state are lost. Consider redirecting to sign-in with a callbackPath back to this callback URL so the flow can continue safely.
Summary
This PR adds the basic scaffolding for adding a Discord OAuth integration to the User/Organization level. It mostly works the same as our Slack integration and is heavily based on it.
CleanShot.2026-02-25.at.14.33.13.mp4