Skip to content

Commit 312e545

Browse files
committed
fix(auth): add session and user-id checks to authorize-params endpoint
1 parent 987e696 commit 312e545

File tree

1 file changed

+11
-0
lines changed
  • apps/sim/app/api/auth/oauth2/authorize-params

1 file changed

+11
-0
lines changed

apps/sim/app/api/auth/oauth2/authorize-params/route.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import { verification } from '@sim/db/schema'
33
import { eq } from 'drizzle-orm'
44
import type { NextRequest } from 'next/server'
55
import { NextResponse } from 'next/server'
6+
import { getSession } from '@/lib/auth'
67

78
/**
89
* Returns the original OAuth authorize parameters stored in the verification record
910
* for a given consent code. Used by the consent page to reconstruct the authorize URL
1011
* when switching accounts.
1112
*/
1213
export async function GET(request: NextRequest) {
14+
const session = await getSession()
15+
if (!session?.user) {
16+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
17+
}
18+
1319
const consentCode = request.nextUrl.searchParams.get('consent_code')
1420
if (!consentCode) {
1521
return NextResponse.json({ error: 'consent_code is required' }, { status: 400 })
@@ -29,12 +35,17 @@ export async function GET(request: NextRequest) {
2935
clientId: string
3036
redirectURI: string
3137
scope: string[]
38+
userId: string
3239
codeChallenge: string
3340
codeChallengeMethod: string
3441
state: string | null
3542
nonce: string | null
3643
}
3744

45+
if (data.userId !== session.user.id) {
46+
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
47+
}
48+
3849
return NextResponse.json({
3950
client_id: data.clientId,
4051
redirect_uri: data.redirectURI,

0 commit comments

Comments
 (0)