@@ -625,15 +625,35 @@ describe("verifyTwilioWebhook", () => {
625625 query : { callId : "call-1" , turnToken : "secret-turn-token" } ,
626626 } ,
627627 "test-auth-token" ,
628+ { publicUrl :
"https://user:[email protected] /callback#fragment-secret" } , 628629 ) ;
629630
630631 expect ( result . ok ) . toBe ( false ) ;
631632 expect ( result . reason ) . toContain ( "Invalid signature for URL:" ) ;
632633 expect ( result . reason ) . toContain ( "turnToken=***" ) ;
633634 expect ( result . reason ) . toContain ( "callId=***" ) ;
634635 expect ( result . reason ) . not . toContain ( "secret-turn-token" ) ;
635- expect ( result . verificationUrl ) . toContain ( "turnToken=***" ) ;
636- expect ( result . verificationUrl ) . not . toContain ( "secret-turn-token" ) ;
636+ expect ( result . reason ) . not . toContain ( "user:pass" ) ;
637+ expect ( result . reason ) . not . toContain ( "fragment-secret" ) ;
638+ } ) ;
639+
640+ it ( "does not echo malformed verification URLs in diagnostics" , ( ) => {
641+ const result = verifyTwilioWebhook (
642+ {
643+ headers : { "x-twilio-signature" : "invalid" } ,
644+ rawBody : "CallSid=CS123" ,
645+ url : "https://local/voice/webhook" ,
646+ method : "POST" ,
647+ } ,
648+ "test-auth-token" ,
649+ { publicUrl : "not a url?turnToken=secret-turn-token" } ,
650+ ) ;
651+
652+ expect ( result ) . toMatchObject ( {
653+ ok : false ,
654+ reason : "Invalid signature for URL: <invalid verification URL>" ,
655+ } ) ;
656+ expect ( result . reason ) . not . toContain ( "secret-turn-token" ) ;
637657 } ) ;
638658
639659 it ( "treats changed idempotency header as replay for identical signed requests" , ( ) => {
@@ -738,7 +758,8 @@ describe("verifyTwilioWebhook", () => {
738758
739759 expect ( result . ok ) . toBe ( false ) ;
740760 // Attacker's host is ignored - uses Host header instead
741- expect ( result . verificationUrl ) . toBe ( "https://legitimate.example.com/voice/webhook" ) ;
761+ expect ( result . reason ) . toContain ( "https://legitimate.example.com/voice/webhook" ) ;
762+ expect ( result . verificationUrl ) . toBeUndefined ( ) ;
742763 } ) ;
743764
744765 it ( "uses X-Forwarded-Host when allowedHosts whitelist is provided" , ( ) => {
@@ -820,7 +841,8 @@ describe("verifyTwilioWebhook", () => {
820841
821842 expect ( result . ok ) . toBe ( false ) ;
822843 // Attacker's host not in whitelist, falls back to Host header
823- expect ( result . verificationUrl ) . toBe ( "https://localhost/voice/webhook" ) ;
844+ expect ( result . reason ) . toContain ( "https://localhost/voice/webhook" ) ;
845+ expect ( result . verificationUrl ) . toBeUndefined ( ) ;
824846 } ) ;
825847
826848 it ( "trusts forwarding headers only from trusted proxy IPs" , ( ) => {
@@ -900,7 +922,8 @@ describe("verifyTwilioWebhook", () => {
900922 ) ;
901923
902924 expect ( result . ok ) . toBe ( false ) ;
903- expect ( result . verificationUrl ) . toBe ( "https://legitimate.example.com/voice/webhook" ) ;
925+ expect ( result . reason ) . toContain ( "https://legitimate.example.com/voice/webhook" ) ;
926+ expect ( result . verificationUrl ) . toBeUndefined ( ) ;
904927 } ) ;
905928 it ( "succeeds when Twilio signs URL without port but server URL has port" , ( ) => {
906929 const authToken = "test-auth-token" ;
0 commit comments