Repository navigation
fix(webhooks): compare signatures in constant time - #328
Merged
Merged
Conversation
The old comparison stopped at the first character that differed, so how long a rejection took showed how much of a guessed signature was right. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Endpoint-reach coverage120 / 120 operations reached by a real HTTP request (100%). Every operation in the SDK was reached. 🎉 |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The timing-safe comparison operands must be reversed so execution time depends on the fixed expected digest length.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Updates webhook signature verification to use timing-safe comparisons while preserving signature rotation support.
Changes:
- Uses
MessageDigest.isEqualfor signature checks. - Adds valid-position and near-match tests.
| File | Description |
|---|---|
src/main/java/com/gr4vy/sdk/Webhooks.java |
Adds timing-safe signature comparison. |
src/test/java/com/gr4vy/sdk/WebhooksTest.java |
Adds signature verification coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
MessageDigest.isEqual takes time in proportion to its first argument, which was the signature from the header. Put the fixed-length expected one first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Compares webhook signatures in constant time.
The old comparison stops at the first character that differs, so how long a rejection takes shows how much of a guessed signature was right. Rotation still works: any one of the comma-separated signatures can match. The expected signature goes first because
isEqual's time follows its first argument's length.🤖 Generated with Claude Code