fix(webhooks): compare signatures in constant time - #331
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
🧪 Test coverage
✅ Every endpoint operation was reached by a real request. Endpoint reach is measured from HTTP requests actually sent by the suite (see tests/utils/client.py). See TESTING.md. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Non-ASCII signatures raise an unexpected TypeError and prevent later valid signatures from matching.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Hardens webhook verification against timing leaks while preserving support for rotated signatures.
Changes:
- Uses
hmac.compare_digestfor signature comparisons. - Adds tests for a later valid signature and a near-match rejection.
| File | Description |
|---|---|
tests/test_webhooks.py |
Adds signature acceptance and rejection tests. |
src/gr4vy/webhooks.py |
Replaces membership checking with constant-time comparisons. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
hmac.compare_digest raises TypeError on non-ASCII strings, so a header containing one skipped the ValueError path and any valid signature after it. Compare bytes instead. 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. Bytes, because
compare_digestraisesTypeErroron non-ASCII strings.🤖 Generated with Claude Code