serverless / serverless/examples

Error using the GitHub Webhook example

Open
#172 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.5k
Forks
4.4k
Avg merge
2h 55m
Merged PRs (30d)
3

Description

Situation

I am setting up the aws-node-github-webhook-listener example for a project at Netlify and running into the error where the generated sha1 create from my secret GitHub token set in my webhook settings never matched the one in header['X-Hub-Signature'].

screenshot 2017-06-23 17 27 22

Complication

There is a function that creates sha1 based on the github event body and secret key.

function signRequestBody(key, body) {
  // key is my secret
  return `sha1=${crypto.createHmac('sha1', key).update(body, 'utf-8').digest('hex')}`;
}

Question

TBH, I don't have ever encountered a problem where I needed to compared encrypted data. Is there that someone has a working example of this in the wild? Is there is something I am overlooking?

My function works fine of course if I remove this secret checking, but my guess is @DavidWells has this working as is 😄. Just need some gentle nudging in the correct direction.

Error Message

Error Message from my logs:

{"errorMessage":"[401] X-Hub-Signature incorrect. Github webhook token doesn't match","errorType":"Error","stackTrace":["module.exports.githubWebhookListener (/var/task/handler.js:52:21)"]}
// serverless.yml

service: netlify-cms-www-webhook

provider:
  name: aws
  runtime: nodejs6.10
  environment:
    GITHUB_WEBHOOK_SECRET: unencrytedSecret
    NETLIFY_WEBHOOK_BUILD: https://api.netlify.com/build_hooks/12345

Live Code is at https://github.com/netlify/netlify-cms-docs-webhook

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The relevant entry point is aws-node-github-webhook-listener/handler.js, especially the linked signature check around lines 36–39; also inspect the serverless.yml secret configuration. Reproduce the webhook request and compare the generated signature with X-Hub-Signature, then verify that valid requests are accepted and invalid ones are rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, javascript, node.js
Domain
api, backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.