From 2414c435250fbdd68f584cb5529882af5626af60 Mon Sep 17 00:00:00 2001 From: Maiko Kuppe Date: Wed, 19 Apr 2017 09:32:15 +0200 Subject: [PATCH 1/2] Calculate github-webhook sig from raw event body Applying JSON.stringify to the raw event body does not work (It is not even a JS object). --- aws-node-github-webhook-listener/handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-node-github-webhook-listener/handler.js b/aws-node-github-webhook-listener/handler.js index fd25a220d..a4d47b0a0 100644 --- a/aws-node-github-webhook-listener/handler.js +++ b/aws-node-github-webhook-listener/handler.js @@ -11,7 +11,7 @@ module.exports.githubWebhookListener = (event, context, callback) => { const sig = headers['X-Hub-Signature']; const githubEvent = headers['X-GitHub-Event']; const id = headers['X-GitHub-Delivery']; - const calculatedSig = signRequestBody(token, JSON.stringify(event.body)); + const calculatedSig = signRequestBody(token, event.body); if (typeof token !== 'string') { errMsg = '[401] must provide a \'GITHUB_WEBHOOK_SECRET\' env variable'; From cd45396f8081c857ba5c833c14e8ab790bc64c4a Mon Sep 17 00:00:00 2001 From: Maiko Kuppe Date: Wed, 19 Apr 2017 10:22:38 +0200 Subject: [PATCH 2/2] Fixed github-webhook logging The event action was not being logged properly. `event.body` is a string and therefore `event.body.action` is always undefined. --- aws-node-github-webhook-listener/handler.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aws-node-github-webhook-listener/handler.js b/aws-node-github-webhook-listener/handler.js index a4d47b0a0..1f3a760d0 100644 --- a/aws-node-github-webhook-listener/handler.js +++ b/aws-node-github-webhook-listener/handler.js @@ -12,6 +12,7 @@ module.exports.githubWebhookListener = (event, context, callback) => { const githubEvent = headers['X-GitHub-Event']; const id = headers['X-GitHub-Delivery']; const calculatedSig = signRequestBody(token, event.body); + const eventObj = JSON.parse(event.body); if (typeof token !== 'string') { errMsg = '[401] must provide a \'GITHUB_WEBHOOK_SECRET\' env variable'; @@ -40,7 +41,7 @@ module.exports.githubWebhookListener = (event, context, callback) => { /* eslint-disable */ console.log('---------------------------------'); - console.log(`Github-Event: "${githubEvent}" with action: "${event.body.action}"`); + console.log(`Github-Event: "${githubEvent}" with action: "${eventObj.action}"`); console.log('---------------------------------'); console.log('Payload', event.body); /* eslint-enable */