mirror of
https://github.com/Luchexx/wacrm.git
synced 2026-11-02 17:29:45 +00:00
Merge pull request #396 from opastorello/fix/cron-timing-safe
fix: use timing-safe compare for cron secret
This commit is contained in:
commit
96e60adecf
@ -1,3 +1,4 @@
|
||||
import { timingSafeEqual } from 'node:crypto'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { supabaseAdmin } from '@/lib/automations/admin-client'
|
||||
import { resumePendingExecution } from '@/lib/automations/engine'
|
||||
@ -19,8 +20,13 @@ export async function GET(request: Request) {
|
||||
if (!expected) {
|
||||
return NextResponse.json({ error: 'cron not configured' }, { status: 503 })
|
||||
}
|
||||
const supplied = request.headers.get('x-cron-secret')
|
||||
if (supplied !== expected) {
|
||||
const supplied = request.headers.get('x-cron-secret') ?? ''
|
||||
const suppliedBuf = Buffer.from(supplied)
|
||||
const expectedBuf = Buffer.from(expected)
|
||||
if (
|
||||
suppliedBuf.length !== expectedBuf.length ||
|
||||
!timingSafeEqual(suppliedBuf, expectedBuf)
|
||||
) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user