Mantissa Hooksnode is a Mantissa product A Mantissa product mantissatech.xyz

How to verify a Flutterwave webhook signature (v3 verif-hash and v4 flutterwave-signature)

Author:
hooksnode
Published:
Updated:
  • flutterwave
  • webhooks
  • security

Flutterwave signs webhooks in two ways, depending on the API version. Check the header that arrived, on the raw body, and reject the request when it does not match.

Quick answer

v3 sends your secret hash as is in verif-hash. Compare it in constant time. v4 sends the base64 HMAC-SHA256 of the raw body, keyed with the secret hash, in flutterwave-signature. Compute that HMAC on the raw bytes and compare it in constant time.

This guide covers:

  1. The quick answer for v3 and v4.
  2. Which header you have, and which secret it uses.
  3. Why the two checks on the v4 docs page do not do the same thing.
  4. v4 samples in Node, Next.js, PHP and Python.
  5. The v3 verif-hash compare.
  6. Why a real event still fails.
  7. What a signature does not prove.
  8. Letting Hooksnode check the signature once.
  9. Short answers to the questions that come up next.

Which version am I on?

Log the headers once on a test event and see which name arrives.

What arrived Version What to do
flutterwave-signature v4 HMAC-SHA256 of the raw body, base64, keyed with the secret hash
verif-hash only v3 Compare the header to the secret hash, in constant time

Both versions use the secret hash you set in the Flutterwave dashboard (Settings, Webhooks). The test dashboard and the live dashboard each have their own hash. The hash your server reads has to come from the same mode as the event.

The secret hash is not your secret key and not your public key. It is the value you typed into the secret hash field.

Header names are case-insensitive. Flutterwave-Signature and VERIF-HASH are the same headers.

Two checks on the v4 docs page

Flutterwave's v4 webhooks page describes the signature in the Verifying Webhook Signatures section, then shows a different check in Examples.

The Verifying Webhook Signatures section says:

When a webhook is triggered, Flutterwave uses the secret hash you specify on your dashboard to hash the webhook response using HMAC-SHA256. The encrypted value is then returned as flutterwave-signature in the header of the webhook.

The sample in that section hashes the raw body and base64-encodes the HMAC:

const hash = crypto.createHmac('sha256', secretHash).update(rawBody).digest('base64');
return hash === signature;

That HMAC is what a v4 flutterwave-signature header carries: base64 HMAC-SHA256 of the raw body, keyed with the secret hash.

The Examples section on the same page compares flutterwave-signature to the secret hash itself. The Express example does this:

const signature = req.headers["flutterwave-signature"];
if (!signature || (signature !== secretHash)) {
    res.status(401).end();
}

The Laravel example compares $signature !== $secretHash. The Django example compares signature != secret_hash. A plain string compare of flutterwave-signature against the secret hash does not match a real v4 event. The header is the HMAC, not the secret. That plain compare is the v3 verif-hash check, written against the v4 header name.

Copy the HMAC from the Verifying Webhook Signatures section. Do not copy the plain compare from Examples.

The sample above compares with ===. A plain === can return as soon as one character differs, which leaks timing. The samples below check the length first, then use a constant-time compare. In Node, crypto.timingSafeEqual throws if the two buffers differ in length, so the length check has to come first.

Check flutterwave-signature (v4)

Read the body as raw bytes, compute base64 HMAC-SHA256 with the secret hash, compare in constant time, and only then parse the JSON. On no match, answer 401.

Node.js (Express)

express.raw on the webhook route keeps req.body as a Buffer:

import crypto from "node:crypto";
import express from "express";

const app = express();
const secret = process.env.FLW_SECRET_HASH.trim();

function verifyFlutterwaveV4(raw, header) {
  const expected = crypto.createHmac("sha256", secret).update(raw).digest("base64");
  const givenBuf = Buffer.from(header || "");
  const expectedBuf = Buffer.from(expected);
  if (givenBuf.length !== expectedBuf.length) return false;
  return crypto.timingSafeEqual(givenBuf, expectedBuf);
}

app.post("/webhooks/flutterwave", express.raw({ type: "application/json" }), (req, res) => {
  const ok = verifyFlutterwaveV4(req.body, req.get("flutterwave-signature"));
  if (!ok) return res.sendStatus(401);

  const event = JSON.parse(req.body.toString("utf8"));
  res.sendStatus(200);
});

If app.use(express.json()) runs before this route, the raw bytes are already gone. Register the webhook route first, or skip the JSON parser for that path.

You can keep express.json() if a verify hook stores the Buffer before parsing:

