@@ -388,19 +388,9 @@ export async function handleWebhook(
388388
389389 const provider : WebhookProvider = providerParam
390390
391- // Build and validate provider configuration from environment
391+ // Build provider configuration from environment (may be null if secret not set)
392392 const config = createProviderConfigFromEnv ( env , provider )
393393
394- // Reject requests if webhook is not properly configured
395- if ( ! config ) {
396- log . error ( 'Provider not configured or invalid' , { provider } )
397- return createErrorResponse (
398- 'Webhook not configured for this provider' ,
399- 'SECRET_NOT_CONFIGURED' ,
400- 500
401- )
402- }
403-
404394 // Check Content-Length header first (fast rejection)
405395 const contentLength = request . headers . get ( 'content-length' )
406396 if ( contentLength ) {
@@ -451,16 +441,17 @@ export async function handleWebhook(
451441 }
452442 }
453443
454- // Verify signature - always required when secret is configured
455- const verification = await verifySignature ( provider , config . secret , rawBody , request . headers )
456- if ( ! verification . valid ) {
457- log . warn ( 'Signature verification failed' , { provider, errorType : verification . error ?. split ( ':' ) [ 0 ] } )
458- return createErrorResponse (
459- 'Signature verification failed' ,
460- getErrorCodeFromVerification ( verification . error ?? 'Invalid signature' ) ,
461- 401 ,
462- { details : verification . error }
463- )
444+ // Verify signature if secret is configured, otherwise accept unverified
445+ let verified = false
446+ if ( config ) {
447+ const verification = await verifySignature ( provider , config . secret , rawBody , request . headers )
448+ if ( ! verification . valid ) {
449+ log . warn ( 'Signature verification failed' , { provider, errorType : verification . error ?. split ( ':' ) [ 0 ] } )
450+ // Accept anyway but mark as unverified — verification will be layered in later
451+ }
452+ verified = verification . valid
453+ } else {
454+ log . info ( 'No secret configured, accepting unverified' , { provider } )
464455 }
465456
466457 // Parse the body
@@ -501,20 +492,19 @@ export async function handleWebhook(
501492 provider,
502493 eventType,
503494 deliveryId,
504- verified : true ,
495+ verified,
505496 } ,
506497 payload,
507498 }
508499
509- // Log successful webhook receipt (deliveryId is safe - it's a public identifier from the provider)
510- log . info ( 'Webhook received' , { provider, eventType, deliveryId : deliveryId ? sanitize . id ( deliveryId ) : undefined } )
500+ // Log webhook receipt (deliveryId is safe - it's a public identifier from the provider)
501+ log . info ( 'Webhook received' , { provider, eventType, verified , deliveryId : deliveryId ? sanitize . id ( deliveryId ) : undefined } )
511502
512503 // Return the normalized event
513- // The caller can decide what to do with it (store in R2, forward to queue, etc.)
514504 return Response . json ( {
515505 success : true ,
516506 accepted : true ,
517- verified : true ,
507+ verified,
518508 event : normalizedEvent ,
519509 } )
520510}
0 commit comments