Security

Verifying Payment Webhooks Properly: A Lesson from Our Own Code

By Admin • November 7, 2026 • 2 min read • 694 views
Verifying Payment Webhooks Properly: A Lesson from Our Own Code
A payment callback endpoint with no authentication is an open door, even when the data it carries looks legitimate. Here is the pattern we now apply to every webhook across our systems.

Payment gateways - M-Pesa included - deliver confirmation of a successful payment to a webhook URL you configure. It is easy to treat that endpoint as implicitly trusted, because in normal operation only the payment provider ever calls it. That assumption doesn't hold once the URL is public, which it always is, because the gateway needs to be able to reach it.

What an unauthenticated webhook actually allows

If a payment confirmation endpoint accepts any request that looks like a valid payload, anyone who discovers the URL can submit a forged "payment successful" confirmation for a transaction that never happened. In a point-of-sale or invoicing system, that can mean stock released, an order marked paid, or a balance cleared - for free.

The fix we standardized on

Every payment webhook across our systems now requires a per-deployment token embedded in the callback URL itself, checked with a constant-time comparison before anything else happens in the handler. The token is never derived from request data, so it can't be guessed from a legitimate payload, and it is independent of whatever signature or validation the payment provider itself offers - a second, application-level lock on a door that shouldn't be left open just because the gateway also checks its own signature.

Why this is now a standing checklist item

We found and fixed exactly this gap in one of our own production systems during a routine audit, which is precisely why it is now a standard check on every payment integration we build or review, not just the one where it was found. Regression tests now cover the unauthenticated-request case explicitly, so a future change to the handler can't silently reopen it.

The broader principle

Any endpoint that changes money, stock, or account state based on an inbound request from a third party needs its own authentication, independent of how trustworthy the caller is assumed to be. "Nobody else knows this URL" is not a security control.

Share this article:
Last updated: Nov 23, 2026