app.use(express.json({
  verify(req, res, buf) {
    req.rawBody = buf;
  }
}));

app.post("/webhooks/flutterwave", (req, res) => {
  const ok = verifyFlutterwaveV4(req.rawBody, req.get("flutterwave-signature"));
  if (!ok) return res.sendStatus(401);
  res.sendStatus(200);
});

Use one of these, not both, on the same route. HMAC the Buffer, not JSON.stringify(req.body).

Next.js (App Router route handler)

Read the text once with await req.text(), verify it, then parse it:

import crypto from "node:crypto";

function verifyFlutterwaveV4(raw: string, header: string, secret: string): boolean {
  const expected = crypto.createHmac("sha256", secret).update(raw, "utf8").digest("base64");
  const givenBuf = Buffer.from(header || "");
  const expectedBuf = Buffer.from(expected);
  if (givenBuf.length !== expectedBuf.length) return false;
  return crypto.timingSafeEqual(givenBuf, expectedBuf);
}

export async function POST(req: Request) {
  const raw = await req.text();
  const header = req.headers.get("flutterwave-signature") ?? "";
  const ok = verifyFlutterwaveV4(raw, header, process.env.FLW_SECRET_HASH!.trim());
  if (!ok) return new Response(null, { status: 401 });

  const event = JSON.parse(raw);
  return new Response(null, { status: 200 });
}

Do not call req.json() before req.text(). The body can only be read once.

PHP

Read php://input, not $_POST and not a decoded array. hash_hmac with true returns the raw digest. Base64-encode that, then hash_equals:

<?php
$raw = file_get_contents("php://input");
$secret = trim(getenv("FLW_SECRET_HASH"));
$expected = base64_encode(hash_hmac("sha256", $raw, $secret, true));
$given = $_SERVER["HTTP_FLUTTERWAVE_SIGNATURE"] ?? "";

if (strlen($given) !== strlen($expected) || !hash_equals($expected, $given)) {
    http_response_code(401);
    exit;
}

$event = json_decode($raw, true);
http_response_code(200);

In Laravel, use $request->getContent() for the raw body.

Python (Flask)

import base64, hashlib, hmac, os
from flask import Flask, abort, request

app = Flask(__name__)
SECRET = os.environ["FLW_SECRET_HASH"].strip().encode()

def verify_flutterwave_v4(raw, header):
    digest = hmac.new(SECRET, raw, hashlib.sha256).digest()
    expected = base64.b64encode(digest)
    given = (header or "").encode()
    return len(given) == len(expected) and hmac.compare_digest(given, expected)

@app.post("/webhooks/flutterwave")
def flutterwave():
    raw = request.get_data()
    header = request.headers.get("flutterwave-signature", "")
    if not verify_flutterwave_v4(raw, header):
        abort(401)
    event = request.get_json()
    return "", 200

In Django, use request.body.

Compare the base64 text, not a hex digest. Hex will not match flutterwave-signature.

Check verif-hash (v3)

On v3, documented on Flutterwave's webhook docs, the secret hash is sent as is in verif-hash. There is no digest to compute. Compare the header to the secret hash in constant time.

These samples are the same checks as in Why your Flutterwave webhook is not arriving.

// Node.js, v3 verif-hash
import crypto from 'node:crypto';

function verifyFlutterwave(req) {
  const expected = Buffer.from(process.env.FLW_SECRET_HASH.trim());
  const got = Buffer.from(String(req.headers['verif-hash'] || ''));
  return got.length === expected.length && crypto.timingSafeEqual(got, expected);
}
<?php
// PHP, v3 verif-hash
$expected = trim(getenv('FLW_SECRET_HASH'));
$got = $_SERVER['HTTP_VERIF_HASH'] ?? '';
if (!hash_equals($expected, $got)) {
    http_response_code(401);
    exit;
}
# Python, v3 verif-hash
import hmac, os

def verify_flutterwave(headers):
    expected = os.environ["FLW_SECRET_HASH"].strip()
    got = headers.get("verif-hash", "")
    return hmac.compare_digest(got, expected)

If flutterwave-signature is present and does not match, answer 401. Do not accept the request because verif-hash matches.

Why a real event still fails

