Skip to content

Commit 28b51b7

Browse files
committed
move session check higher in checkSessionOrInternalAuth
1 parent b1bcd9a commit 28b51b7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

apps/sim/lib/auth/hybrid.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,16 @@ export async function checkSessionOrInternalAuth(
143143
options: { requireWorkflowId?: boolean } = {}
144144
): Promise<AuthResult> {
145145
try {
146-
// 1. Check for internal JWT token first
146+
// 1. Reject API keys first
147+
const apiKeyHeader = request.headers.get('x-api-key')
148+
if (apiKeyHeader) {
149+
return {
150+
success: false,
151+
error: 'API key access not allowed for this endpoint',
152+
}
153+
}
154+
155+
// 2. Check for internal JWT token
147156
const authHeader = request.headers.get('authorization')
148157
if (authHeader?.startsWith('Bearer ')) {
149158
const token = authHeader.split(' ')[1]
@@ -216,7 +225,7 @@ export async function checkSessionOrInternalAuth(
216225
}
217226
}
218227

219-
// 2. Try session auth (for web UI)
228+
// 3. Try session auth (for web UI)
220229
const session = await getSession()
221230
if (session?.user?.id) {
222231
return {
@@ -226,15 +235,6 @@ export async function checkSessionOrInternalAuth(
226235
}
227236
}
228237

229-
// 3. Explicitly reject API key
230-
const apiKeyHeader = request.headers.get('x-api-key')
231-
if (apiKeyHeader) {
232-
return {
233-
success: false,
234-
error: 'API key access not allowed for this endpoint',
235-
}
236-
}
237-
238238
return {
239239
success: false,
240240
error: 'Authentication required - provide session or internal JWT',

0 commit comments

Comments
 (0)