Skip to content

Commit 896a00a

Browse files
authored
fix(security): require internal API key for copilot training endpoints (#4311)
1 parent 74946fb commit 896a00a

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

apps/sim/app/api/copilot/training/examples/route.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { z } from 'zod'
4-
import {
5-
authenticateCopilotRequestSessionOnly,
6-
createUnauthorizedResponse,
7-
} from '@/lib/copilot/request/http'
4+
import { checkInternalApiKey, createUnauthorizedResponse } from '@/lib/copilot/request/http'
85
import { env } from '@/lib/core/config/env'
96
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
107

@@ -21,8 +18,8 @@ const TrainingExampleSchema = z.object({
2118
})
2219

2320
export const POST = withRouteHandler(async (request: NextRequest) => {
24-
const { userId, isAuthenticated } = await authenticateCopilotRequestSessionOnly()
25-
if (!isAuthenticated || !userId) {
21+
const auth = checkInternalApiKey(request)
22+
if (!auth.success) {
2623
return createUnauthorizedResponse()
2724
}
2825

apps/sim/app/api/copilot/training/route.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { z } from 'zod'
4-
import {
5-
authenticateCopilotRequestSessionOnly,
6-
createUnauthorizedResponse,
7-
} from '@/lib/copilot/request/http'
4+
import { checkInternalApiKey, createUnauthorizedResponse } from '@/lib/copilot/request/http'
85
import { env } from '@/lib/core/config/env'
96
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
107

@@ -27,8 +24,8 @@ const TrainingDataSchema = z.object({
2724
})
2825

2926
export const POST = withRouteHandler(async (request: NextRequest) => {
30-
const { userId, isAuthenticated } = await authenticateCopilotRequestSessionOnly()
31-
if (!isAuthenticated || !userId) {
27+
const auth = checkInternalApiKey(request)
28+
if (!auth.success) {
3229
return createUnauthorizedResponse()
3330
}
3431

0 commit comments

Comments
 (0)