File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -19,16 +19,16 @@ const validateGitHubWebHook = (context) => {
19
19
if ( context . req . headers [ 'content-type' ] !== 'application/json' ) {
20
20
throw new Error ( 'Unexpected content type: ' + context . req . headers [ 'content-type' ] ) ;
21
21
}
22
- const signature = context . req . headers [ 'x-hub-signature' ] ;
22
+ const signature = context . req . headers [ 'x-hub-signature-256 ' ] ;
23
23
if ( ! signature ) {
24
24
throw new Error ( 'Missing X-Hub-Signature' ) ;
25
25
}
26
- const sha1 = signature . match ( / ^ s h a 1 = ( .* ) / ) ;
27
- if ( ! sha1 ) {
26
+ const sha256 = signature . match ( / ^ s h a 2 5 6 = ( .* ) / ) ;
27
+ if ( ! sha256 ) {
28
28
throw new Error ( 'Unexpected X-Hub-Signature format: ' + signature ) ;
29
29
}
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 ) {
32
32
throw new Error ( 'Incorrect X-Hub-Signature' ) ;
33
33
}
34
34
}
Original file line number Diff line number Diff line change @@ -38,10 +38,10 @@ test('reject requests other than webhook payloads', async () => {
38
38
context . req . headers [ 'content-type' ] = 'application/json'
39
39
await expectInvalidWebhook ( 'Missing X-Hub-Signature' )
40
40
41
- context . req . headers [ 'x-hub-signature' ] = 'invalid'
41
+ context . req . headers [ 'x-hub-signature-256 ' ] = 'invalid'
42
42
await expectInvalidWebhook ( 'Unexpected X-Hub-Signature format: invalid' )
43
43
44
- context . req . headers [ 'x-hub-signature' ] = 'sha1 =incorrect'
44
+ context . req . headers [ 'x-hub-signature-256 ' ] = 'sha256 =incorrect'
45
45
context . req . rawBody = '# empty'
46
46
await expectInvalidWebhook ( 'Incorrect X-Hub-Signature' )
47
47
} )
You can’t perform that action at this time.
0 commit comments