MT-22022: Add webhook signature verification helper#53
Conversation
|
Warning Review limit reached
More reviews will be available in 59 minutes and 47 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds webhook signature verification to the Mailtrap Java SDK. A new ChangesWebhook Signature Verification
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Add `io.mailtrap.webhooks.WebhookSignatures.verify(payload, signature, signingSecret)` for verifying Mailtrap webhook signatures using HMAC-SHA256 over the raw request body with constant-time comparison via `MessageDigest.isEqual`. Returns false (no throw) for null/empty/malformed/wrong-length signatures and non-hex characters, so a single guard at the request handler covers every bad-input case. Includes the shared cross-SDK test fixture (payload + secret + expected signature) that all six Mailtrap SDKs use to stay byte-for-byte compatible, plus a Jakarta Servlet / Spring example and README subsection. See https://railsware.atlassian.net/browse/MT-22022
c534392 to
bfe3bad
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Motivation
Expose a helper so Java users don't have to re-implement Mailtrap's HMAC-SHA256 webhook signature check on every receiver.
Changes
io.mailtrap.webhooks.WebhookSignatures.verify(String payload, String signature, String signingSecret): boolean. HMAC-SHA256 over the raw body, constant-time compare viaMessageDigest.isEqual. Returnsfalse(never throws) onnull/ empty / wrong-length / non-hex inputs.src/test/java/io/mailtrap/webhooks/WebhookSignaturesTest.javapins the cross-SDK fixture (payload + signing_secret + expected digest) shared verbatim across all six official Mailtrap SDKs to guarantee byte-for-byte parity.examples/.../webhooks/WebhookSignatureExample.java— runnable usage snippet (mainmethod that asserts valid + bad inputs).How to test
CI runs the full maven test suite. Manually:
The last command should exit 0 with no output.
Companion PRs
Coordinated rollout across all six official SDKs (same algorithm, same shared fixture):
Summary by CodeRabbit
New Features
Documentation
Tests