The HMAC section is the right check, and it still fails when the bytes you hash are not the bytes Flutterwave sent.

  • Re-serialized JSON. JSON.stringify, json.dumps and json_encode build a new string. Key order, spacing, escaped slashes and number formatting can all differ.
  • A body parser ran first. express.json(), req.json(), $_POST and a decoded array have already thrown away the raw bytes.
  • Trailing whitespace in the env var. A newline copied into .env changes the key. Trim the secret hash.
  • The wrong env var. The secret key and the public key are not the secret hash.
  • Test vs live. Each dashboard has its own hash.
  • Hex instead of base64. flutterwave-signature is standard base64, not hex.
  • A proxy or framework rewrote the body. A middleware that re-encodes JSON, or a proxy that changes the payload, breaks the HMAC. Hash the bytes that arrived on the wire.

What the signature does not do

A matching signature means the body and the secret hash go together. It does not mean the event is new.

Neither verif-hash nor flutterwave-signature carries a timestamp, so the check has no clock window and does not stop replays. Someone who has seen a request can send the same bytes again.

Before you give value, re-verify the transaction with the Flutterwave API and check the status, amount, currency and reference. Dedupe on data.tx_ref so a second delivery does not credit the customer twice. The handler is in Why your payment webhook arrived twice. The redirect and the webhook both have to call that check. The pattern is in Flutterwave redirect_url vs webhook: which one should give value?.

Answer 200 for a duplicate. An error makes the sender try again.

Verify once at the edge with Hooksnode

If several services need the same Flutterwave events, each one otherwise needs the secret hash and its own copy of the check. Hooksnode can do the Flutterwave check once, at the source.

  1. Open the source and turn on Require signature verification.
  2. Under Signature format, choose Flutterwave.
  3. Paste the secret hash into the field labeled Flutterwave secret, then press Save format. The same secret covers v3 and v4.

When flutterwave-signature is present, Hooksnode computes the base64 HMAC-SHA256 of the exact raw body, keyed with the secret hash, and compares in constant time. A mismatch is rejected with 401 and is not delivered, even if verif-hash would have matched. A matching flutterwave-signature is accepted even when verif-hash is wrong. A blank or whitespace-only flutterwave-signature is treated as absent, and the verif-hash check runs.

When flutterwave-signature is absent, Hooksnode compares verif-hash with the secret hash. A missing or wrong value, or both headers missing, is rejected with 401 and is not delivered.

Hooksnode forwards the raw body and the original headers unchanged. It does not re-sign flutterwave-signature or verif-hash on a retry or replay. Neither header carries a timestamp, so a later retry does not fail the Flutterwave check on time. A destination with a transform should verify X-Hooksnode-Signature instead. On the destination, the section is labeled Signing. Turn on Sign outbound requests, then copy Signing secret. With that on, Hooksnode adds X-Hooksnode-Signature: sha256=<hex>, the HMAC SHA256 of the final body, keyed with that destination's secret. See destination signing.

Delivery is at least once, never exactly once. Hooksnode makes up to 25 delivery attempts in total. Keep the data.tx_ref check in each service.

One URL, filters and per-destination retries are in Send one Flutterwave webhook to several services. If the event never shows up at all, see Why your Flutterwave webhook is not arriving.

FAQ

Is flutterwave-signature an HMAC?

Yes. On v4, flutterwave-signature is the base64 HMAC-SHA256 of the raw request body, keyed with your secret hash. Compute it on the raw bytes and compare in constant time. v3 does not send that header. v3 sends the secret hash itself in verif-hash.

Do v3 and v4 use different secrets?

No. Both use the secret hash you set in the Flutterwave dashboard. The test dashboard and the live dashboard each have their own hash. In Hooksnode, the same pasted secret covers v3 and v4.

Why does my check fail when I JSON.stringify the body?

JSON.stringify builds a new string. Key order, spacing and escaping can differ from the bytes Flutterwave signed. Compute the HMAC over the raw body, before any JSON parsing.

Does Hooksnode re-sign Flutterwave headers on retry?

No. Hooksnode forwards the raw body and the original headers unchanged. It does not re-sign flutterwave-signature or verif-hash on a retry or replay. Neither header carries a timestamp, so a later retry does not fail the Flutterwave check on time. A destination with a transform should verify X-Hooksnode-Signature instead. That value is the HMAC SHA256 of the final body, keyed with the per-destination secret.

Checklist

  • Log headers once. v4 uses flutterwave-signature. v3 uses verif-hash only
  • v4: base64 HMAC-SHA256 of the raw body, length check, then a constant-time compare
  • v3: constant-time compare of verif-hash to the secret hash
  • Secret hash from the same dashboard mode as the event, not the secret key
  • Do not compare flutterwave-signature to the secret hash
  • Hash the raw body, before any JSON parsing
  • Answer 401 when nothing matches
  • Re-verify the transaction with the Flutterwave API before giving value
  • Dedupe on data.tx_ref

Further reading