【发布时间】:2018-09-28 21:57:44
【问题描述】:
我有一个 webhook,可以将 Push 事件负载传递到 Google Cloud Function。我的 nodejs 代码如下所示:
function validateRequest (req) {
return Promise.resolve()
.then(() => {
const digest = crypto
.createHmac('sha1', '12345')
.update(JSON.stringify(req.body))
.digest('hex');
if (req.headers['x-hub-signature'] !== `sha1=${digest}`) {
const error = new Error('Unauthorized');
error.statusCode = 403;
throw error;
} else {
console.log('Request validated.');
}
});
}
我已经两次和三次检查了秘密令牌( 12345') 与 webhook 中的密钥匹配。然而,这段代码计算的 sha 并不等于 GitHub 发送的 sha。此代码逐字取自https://cloud.google.com/community/tutorials/github-auto-assign-reviewers-cloud-functions。 GitHub 使用的哈希方法有变化吗?
【问题讨论】: