File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -380,15 +380,16 @@ class LicenseChainClient {
380380 }
381381
382382 /**
383- * Verify webhook signature
383+ * Verify webhook signature (HMAC-SHA256) using constant-time comparison.
384384 */
385385 verifyWebhookSignature ( payload , signature , secret ) {
386- const expectedSignature = crypto
387- . createHmac ( 'sha256' , secret )
388- . update ( payload )
389- . digest ( 'hex' ) ;
390-
391- return signature === `sha256=${ expectedSignature } ` ;
386+ if ( ! payload || ! signature || ! secret ) return false ;
387+ const expected = crypto . createHmac ( 'sha256' , secret ) . update ( payload ) . digest ( 'hex' ) ;
388+ const received = String ( signature ) . startsWith ( 'sha256=' ) ? String ( signature ) . slice ( 7 ) : String ( signature ) ;
389+ const a = Buffer . from ( expected , 'hex' ) ;
390+ const b = Buffer . from ( received , 'hex' ) ;
391+ if ( a . length !== b . length ) return false ;
392+ return crypto . timingSafeEqual ( a , b ) ;
392393 }
393394
394395 /**
You can’t perform that action at this time.
0 commit comments