Skip to content

Commit 415de92

Browse files
author
mimix
committed
fix(api/gogs): 2 fixes in gogs webhook handling
- no sha256= prefix sent by gogs - wrong header name for signature extraction
1 parent b17c00c commit 415de92

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/git/gogs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ export class GogsApi extends Repo {
190190

191191
public getWebhook(event: string, delivery: string, signature: string, body: any): IWebhook | boolean {
192192
let secret = process.env.KUBERO_WEBHOOK_SECRET as string;
193-
let hash = 'sha256='+crypto.createHmac('sha256', secret).update(JSON.stringify(body, null, ' ')).digest('hex')
193+
let hash = crypto.createHmac('sha256', secret).update(JSON.stringify(body, null, ' ')).digest('hex')
194194

195195
let verified = false;
196196
if (hash === signature) {
197-
debug.debug('Gitea webhook signature is valid for event: '+delivery);
197+
debug.debug('Gogs webhook signature is valid for event: '+delivery);
198198
verified = true;
199199
} else {
200200
debug.log('ERROR: invalid signature for event: '+delivery);

src/routes/repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Router.all('/repo/webhooks/:repoprovider', async function (req: Request, res: Re
6161
//console.log(req.headers)
6262
let gogs_event = req.headers['x-gogs-event']
6363
let gogs_delivery = req.headers['x-gogs-delivery']
64-
let gogs_signature = req.headers['x-hub-signature-256']
64+
let gogs_signature = req.headers['x-gogs-signature']
6565
let gogs_body = req.body
6666

6767
req.app.locals.kubero.handleWebhook('gogs', gogs_event, gogs_delivery, gogs_signature, gogs_body);

0 commit comments

Comments
 (0)