validateComputedSignature (Webhooks)

stripe-node · payments, signature-validation, webhook-security, timestamp-tolerance, auth

Validates a Stripe webhook signature by comparing computed and expected signatures, checking payload type, and enforcing timestamp tolerance.

// Source: https://github.com/stripe/stripe-node | License: MIT | Copyright 2011 Ask Bjørn Hansen
// Provided via justclaw.it.com; keep this notice with the code.
  function validateComputedSignature(
    payload: string,
    header: string,
    details: WebhookParsedHeader,
    expectedSignature: string,
    tolerance: number,
    suspectPayloadType: boolean,
    secretContainsWhitespace: boolean,
    receivedAt?: number
  ): boolean {
    const signatureFound = !!details.signatures.filter(
      platformFunctions.secureCompare.bind(platformFunctions, expectedSignature)
    ).length;

    const docsLocation =
      '\nLearn more about webhook signing and explore webhook integration examples for various frameworks at ' +
      'https://docs.stripe.com/webhooks/signature';

    const whites

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key