feat(webhook): Add Gitea webhook signature validation support - #66895
feat(webhook): Add Gitea webhook signature validation support#66895MISAKIGA wants to merge 3 commits into
Conversation
Gitea sends X-Gitea-Signature header with HMAC-SHA256 hex digest. This patch adds support for validating Gitea webhook signatures. Fixes: Gitea webhooks fail with 'Invalid signature' error Related-to: https://github.com/NousResearch/hermes-agent
Review — addresses #66893. Verdict: correct, minimal fix; the one gap is missing test coverage. What's solid
Gaps / suggestions
Net: the change is safe to merge on correctness; adding the parallel test in |
Related: #63108 is the earlier open Gitea/Forgejo superset (event-header recognition, signature validation, and tests). This PR is signature-only and its live diff contains no regression tests, so it is related competing work rather than a duplicate. |
- Add _gitea_signature() helper function - Add test_validate_gitea_signature_valid - Add test_validate_gitea_signature_invalid - Add test_validate_gitea_signature_wrong_body_rejected - Add X-Gitea-Signature to non-ASCII header rejection test - Add comment explaining X-Hub-Signature-256 fallback for modern Gitea All 30 signature validation tests pass. Addresses PR review feedback on NousResearch#66895
This PR now provides full Gitea and Forgejo webhook support: **Signature Validation:** - X-Gitea-Signature (HMAC-SHA256 hex, no prefix) - X-Forgejo-Signature (same format as Gitea) **Event Type Extraction:** - X-Gitea-Event header recognition - X-Forgejo-Event header recognition **Tests Added:** - test_validate_gitea_signature_valid/invalid/wrong_body - test_validate_forgejo_signature_valid/invalid/wrong_body - test_event_filter_accepts_gitea_event/rejects_non_matching - test_event_filter_accepts_forgejo_event/rejects_non_matching - X-Gitea-Signature and X-Forgejo-Signature in non-ASCII test **Test Results:** - 33 signature validation tests pass - 8 event filter tests pass This supersedes NousResearch#63108 by providing complete implementation with matching tests (no test/code gaps). Closes NousResearch#66893
|
Thanks for the complete follow-up. Current main at Automated hermes-sweeper review. |
|
Heads-up: this PR currently shows as dirty (conflicts with main). I just tested the rebase locally against current
So a plain Also worth noting for the maintainer choosing scope: our focused header-recognition PR (#83723) is being closed in favor of this one, since it is a strict superset (headers + signature validation). |
- Add _gitea_signature() helper function - Add test_validate_gitea_signature_valid - Add test_validate_gitea_signature_invalid - Add test_validate_gitea_signature_wrong_body_rejected - Add X-Gitea-Signature to non-ASCII header rejection test - Add comment explaining X-Hub-Signature-256 fallback for modern Gitea All 30 signature validation tests pass. Addresses PR review feedback on NousResearch#66895
Pull Request: Add Gitea Webhook Signature Validation Support
Summary
This PR adds support for Gitea webhook signature validation in Hermes Gateway.
Problem
Gitea webhooks fail with
Invalid signatureerror because Hermes Gateway does not recognize theX-Gitea-Signatureheader format.Solution
Add Gitea signature validation logic to
_validate_signature()method ingateway/platforms/webhook.py.Changes
Technical Details
X-Hub-Signature-256sha256=<hex>X-Gitlab-Token<plain secret>X-Gitea-Signature<hex>(raw)X-Webhook-Signature<hex>Gitea sends the raw HMAC-SHA256 hex digest without the
sha256=prefix that GitHub uses.Testing
Test Environment
Test Steps
Expected Result
Invalid signaturewarning in logsImpact
Security
_hmac_str_equal) to prevent timing attacksRelated
Checklist