File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
packages/thirdweb/src/bridge Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -27,22 +27,31 @@ export async function parse<T extends Record<string, unknown>>(
27
27
tolerance = 300 , // Default to 5 minutes if not specified
28
28
) {
29
29
// Get the signature and timestamp from headers
30
+ // Normalize header keys to lowercase for broader compatibility
31
+ const lower = Object . fromEntries (
32
+ Object . entries ( headers ) . map ( ( [ k , v ] ) => [ k . toLowerCase ( ) , v ] ) ,
33
+ ) ;
30
34
const receivedSignature =
31
- headers [ "x-payload-signature" ] || headers [ "x-pay-signature" ] ;
35
+ lower [ "x-payload-signature" ] || lower [ "x-pay-signature" ] ;
32
36
const receivedTimestamp =
33
- headers [ "x-timestamp" ] || headers [ "x-pay-timestamp" ] ;
34
-
37
+ lower [ "x-timestamp" ] || lower [ "x-pay-timestamp" ] ;
35
38
if ( ! receivedSignature || ! receivedTimestamp ) {
36
39
throw new Error ( "Missing required webhook headers: signature or timestamp" ) ;
37
40
}
38
41
39
42
// Verify timestamp
40
43
const now = Math . floor ( Date . now ( ) / 1000 ) ;
41
44
const timestamp = Number . parseInt ( receivedTimestamp , 10 ) ;
45
+ if ( Number . isNaN ( timestamp ) ) {
46
+ throw new Error ( "Invalid webhook timestamp: must be a Unix epoch (seconds)" ) ;
47
+ }
42
48
const diff = Math . abs ( now - timestamp ) ;
43
49
44
50
if ( diff > tolerance ) {
45
51
throw new Error (
52
+ // …
53
+ ) ;
54
+ }
46
55
`Webhook timestamp is too old. Difference: ${ diff } s, tolerance: ${ tolerance } s` ,
47
56
) ;
48
57
}
You can’t perform that action at this time.
0 commit comments