feat: implement REST API views and HMAC-based webhook authentication for event ingestion#443
Open
Dantama022 wants to merge 3 commits intoSoroScan:mainfrom
Open
Conversation
|
@Dantama022 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Webhook HMAC Validation Decorator Implementation
I have implemented a new HMAC validation decorator for SoroScan webhooks. This allows receiver endpoints to verify the authenticity of incoming webhooks from SoroScan.
Changes Made
Decorator Implementation I created decorators.py which contains the webhook_hmac_required decorator.
Extracts contract_id from the JSON payload.
Retrieves the applicable WebhookSubscription secret from the database.
Verifies the X-SoroScan-Signature header (supporting SHA-256 and SHA-1).
Uses hmac.compare_digest to prevent timing attacks.
Sample Endpoint
I added a sample receiver endpoint in views.py and registered it in urls.py.
Endpoint:
POST /api/ingest/webhooks/receiver-example/
Protected by @webhook_hmac_required()
Tests
I created
test_decorators.py
with comprehensive tests for:
Valid SHA-256 and SHA-1 signatures.
Invalid and missing signatures.
Missing contract ID and inactive subscriptions.
Verification Results
Linting and Formatting
Ruff: All checks passed.
Formatting: Applied ruff format to all new and modified files.
Closes #334