mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 15:07:55 -05:00
fix(cron): reject CRON requests when CRON secret is not set (#2343)
This commit is contained in:
@@ -42,7 +42,7 @@ export async function validateWorkflowAccess(
|
||||
}
|
||||
|
||||
const internalSecret = request.headers.get('X-Internal-Secret')
|
||||
if (internalSecret === env.INTERNAL_API_SECRET) {
|
||||
if (env.INTERNAL_API_SECRET && internalSecret === env.INTERNAL_API_SECRET) {
|
||||
return { workflow }
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,16 @@ export async function verifyInternalToken(
|
||||
* Returns null if authorized, or a NextResponse with error if unauthorized
|
||||
*/
|
||||
export function verifyCronAuth(request: NextRequest, context?: string): NextResponse | null {
|
||||
if (!env.CRON_SECRET) {
|
||||
const contextInfo = context ? ` for ${context}` : ''
|
||||
logger.warn(`CRON endpoint accessed but CRON_SECRET is not configured${contextInfo}`, {
|
||||
ip: request.headers.get('x-forwarded-for') ?? request.headers.get('x-real-ip') ?? 'unknown',
|
||||
userAgent: request.headers.get('user-agent') ?? 'unknown',
|
||||
context,
|
||||
})
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const authHeader = request.headers.get('authorization')
|
||||
const expectedAuth = `Bearer ${env.CRON_SECRET}`
|
||||
if (authHeader !== expectedAuth) {
|
||||
|
||||
Reference in New Issue
Block a user