(req: Request, res: Response, next: NextFunction)
| 88 | * @see https://docs.github.com/en/webhooks/using-webhooks/securing-your-webhooks |
| 89 | */ |
| 90 | export const verifyGhWebhookMiddleware = (req: Request, res: Response, next: NextFunction) => { |
| 91 | const secretKey = getEnvVar(EnvVar.SECRET_KEY, { |
| 92 | hardFail: true, |
| 93 | calledFrom: 'verifyGhWebhookMiddleware' |
| 94 | }) |
| 95 | const signature = req.headers?.['x-hub-signature-256'] |
| 96 | if (!signature) return res.status(400).send('Missing GitHub signature') |
| 97 | if (Array.isArray(signature)) |
| 98 | return res.status(400).send('GitHub signature must be a single value') |
| 99 | if (!verifyGhWebhookSignature(secretKey, req.body, signature)) { |
| 100 | return res.status(401).send('Wrong signature, GitHub hook secret might be misconfigured') |
| 101 | } |
| 102 | next() |
| 103 | } |
| 104 | |
| 105 | export async function checkMainPushAction(req: Request, res: Response, next: NextFunction) { |
| 106 | // @see https://docs.github.com/en/webhooks/webhook-events-and-payloads#push |
nothing calls this directly
no test coverage detected