Skip to main content

apps/gateway/src/routes/integrations.ts

Metadata

Indexed Symbols

  • validateSignature (line 9, function) - Implements validate signature for HTTP request handling.

Markdown Headings (if applicable)

No markdown headings detected.

Source Preview

import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
import type { FastifyPluginAsync } from "fastify";
import { env } from "../config/env.js";
import { enqueueOutboxEvent } from "../services/event-pipeline.js";
import { getEffectivePlatformSettings, resolveSecretValue } from "../services/runtime-config.js";
import { recordWebhookReceipt } from "../services/webhook-repository.js";
import { ensureUuid, isUuid } from "../utils/uuid.js";

function validateSignature(rawBody: string, signatureHeader: string | undefined, secret: string | undefined): boolean {
if (!secret) {
return false;
}
if (!signatureHeader?.startsWith("sha256=")) {
return false;
}

const expected = Buffer.from(
`sha256=${createHmac("sha256", secret).update(rawBody).digest("hex")}`,
"utf8"
);
const received = Buffer.from(signatureHeader, "utf8");

if (expected.length !== received.length) {
return false;
}