rvagg / rvagg/github-webhook-handler
X-Hub-Signature does not match blob signature
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 793
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
using my own function works but it crash with github-webhook-handler:
const createComparisonSignature = (body) => {
const hmac = crypto.createHmac('sha1', process.env.GITHUB_SECRET);
const self_signature = hmac.update(JSON.stringify(body)).digest('hex');
return `sha1=${self_signature}`; // shape in GitHub header
}
const compareSignatures = (signature, comparison_signature) => {
const source = Buffer.from(signature);
const comparison = Buffer.from(comparison_signature);
return crypto.timingSafeEqual(source, comparison); // constant time comparison
}
const { headers, body } = req;
const signature = headers['x-hub-signature'];
const comparison_signature = createComparisonSignature(req.body);
if (!compareSignatures(signature, comparison_signature)) {
return res.status(401).send('Mismatched signatures');
} else {
console.log("signature match")
const { action, ...payload } = body;
req.event_type = headers['x-github-event']; // one of: https://developer.github.com/v3/activity/events/types/
req.action = action;
req.payload = payload;
next();
}
return next()
please let me know if there is any solution
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named in the issue. Start by tracing how github-webhook-handler receives and parses req.body, then compare the bytes used for signature verification with the original request body. Done means a valid X-Hub-Signature verifies consistently without the reported mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100