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

Webhook library signature and timestamp functions return incorrect string values #1307

Open
imbenham opened this issue Sep 28, 2021 · 1 comment
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@imbenham
Copy link

Issue Summary

An apparent backend change to the sendgrid webhooks implementation has resulted in a change to the case of the signature and timestamp headers. For example, the signature header previously was "X-Twilio-Email-Event-Webhook-Signature" but now is "x-twilio-email-event-webhook-signature".

The helper functions to access the keys for these headers now return the incorrect values. Attempting to access the signature using the key form the helper nib now results in an undefined value:
const sig = headers[EventWebhookHeader.SIGNATURE()] // sig === undefined

Steps to Reproduce

  1. Set up webhooks and use the EventWebhookHeader.SIGNATURE() and EventWebhookHeader.TIMESTAMP() methods to extract the relevant header values.
  2. Note the result.

Code Snippet

const verifyWebhookSig = (headers: any|undefined, body: string) => {
  if (headers === undefined) {
    return false;
  }

  const signature = headers[EventWebhookHeader.SIGNATURE()];
  const timestamp = headers[EventWebhookHeader.TIMESTAMP()];

  console.log('signature', signature); // undefined
  console.log('timestamp', timestamp); // undefined

  if (signature === undefined || timestamp === undefined) {
    return false;
  }

  const eventWH = new EventWebhook();
  const pubKey = eventWH.convertPublicKeyToECDSA(webhookKey);
  return eventWH.verifySignature(pubKey, body, signature, timestamp);
};

Header examples

9/28/2021

'x-twilio-email-event-webhook-timestamp': '1632838793' 

9/9/2021

"X-Twilio-Email-Event-Webhook-Timestamp": "1631213066"

Technical details:

*@sendgrid/eventwebhook: 7.4.5,

  • node version:12.x
@eshanholtz
Copy link
Contributor

Interesting. I wasn't aware of the change. Thanks for bringing this to our attention. For now, I recommend casting the strings to lowercase, like so: EventWebhookHeader.SIGNATURE().toLowerCase().
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.

@eshanholtz eshanholtz added status: help wanted requesting help from the community type: bug bug in the library labels Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

2 participants