MCPcopy Create free account
hub / github.com/Devographics/Monorepo / verifyGhWebhookMiddleware

Function verifyGhWebhookMiddleware

api/src/external_apis/github.ts:90–103  ·  view source on GitHub ↗
(req: Request, res: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

88 * @see https://docs.github.com/en/webhooks/using-webhooks/securing-your-webhooks
89 */
90export 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
105export async function checkMainPushAction(req: Request, res: Response, next: NextFunction) {
106 // @see https://docs.github.com/en/webhooks/webhook-events-and-payloads#push

Callers

nothing calls this directly

Calls 3

getEnvVarFunction · 0.90
verifyGhWebhookSignatureFunction · 0.85
nextFunction · 0.85

Tested by

no test coverage detected