DEV Community

Payneteasy
Payneteasy

Posted on

Webhook signature failures for 11 minutes, twice a day: it was the clock

A merchant's webhooks failed signature checks for about 11 minutes, twice a day. The HMAC secret hadn't changed.

The handler rejected any event whose timestamp differed from now by more than 5 minutes, a standard replay guard. The cause was the host clock. The VM paused during live migration and resumed roughly 6 minutes behind until chrony stepped it back. Every webhook in that window looked like it came from the future and got a 400.

Some retries landed after the clock was corrected and passed. Others used up their retry budget, and those orders stayed pending until the nightly reconciliation caught them.

What we changed:

  • Log the computed skew on every rejection. The old line said only "invalid signature", so the pattern took a day to spot.
  • Widen tolerance to 10 minutes. Replay is already covered by deduplicating on event ID.
  • Alert when skew on accepted webhooks passes 60 seconds. It fires before rejections start.
  • Return 503, not 400, for timestamp failures. It's our fault, and some senders stop retrying on 4xx.

Do you reject on timestamp at all, or rely only on event ID dedup? Where do you set the tolerance?

Payneteasy handles this kind of payment flow for merchants and PSPs — see how it works.

Top comments (2)

Collapse
 
keyharbor profile image
Arthur | Keyharbor •

Good writeup, and returning 503 instead of 400 is the change most people miss.

To your question: I'd keep the timestamp check, but as a second line. Event ID dedup stops replays of events you've already seen, while the timestamp window is what stops an old captured payload from being replayed after your dedup records have been pruned. So the tolerance only needs to stay well under your dedup retention, and 10 minutes against days of retention is fine.

For the migration case specifically, it's worth checking whether the guest can sync from the hypervisor clock (ptp_kvm as a chrony refclock on KVM, for example), so it corrects right after a resume instead of waiting on NTP.

Collapse
 
hamichidev profile image
Hamichi •

Returning 503 instead of 400 for timestamp failures is the change I'd copy first, since a sender that stops retrying on 4xx turns a short clock problem into stuck orders. If event ID dedup already covers replay, the timestamp check mostly guards the window before the ID is stored, so 10 minutes looks like a fair trade. Logging the skew on accepted webhooks too, not just rejections, gives you a trend line that shows a drifting host days before it crosses the limit. Did the nightly reconciliation catch every stuck order, or did some need a manual push?