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

[CCAP-612] Fixing Sendgrid callback #1043

Merged
merged 8 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/org/ilgcc/app/email/SendGridWebhookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ public void handleSendGridEvents(HttpServletRequest request)
Security.addProvider(new BouncyCastleProvider());
final EventWebhook ew = new EventWebhook();
final ECPublicKey ellipticCurvePublicKey = ew.ConvertPublicKeyToECDSA(sendGridPublicKey);
final boolean valid = ew.VerifySignature(ellipticCurvePublicKey, requestBody, signature, timestamp);

// Sendgrid payloads should always end with a CRLF for validation
boolean valid = ew.VerifySignature(ellipticCurvePublicKey, requestBody + "\r\n", signature, timestamp);

if (!valid) {
log.error("Invalid signature for SendGrid events was provided. Ignoring events.");
return;
// Sendgrid's test API doesn't apparently have a trailing CRLF, so we can try again
// But also raise this error here, and have an alert so if this ever happens in reality
// we can debug further
log.error("Invalid signature for SendGrid events was provided. Removing CRLF modifier.");
valid = ew.VerifySignature(ellipticCurvePublicKey, requestBody, signature, timestamp);

if (!valid) {
log.error("Invalid signature for SendGrid events was provided. Ignoring events.");
return;
}
}

log.info("Received SendGrid events {}", requestBody);
Expand Down
Loading