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) => {
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 ( / ^ s h a 1 = ( .* ) / ) ;
27- if ( ! sha1 ) {
26+ const sha256 = signature . match ( / ^ s h a 2 5 6 = ( .* ) / ) ;
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}
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments