我有一个 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 使用的散列方法是否发生了变化?