fix: add HMAC-SHA256 signature for outbound webhook events (PILOT-90)#3
Merged
Merged
Conversation
The webhook Client POSTs unsigned JSON with no integrity or authenticity guarantee. Add an optional pre-shared secret (WithSecret option); when set, every outbound POST includes an X-Pilot-Signature-256 header with the hex-encoded HMAC-SHA256 of the request body. Receivers that do not care about signatures simply ignore the header (backward-compatible). Receivers that DO care recompute the HMAC against the shared secret and reject mismatches. Changes: - Client.secret field + WithSecret() option - crypto/hmac, crypto/sha256, encoding/hex imports - post() switches from client.Post to http.NewRequest + client.Do to inject the header (same send semantics, same retry+circuit-breaker logic preserved) Verification: - go build ./... → clean - go vet ./... → clean - All existing tests pass + new TestWebhookClientHMACSignatureHeader and TestWebhookClientNoSignatureWhenNoSecret Closes PILOT-90
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
What
The webhook
ClientPOSTs unsigned JSON with no integrity or authenticity guarantee. Anyone who can reach the configured URL — MITM, spoofed IP, leaked URL — can forge events the receiver will treat as authentic.Fix
Add an optional pre-shared secret via
WithSecret(secret string)client option. When set, every outbound POST includes anX-Pilot-Signature-256header containing the hex-encoded HMAC-SHA256 of the request body.Backward-compatible: receivers that do not care about signatures simply ignore the header.
Files changed
Client.secretfield,WithSecret()option, HMAC computation inpost(),POST→http.NewRequest + client.Doto inject the header (same send + retry + circuit-breaker semantics)TestWebhookClientHMACSignatureHeader(secret → header present, validates HMAC) +TestWebhookClientNoSignatureWhenNoSecret(no secret → no header)Verification
Closes PILOT-90