packages/docs/docs/lambda/validatewebhooksignature.mdx
Validates that the signature that was received by a webhook endpoint is authentic. If the validation fails, an error is thrown.
The function accepts an object with three key-value pairs:
secretThe same webhook secret that was passed to renderMediaOnLambda()'s webhook options.
bodyThe body that was received by the endpoint - takes a parsed JSON object, not a string.
signatureHeaderThe X-Remotion-Signature header from the request that was received by the endpoint.
In the following Next.JS webhook endpoint, an error gets thrown if the signature does not match the one expected one or is missing..
type NextApiRequest = {
body: object;
headers: Record<string, string>;
};
type NextApiResponse = {
status: (code: number) => {json: (body: object) => void};
};
// ---cut---
import {validateWebhookSignature, WebhookPayload} from '@remotion/lambda/client';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
validateWebhookSignature({
secret: process.env.WEBHOOK_SECRET as string,
body: req.body,
signatureHeader: req.headers['x-remotion-signature'] as string,
});
// If code reaches this path, the webhook is authentic.
const payload = req.body as WebhookPayload;
if (payload.type === 'success') {
// ...
} else if (payload.type === 'timeout') {
// ...
}
res.status(200).json({
success: true,
});
}
See Webhooks for an Express example.