Webhook signature verification (timing-safe compare)

9519
0

For webhooks, I assume the internet is hostile by default. I don’t trust that a request ‘looks like’ it came from Stripe/GitHub/etc; I verify the signature over the raw request body and use crypto.timingSafeEqual to avoid leaking information via timing. When signature checks fail, I log just enough metadata to debug (provider, event id, timestamp skew), but never the secret and never the full raw payload. If the provider includes a timestamp header, I enforce a tolerance window to reduce replay risk. This keeps the endpoint safe even when it’s publicly exposed, and it makes failures explainable without turning logs into a liability.