Skip to content

Commit 568a2c7

Browse files
committed
Do validate the SHA-256 signature
Not that SHA-1 is _practically_ broken yet... but still... Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 5af2ba6 commit 568a2c7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

GitGitGadget/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ const validateGitHubWebHook = (context) => {
1919
if (context.req.headers['content-type'] !== 'application/json') {
2020
throw new Error('Unexpected content type: ' + context.req.headers['content-type']);
2121
}
22-
const signature = context.req.headers['x-hub-signature'];
22+
const signature = context.req.headers['x-hub-signature-256'];
2323
if (!signature) {
2424
throw new Error('Missing X-Hub-Signature');
2525
}
26-
const sha1 = signature.match(/^sha1=(.*)/);
27-
if (!sha1) {
26+
const sha256 = signature.match(/^sha256=(.*)/);
27+
if (!sha256) {
2828
throw new Error('Unexpected X-Hub-Signature format: ' + signature);
2929
}
30-
const computed = crypto.createHmac('sha1', secret).update(context.req.rawBody).digest('hex');
31-
if (sha1[1] !== computed) {
30+
const computed = crypto.createHmac('sha256', secret).update(context.req.rawBody).digest('hex');
31+
if (sha256[1] !== computed) {
3232
throw new Error('Incorrect X-Hub-Signature');
3333
}
3434
}

__tests__/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ test('reject requests other than webhook payloads', async () => {
3838
context.req.headers['content-type'] = 'application/json'
3939
await expectInvalidWebhook('Missing X-Hub-Signature')
4040

41-
context.req.headers['x-hub-signature'] = 'invalid'
41+
context.req.headers['x-hub-signature-256'] = 'invalid'
4242
await expectInvalidWebhook('Unexpected X-Hub-Signature format: invalid')
4343

44-
context.req.headers['x-hub-signature'] = 'sha1=incorrect'
44+
context.req.headers['x-hub-signature-256'] = 'sha256=incorrect'
4545
context.req.rawBody = '# empty'
4646
await expectInvalidWebhook('Incorrect X-Hub-Signature')
4747
})

0 commit comments

Comments
 (0)