Trying to mock a github webhook request, get: "X-Hub-Signature does not match blob signature"

Here is a small proxy server setting for working with github webhooks:

require('dotenv').config();
var http = require('http');
var createHandler = require('github-webhook-handler');
var handler = createHandler({
  path: '/webhook',
  secret: process.env.GIT_WEBHOOK_SECRET
});

http
  .createServer(function(req, res) {
    handler(req, res, function(err) {
      res.statusCode = 404;
      res.end('no such location');
    });
  })
  .listen(8080);

handler.on('error', function(err) {
  console.error('Error:', err.message);
});

handler.on('push', function(event) {
  console.log(
    'Received a push event for %s to %s',
    event.payload.repository.name,
    event.payload.ref
  );
});

handler.on('issues', function(event) {
  console.log(
    'Received an issue event for %s action=%s: #%d %s',
    event.payload.repository.name,
    event.payload.action,
    event.payload.issue.number,
    event.payload.issue.title
  );
});

In the postman, I have these headers:

Headings

Raw body here: https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent

Here is my preliminary script request:

var payload = request.data;
console.log("Using payload as " + payload)
var hash = CryptoJS.HmacSHA1(payload, environment.secret).toString(CryptoJS.enc.Hex)
postman.setGlobalVariable("signature", hash);

I can confirm that GIT_WEBHOOK_SECRET.env matches what is set in secretPostman's environment settings.

+4
source share
1 answer

You need to set the content X-Hub-Signatureas parameters with a field sha1:

var payload = request.data;
console.log("Using payload as " + payload)
var hash = CryptoJS.HmacSHA1(payload, environment.secret).toString(CryptoJS.enc.Hex)
postman.setGlobalVariable("signature", "sha1=" + hash);

Github:

, , - sha1 =, .

+1

Source: https://habr.com/ru/post/1680516/


All Articles