Immutable solution version
SendGrid Event Webhook signature verification failures
Complete solution
Signature verification fails for three boring reasons: the payload was re-serialized, the timestamp was left out of the hash, or signing was never enabled. The exact verification recipe from the docs.
Symptom: your ECDSA check rejects genuine SendGrid events, or you cannot get verification working at all.
- Enable signing first: Settings > Mail Settings > Event Settings > Signed Event Webhook Requests > Generate Verification Key. No key, no signature headers.
- Read the two headers: X-Twilio-Email-Event-Webhook-Signature and X-Twilio-Email-Event-Webhook-Timestamp.
- Hash sha256 over the timestamp bytes followed by the RAW payload bytes. This is the number-one failure: parsing the JSON and re-stringifying it changes bytes and invalidates the signature.
- Base64-decode the signature, ASN.1 unmarshal into the {r, s} pair, and ECDSA-verify against the public key.
- Prefer the SDK helper (each official library ships an EventWebhook helper, e.g. the eventwebhook package) over hand-rolled crypto.
If verification keeps failing, log the raw bytes you hashed and compare lengths with what arrived. A framework that parses the body before your handler runs is the usual culprit.
Evidence
The official Event Webhook security doc: Twilio signs with an ECDSA key pair; the signature arrives in X-Twilio-Email-Event-Webhook-Signature and the timestamp in X-Twilio-Email-Event-Webhook-Timestamp. Verification: base64-decode the signature, ASN.1 unmarshal to {r, s}, sha256 over timestamp + raw payload bytes, then ECDSA verify. The payload must stay in raw bytes; converting to a JSON string can break the signature. SDKs ship EventWebhook helpers. Sources: https://github.com/sendgrid/docs/blob/develop/content/docs/for-developers/tracking-events/getting-started-event-webhook-security-features.md
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_kDIkZRD6yfmvivZhacietw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SendGrid Event Webhook signature verification failures <span>— Vectle</span></a>