Skip to content

Commit 2ca9a67

Browse files
committed
fix(network-policy): gate socket-token minting via enforcing getSession (app-side primary socket gate)
1 parent 83ba26e commit 2ca9a67

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • apps/sim/app/api/auth/socket-token

apps/sim/app/api/auth/socket-token/route.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { toError } from '@sim/utils/errors'
33
import { headers } from 'next/headers'
44
import { type NextRequest, NextResponse } from 'next/server'
5-
import { auth } from '@/lib/auth'
5+
import { auth, getSession } from '@/lib/auth'
66
import { isAuthDisabled } from '@/lib/core/config/env-flags'
77
import { enforceIpRateLimit } from '@/lib/core/rate-limiter'
88
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
@@ -21,6 +21,17 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
2121
})
2222
if (rateLimited) return rateLimited
2323

24+
// Gate socket-token minting through the enforcing getSession chokepoint so a
25+
// member blocked by the org IP allowlist can't obtain a socket token in the
26+
// first place — making the app the primary socket gate (same cache and
27+
// ~60s propagation as every other surface). `generateOneTimeToken` uses
28+
// Better Auth's internal session middleware, which does not run the
29+
// customSession network-policy check, so this explicit call is required.
30+
const session = await getSession()
31+
if (!session?.user?.id) {
32+
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
33+
}
34+
2435
try {
2536
const hdrs = await headers()
2637
const response = await auth.api.generateOneTimeToken({

0 commit comments

Comments
 (0)