Skip to content

Commit e359dc2

Browse files
authored
fix(cron): reject CRON requests when CRON secret is not set (#2343)
1 parent 0415eb4 commit e359dc2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

apps/sim/app/api/workflows/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function validateWorkflowAccess(
4242
}
4343

4444
const internalSecret = request.headers.get('X-Internal-Secret')
45-
if (internalSecret === env.INTERNAL_API_SECRET) {
45+
if (env.INTERNAL_API_SECRET && internalSecret === env.INTERNAL_API_SECRET) {
4646
return { workflow }
4747
}
4848

apps/sim/lib/auth/internal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ export async function verifyInternalToken(
6969
* Returns null if authorized, or a NextResponse with error if unauthorized
7070
*/
7171
export function verifyCronAuth(request: NextRequest, context?: string): NextResponse | null {
72+
if (!env.CRON_SECRET) {
73+
const contextInfo = context ? ` for ${context}` : ''
74+
logger.warn(`CRON endpoint accessed but CRON_SECRET is not configured${contextInfo}`, {
75+
ip: request.headers.get('x-forwarded-for') ?? request.headers.get('x-real-ip') ?? 'unknown',
76+
userAgent: request.headers.get('user-agent') ?? 'unknown',
77+
context,
78+
})
79+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
80+
}
81+
7282
const authHeader = request.headers.get('authorization')
7383
const expectedAuth = `Bearer ${env.CRON_SECRET}`
7484
if (authHeader !== expectedAuth) {

0 commit comments

Comments
 (0)