Validate HMAC key from Tito webhook request before adding user to customer.io #115
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.
This PR implements verification of the HMAC key header present on incoming webhook requests from Tito, based on the information provided in their docs.
Prior to this verification, event registration could be spoofed by simply hitting the webhook endpoint with a payload containing a
first_name
,last_name
, andemail
. Granted, the negative implications of doing so were minimal, given this just adds users to the customer.io database and signs them up for the mailing list. But this added validation prevents abuse, eliminates potential spam/invalid data ending up in customer.io, and bolsters the site against denial of service attacks.Prerequisites
The verification requires that an admin of the Begin deployment sets an additional environment variable,
TITO_SECURITY_TOKEN
, which matches the security token present on the Tito event settings page. This can be found by going to the event dashboard in Tito, then navigating to Settings > Webhook endpoints.The annoying caveat to this is that presently, security tokens are uniquely generated per event. I've reached out to Tito to inquire about account-wide security tokens, or at least the ability to custom-set a token or copy a token from a previous event when you duplicate it. But until then, it will be necessary to rotate the security token each month when setting up the new Tito event. To that end, I've added an additional item to the meetup checklist to help with remembering to update this. 🙂
Test plan
Valid requests
.env
addToCustomerIO
, add basic logging offirst_name
,last_name
, andemail
instead (since we don't actually want to save a user for testing 😛)${publicURL}/webhooks/tito
, give it at least theregistration.completed
eventInvalid requests
Missing signature
${publicURL}/webhooks/tito
without any header, body doesn't matterInvalid/mismatched signature
${publicURL}/webhooks/tito
with the request payload body and signature header values you copied