Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TITO_SECURITY_TOKEN=xxx
TWITTER_STREAM_KEY=xxx
TWITCH_STREAM_KEY=xxx
YOUTUBE_STREAM_KEY=xxx
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/meetup-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ assignees: ''
- [ ] duplicate meetup survey and update speaker info (Google Docs)
- [ ] send email via Tito to previous month's attendees with link to survey + link to tickets
- [ ] update website with event json
- [ ] update TITO_SECURITY_TOKEN on Begin to match ti.to event security token (go to ti.to event > Settings > Webhook endpoints to view)

## (3 weeks out)
- [ ] confirm sponsor & update website
Expand Down
23 changes: 21 additions & 2 deletions app/api/webhooks/tito.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import crypto from 'crypto'
//import { addToCustomerIO } from "../signup.mjs"

/* TODO: this code block (addToCustomerIO) is copied from ../signup.mjs because (for some reason) importing this function
Expand Down Expand Up @@ -34,9 +35,27 @@ export async function addToCustomerIO(first_name, last_name, email_address) {

// process webhook requests from Tito.io, the ticketing system for SeattleJS meetups. Add these users to our mailing list.
export async function post(req) {
// Check for the presence of the signature header.
const signature = req.headers['tito-signature']
if (!signature || signature === '') {
return {
json: { ok: false, error: 'missing security signature header' },
statusCode: 401
}
}

// Create an HMAC with the payload body using our security token, and convert to base64.
const hmac = crypto.createHmac('sha256', process.env.TITO_SECURITY_TOKEN)
const digest = hmac.update(req.rawBody).digest('base64')

if (signature !== digest) {
return {
json: { ok: false, error: 'security signature does not match' },
statusCode: 401
}
}

let { first_name, last_name, email } = req.body
//console.log(first_name, last_name, email)
await addToCustomerIO(first_name, last_name, email)
//console.log(foo)
return { json: { ok: true } }
}