Skip to content

Commit 0552fb5

Browse files
committed
fix(gogs): fix formatting JSON payload before calculating signature (closes #336)
1 parent dbd4590 commit 0552fb5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/api/webhooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ webhooks.post('/gogs', (req: express.Request, res: express.Response) => {
401401
break;
402402
case 'release':
403403
res.status(200).json({ msg: 'ok' });
404+
break;
404405
case 'pull_request':
405406
switch (payload.action) {
406407
case 'opened':
@@ -473,6 +474,6 @@ function verifyGithubWebhook(signature: string, payload: any, secret: string): b
473474
}
474475

475476
function verifyGogsWebhook(signature: string, payload: any, secret: string): boolean {
476-
let sig = `${crypto.createHmac('sha256', secret).update(JSON.stringify(payload)).digest('hex')}`;
477+
let sig = `${crypto.createHmac('sha256', secret).update(JSON.stringify(payload, null, 2)).digest('hex')}`;
477478
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(sig));
478479
}

0 commit comments

Comments
 (0)