Skip to content
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

Event Webhook only works for a single event payload #1238

Closed
Abr3u opened this issue Jan 5, 2021 · 16 comments · Fixed by #1271
Closed

Event Webhook only works for a single event payload #1238

Abr3u opened this issue Jan 5, 2021 · 16 comments · Fixed by #1271
Labels
type: bug bug in the library

Comments

@Abr3u
Copy link

Abr3u commented Jan 5, 2021

Issue Summary

The helper library to validate the webhook signature only works when the payload has a single event. when the payload is an array of multiple JSON objects the signature always returns false. as seen here: https://github.com/sendgrid/sendgrid-nodejs/blob/main/packages/eventwebhook/src/eventwebhook.spec.js there is only 1 test and this tests uses a payload with a single event. I've opened a ticket with the sendgrid support team who told me to open an issue here stating the problem.

Steps to Reproduce

  1. setup a signed webhook as seen here: https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook-security-features/
  2. if sendgrid sends a single event per request everything is fine and the verifySignature function always returns true
  3. if sendgrid aggregates 2 or more events in a single request the verifySignature function returns false

Code Snippet

Basically the same as here: https://github.com/sendgrid/sendgrid-nodejs/blob/main/packages/eventwebhook/src/eventwebhook.spec.js with the payload being a 2 object array.

Exception/Log

No exception, just returns false

Technical details:

I have an example payload, signature and timestamp received that I shared with the support team when creating the ticket but since the payload contains sensitive information I'm not pasting that here. I'll be glad to do so via a private chat or something similar.
To quote the answer that I got from the technical support: "I have looked into this further and would agree this could be a library specific issue with the configuration since a single event works. I also reviewed the payload and do not see anything that is wrong. "

I'm running this code in a aws lambda running Node.js 12.x. To be able to use the webhook helper lib I copied this file into my lambda env https://github.com/sendgrid/sendgrid-nodejs/blob/main/packages/eventwebhook/src/eventwebhook.js and used it as shown in its respective tests (as linked above)

@thinkingserious thinkingserious added status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Jan 7, 2021
@thinkingserious
Copy link
Contributor

Thanks for taking the time to report this @Abr3u!

Could you please provide your support ticket number so I can dig in and try to reproduce?

With best regards,

Elmer

@Abr3u
Copy link
Author

Abr3u commented Jan 7, 2021 via email

@JenniferMah JenniferMah added status: help wanted requesting help from the community type: bug bug in the library and removed type: question question directed at the library status: waiting for feedback waiting for feedback from the submitter labels Feb 1, 2021
@JenniferMah
Copy link
Contributor

Hi @Abr3u
I was able to reproduce this bug. 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.

@edsrodrigues
Copy link

Hi @JenniferMah @thinkingserious ,

I'm having exactly the same problem. It's not returning any exception and return false.

Do you have any expected resolution time for this?

@shwetha-manvinkurke
Copy link
Contributor

@edsrodrigues We do not yet have an expected resolution time for this. That said, +1s and PRs will definitely help it move up our backlog.

@khaosans
Copy link

Yes, I realized that before but didn't know it was a bug. Thanks

@BeigeBox
Copy link

We're also running into this problem. +1

@mattmorganpdx
Copy link

I've hit this problem too

@AndreRog
Copy link

AndreRog commented Apr 1, 2021

+1 I'm having the same issue

@nFangueiro
Copy link

+1 Happen to me already

@RJRVAZ
Copy link

RJRVAZ commented Apr 5, 2021

+1 already had the same issue

@tiagobgarcia
Copy link

+1 Same issue here

@MihailCuculici
Copy link

+1 Same issue here

@uberj
Copy link

uberj commented Apr 28, 2021

+1

@shwetha-manvinkurke shwetha-manvinkurke added status: work in progress Twilio or the community is in the process of implementing and removed status: help wanted requesting help from the community labels Apr 28, 2021
@shwetha-manvinkurke shwetha-manvinkurke removed the status: work in progress Twilio or the community is in the process of implementing label Apr 29, 2021
@mayureshs
Copy link

+1 same issue here. It is also happening on Csharp side as well.

@DanielGeoffreyHodgkins
Copy link

@mayureshs if you're still needing a fix and anyone else who finds this issue while searching (like I did):

The test code has the correct way to stringify your payload from the incoming webhook

const PAYLOAD_MULTIPLE_EVENTS = JSON.stringify(eventsPayloadMultiple).split('},{').join('},\r\n{') + '\r\n'; // Be sure to include the trailing carriage return and newline after each event

https://github.com/sendgrid/sendgrid-nodejs/blob/main/packages/eventwebhook/src/eventwebhook.spec.js#L48

You may have to tweak it for your C# issues but this format should be consistent across the board. Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug bug in the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.