File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -85,4 +85,5 @@ export interface Adapter {
85
85
res ?: Response ,
86
86
) => Promise < { apiKey : string ; apiUrl : string } > ;
87
87
handleWebhook ?: ( req : Request ) => Promise < ContactsChangedData > ;
88
+ verifyWebhookRequest ?: ( req : Request ) => Promise < boolean > ;
88
89
}
Original file line number Diff line number Diff line change @@ -1350,11 +1350,20 @@ export class Controller {
1350
1350
}
1351
1351
1352
1352
public async handleWebhook ( req : Request , res : Response ) : Promise < void > {
1353
- try {
1354
- if ( ! this . adapter . handleWebhook ) {
1355
- throw new ServerError ( 501 , 'Webhook handling not implemented' ) ;
1356
- }
1353
+ if ( ! this . adapter . handleWebhook ) {
1354
+ throw new ServerError ( 501 , 'Webhook handling not implemented' ) ;
1355
+ }
1356
+
1357
+ if ( ! this . adapter . verifyWebhookRequest ) {
1358
+ throw new ServerError ( 501 , 'Webhook verification not implemented' ) ;
1359
+ }
1360
+
1361
+ const verified = await this . adapter . verifyWebhookRequest ( req ) ;
1362
+ if ( ! verified ) {
1363
+ throw new ServerError ( 403 , 'Webhook verification failed' ) ;
1364
+ }
1357
1365
1366
+ try {
1358
1367
const contactsChangedData : ContactsChangedData =
1359
1368
await this . adapter . handleWebhook ( req ) ;
1360
1369
You can’t perform that action at this time.
0 commit comments