You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on a Conversations webhook we noticed that twilio signature validation would occasionally return a false negative with certain combinations of parameters, in our case the "MessagingBinding.Address" array with group messaging.
Digging into this we discovered that the sorting logic doesn't account for the values of like-named parameters, leading to occurrences of signatures not matching between the Twilio header and the expected signature from the Twilio SDK validateSignature helper method.
Below is an example of a constructed string read from breakpointing the method which leads to a 'false' validation result:
Taking the value returned from toFormUrlEncodedParam, manually arranging the order of each of the "MessagingBinding.Address" parameters, and running the crypto function to compare returned a matching signature sent with the original request.
Setup a webhook route on a test server that will receive Twilio Conversation events. We encountered this issue in the "onConversationAdd" pre-event.
Have a Twilio number point to a message service that uses conversations and has the "auto create conversation" integration setting enabled.
Send a group message with more than two recipients. The more recipient phone numbers added the more likely you will encounter this problem as it depends on how the .sort on the "MessagingBinding.Address" parameter comes out.
We were able to prevent this issue from occurring if we checked for any array parameters and pre-sorted their items before passing it into the validateRequest method like below:
Looking at the toFormUrlEncodedParam method there is a check to see if the parameter is an array before recursively mapping the array values for the accumulated string. Adding a sort before the .map call would ensure array values are pre-sorted to match the signature returned from Twilio server:
@KyleLehtinenDev thanks for bringing this to our attention. This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.
Hi, our team just came across the issue as well, with Autopilot picking up multiple parameters for a field type. Seems to be an issue in all of the Twilio language modules that I have tested (and probably more from the quick skimming of the code) and not mentioned in the security documentation.
Assuming Twilio is using this module to validate the requests in their new feature "Functions", this will be the reason why it is rejecting any requests multiple values set to one parameter.
Issue Summary
While working on a Conversations webhook we noticed that twilio signature validation would occasionally return a false negative with certain combinations of parameters, in our case the "MessagingBinding.Address" array with group messaging.
Digging into this we discovered that the sorting logic doesn't account for the values of like-named parameters, leading to occurrences of signatures not matching between the Twilio header and the expected signature from the Twilio SDK
validateSignature
helper method.Below is an example of a constructed string read from breakpointing the method which leads to a 'false' validation result:
Taking the value returned from
toFormUrlEncodedParam
, manually arranging the order of each of the "MessagingBinding.Address" parameters, and running the crypto function to compare returned a matching signature sent with the original request.Altered string that passes
Steps to Reproduce
To recreate our scenario:
.sort
on the "MessagingBinding.Address" parameter comes out.We were able to prevent this issue from occurring if we checked for any array parameters and pre-sorted their items before passing it into the
validateRequest
method like below:Looking at the
toFormUrlEncodedParam
method there is a check to see if the parameter is an array before recursively mapping the array values for the accumulated string. Adding a sort before the.map
call would ensure array values are pre-sorted to match the signature returned from Twilio server:Technical details:
The text was updated successfully, but these errors were encountered: