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

Can't validate eventHook signature, help! #1411

Open
zheng-liu-seattle opened this issue Jul 31, 2024 · 1 comment
Open

Can't validate eventHook signature, help! #1411

zheng-liu-seattle opened this issue Jul 31, 2024 · 1 comment

Comments

@zheng-liu-seattle
Copy link

 const signature = req.headers[
   EventWebhookHeader.SIGNATURE().toLowerCase()
  ] as string;
  const timestamp = req.headers[
    EventWebhookHeader.TIMESTAMP().toLowerCase()
  ] as string;

  const payload = JSON.stringify(req.body).split('},{').join('},\r\n{') + '\r\n';

  if (!signature || !timestamp) {
    res.status(401).json(UNAUTHORIZED);
    return;
  }
  try {
    const eventWebhook = new EventWebhook();
    const isValid = eventWebhook.verifySignature(
      eventWebhook.convertPublicKeyToECDSA(publicKey),
      payload,
      signature,
      timestamp
    );
    }

isValid is always false... verified both timestamp and signature are there.

@hss-iullah
Copy link

I spent days looking into this, using the EXACT code supplied by Sendgrid. Spent weeks with their support team who just kept sending me the same stackoverflow links that I'd already read.
In the end I decided to remove the equivalent to this in their python code.
const payload = JSON.stringify(req.body).split('},{').join('},\r\n{') + '\r\n';

I then removed it from the node js code and it worked.
Poor documentation. The forums are full of it.

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

No branches or pull requests

2 participants