-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed WhatsApp Signature Validation #815
Comments
I'm afraid there're some cases that I didn't find in the Twilio official docs. For example: This https://github.com/twilio/twilio-node/blob/565cc4cc523ab7fe7efa3a9eb2dcc73bfa55e759/lib/webhooks/webhooks.js#L170-L184 This Is there any |
Hm, do you maybe see any issue in my nginx handler ? `location /api/ {
` |
@chentsulin Ah, wait it always comes with a second error:
|
For the first error, if you're using express behind nginx you may want to For the second error, are you sending any urls (for example, media url) in your app? could you show me the url or the function call? |
Oh, maybe I should make some changes to the inferred url:
And still need another two nginx configs to make it works: https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/
|
The server app is as reduced as this: server.set('trust proxy'); const verify = (req, _, buf) => { server.all('*', (req, res) => { |
Thank you so much for the update! I updated bottender to 1.4.7 as well as the NGINX server block: `
` But still getting the same error from f*** Twilio :( Any other hints?.. |
Are you able to print this out on your express server? This might helps a lot. const server = express();
server.use((req, res, next) => {
console.log('headers', JSON.stringify(req.headers));
console.log('hostname', req.hostname);
console.log('protocol', req.protocol);
console.log('requestUrl', `${req.protocol}://${req.hostname}${req.url}`);
next();
}); We should make sure the requestUrl here in your server match the url you registered on Twilio. |
here is the log: `"headers": { hostname: XXX.dev So I guess |
It's a little bit weird. I see your comment calling If you did that, you should change that line to one of the following call: server.set('trust proxy', true);
// or
server.enable('trust proxy'); Those two do the exactly same thing. See: https://github.com/expressjs/express/blob/18da651c5b57431f61391d9de2518a8c2ef88b2c/lib/application.js#L452-L454 But you can't call server.set('trust proxy'); |
@chentsulin Ah, damn it, my bad! I changed it and now it matches: "x-forwarded-proto":"https" and But I just realized the url ending requestUrl Any idea where this is happening? |
Could const server = express();
server.use((req, res, next) => {
console.log('originalUrl', req.originalUrl);
console.log('url', req.url);
console.log('requestUrl', `${req.protocol}://${req.hostname}${req.originalUrl}`);
next();
}); If |
I already tried. It is not supposed to be included in the
|
How about adding |
Note: you might need to modify path in your |
It's already inside a location block:
So I'm relatively sure I don't need the |
Ah, it has to be included on the proxy header as well, ofc!
EDIT: Which is actually not a soluction, since modifiying the host like that doesnt realy make sense... |
Okay, maybe this helps: Since it's all working FINE for other messengers here's the slack config: The Slack request URL is set to Path in bottender.config.js is set to Enabled trust proxy Log of a slack request:
NGINX block:
Why is this not working for twilio? |
Twilio is the only provider that uses HTTP URL to sign the signature. const server = express();
server.use((req, res, next) => {
req.url = `/api${req.url}`; // conditionally apply this on your proxy env
next();
}); Edit: Sorry my bad. Should be |
Not everyone have permission to change the settings of nginx, so maybe we should support some other options to config |
That indeed turn the log But results into a 502 on Twilio:
:/ :( |
After adding that path patch, you need to modify path in your
to
Note: This affects every channel (messenger, whatsapp...). |
Right, of course! This works. So briefly summarized:
Thanks a lot to @tw0517tw @chentsulin for this quick workaround!! |
Hey there!
Thank you for this great project!
Unfortunalety I'm having trouble connecting twilio (live credentials) to my whatsapp webhook (other webhooks work great)..
Twilio is trowing an "11200" errorCode containing this body:
{ "error": { "message": "WhatsApp Signature Validation Failed!", "request": { "rawBody": "xxx", "headers": { "x-twilio-signature": "xxxLzNwapQY4rGkb+mVFYO2I2jI=" } } } }
Any help would would be appreciated!
The text was updated successfully, but these errors were encountered: