seattlejs / seattlejs.com

The code for seattlejs.com
http://seattlejs.com
16 stars 12 forks source link

Validate HMAC key from Tito webhook request before adding user to customer.io #115

Open courier-new opened 1 year ago

courier-new commented 1 year ago

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, and email. 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

Invalid requests

Missing signature

Invalid/mismatched signature