Add verifyRequestSignature helper for webhook validation#227
Merged
mike-engel merged 1 commit intoJul 2, 2026
Merged
Conversation
Adds a helper to verify that incoming reporting-webhook requests genuinely came from Customer.io, addressing customerio#155. Customer.io signs each request with an HMAC-SHA256 over `v0:<timestamp>:<body>` keyed with your webhook signing secret, sent hex-encoded in the X-CIO-Signature header. The helper recomputes that signature and compares it in constant time (crypto.timingSafeEqual), guarding the length first. It accepts string or Buffer bodies to avoid lossy re-serialization, returns false for a missing/malformed signature, and throws MissingParamError only for an empty signing secret. Includes 11 unit tests (100% coverage), a README section, and the package export.
mike-engel
approved these changes
Jul 2, 2026
Collaborator
|
Thanks for this @brian717! This will go out in the next release |
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.
Summary
Adds a
verifyRequestSignaturehelper so consumers can verify that incoming Customer.io reporting webhooks are authentic, addressing #155.Also, updated the README under a new "Webhooks" section. If this is not important enough to take up space in the main README, it can be removed (or maybe moved elsewhere?)
Testing
11 new unit tests in
test/webhooks.ts, lint and prettier run. All passed locally.Notes
.digest('hex')convention (the docs don't state it explicitly).Note
Medium Risk
Touches webhook authentication logic; incorrect verification could accept forged webhooks, though the change is additive and well-tested.
Overview
Adds
verifyRequestSignatureso apps can confirm Customer.io reporting webhooks are authentic (addresses #155). The helper recomputes HMAC-SHA256 overv0:<timestamp>:<body>with the webhook signing secret, compares the hex digest toX-CIO-SignatureviatimingSafeEqual(with length checks first), and returnsfalsefor bad/missing signatures while throwingMissingParamErrorifsigningSecretis empty. It accepts rawstringorBufferbodies andstringornumbertimestamps.Implementation lives in new
lib/webhooks.ts, re-exported from the package entrypoint. The README gains a Webhooks section with an Express-style example and option docs.test/webhooks.tsadds 11 unit tests covering valid signatures, a golden hash, tampering, wrong secret/timestamp, malformed signatures, and empty secret.Reviewed by Cursor Bugbot for commit 496c2fd. Bugbot is set up for automated code reviews on this repo. Configure here.