File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 "https-proxy-agent" : " ^5.0.0" ,
2626 "jsonwebtoken" : " ^9.0.3" ,
2727 "qs" : " ^6.14.1" ,
28- "scmp" : " ^2.1.0" ,
2928 "xmlbuilder" : " ^13.0.2"
3029 },
3130 "devDependencies" : {
Original file line number Diff line number Diff line change 1- const scmp = require ( "scmp" ) ;
21import crypto from "crypto" ;
32import urllib from "url" ;
43import { IncomingHttpHeaders } from "http2" ;
@@ -257,15 +256,23 @@ function validateSignatureWithUrl(
257256 params
258257 ) ;
259258
260- return scmp ( Buffer . from ( twilioHeader ) , Buffer . from ( signatureWithoutPort ) ) ;
259+ return timingSafeEqual (
260+ Buffer . from ( twilioHeader ) ,
261+ Buffer . from ( signatureWithoutPort )
262+ ) ;
261263}
262264
263265export function validateBody (
264266 body : string ,
265267 bodyHash : any [ ] | string | Buffer
266268) : boolean {
267269 var expectedHash = getExpectedBodyHash ( body ) ;
268- return scmp ( Buffer . from ( bodyHash ) , Buffer . from ( expectedHash ) ) ;
270+ return timingSafeEqual ( Buffer . from ( bodyHash ) , Buffer . from ( expectedHash ) ) ;
271+ }
272+
273+ function timingSafeEqual ( a : Buffer , b : Buffer ) {
274+ if ( a . length !== b . length ) return false ;
275+ return crypto . timingSafeEqual ( a , b ) ;
269276}
270277
271278/**
You can’t perform that action at this time.
0 commit comments