- Symptom
- verifySignature returns false for live eventsVerification passes for a single test event and fails for batched eventsWorks in unit tests with sample payload, fails behind Express
- Cause
- The ECDSA signature covers the timestamp header plus the raw request bytes, including the line breaks SendGrid puts between batched events. Parsing and re-stringifying the JSON changes those bytes.
- Fix
- Capture the raw body before any JSON middleware and verify against it with the public key from the Event Webhook security settings.
- Apply
app.post('/sg-events', express.raw({ type: 'application/json' }), (req, res) => { const ew = new EventWebhook(); const ok = ew.verifySignature(ew.convertPublicKeyToECDSA(PUBLIC_KEY), req.body, req.get('X-Twilio-Email-Event-Webhook-Signature'), req.get('X-Twilio-Email-Event-Webhook-Timestamp')); res.sendStatus(ok ? 200 : 403); });- Affected
- SendGrid signed Event Webhook, @sendgrid/eventwebhook and sendgrid-python helpers, as of 2026-10
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders