1
votes

I'm trying to use the Twilio Node SDK with my Express app as per the docs here https://www.twilio.com/docs/usage/tutorials/how-to-secure-your-express-app-by-validating-incoming-twilio-requests in order to validate that requests to my webhook endpoints are in fact coming from Twilio.

I have the TWILIO_AUTH_TOKEN environment variable set in my production environment and have my webhook endpoint defined like so:

router.post(
  "/foo",
  twilio.webhook(),
  async (req, res) => {
    ...
  }

However, when I send an SMS to the Twilio number which triggers the webhook, it returns a 403. From inspecting the debugger in the Twilio console the response body is Twilio Request Validation Failed.

Not too sure what I could be doing wrong here as the docs make it sound fairly straightforward. If I remove the twilio.webhook() line everything works as expected. The webhook endpoint is https, and I have SSL Certificate Validation enabled in my Twilio account.

2

2 Answers

0
votes

I ended up getting this to work by just following the steps in the Twilio security guide to generate the hash myself and compare it with the x-twilio-signature header. My only guess is that the Twilio Node SDK is buggy.

0
votes

Just text your number, it is not expecting a request via http, but from Twilio (when your number gets a text and Twilio calls the webhook)