Skip to content

Commit

Permalink
fix(api/gogs): 2 fix in gogs webhook handling
Browse files Browse the repository at this point in the history
- no sha256= prefix send by gogs
- wrong header name for signature extraction
  • Loading branch information
mimix committed Aug 16, 2023
1 parent b17c00c commit fed6663
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/git/gogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ export class GogsApi extends Repo {

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

let verified = false;
if (hash === signature) {
debug.debug('Gitea webhook signature is valid for event: '+delivery);
debug.debug('Gogs webhook signature is valid for event: '+delivery);
verified = true;
} else {
debug.log('ERROR: invalid signature for event: '+delivery);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Router.all('/repo/webhooks/:repoprovider', async function (req: Request, res: Re
//console.log(req.headers)
let gogs_event = req.headers['x-gogs-event']
let gogs_delivery = req.headers['x-gogs-delivery']
let gogs_signature = req.headers['x-hub-signature-256']
let gogs_signature = req.headers['x-gogs-signature']
let gogs_body = req.body

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

0 comments on commit fed6663

Please sign in to comment.