Authentication and API security

Verify webhook signatures and prevent replay

Validate webhook signatures over the exact request bytes and define replay protection and delivery retry behavior. Parsing or normalizing a webhook body before signature verification can change the signed bytes. A valid signature also does not by itself prevent replay of an old delivery. Security controls depend on client type, data sensitivity and deployment context; verify provider and standards guidance before production changes.

Threat model and trust boundaries

Parsing or normalizing a webhook body before signature verification can change the signed bytes. A valid signature also does not by itself prevent replay of an old delivery.

  • Identify actors, assets and trust boundaries
  • Choose controls that address the stated threat
  • Test failure behavior and recovery paths

Implementation approach

Verify signatures using the provider's documented canonicalization, compare MACs in constant time, enforce a bounded timestamp window where supported, and deduplicate delivery IDs in durable storage.

  • Confirm the responsible owner
  • Apply the change to a representative case
  • Document decisions and exceptions

Practical example

The receiver reads the raw request body, checks the signed timestamp and HMAC before JSON parsing, then records the provider event ID so a retry is acknowledged without repeating the side effect.

  • Reproduce the starting situation
  • Apply the described approach
  • Check the user-facing result

Verification and follow-up

Test altered body bytes, invalid signatures, stale timestamps, duplicated event IDs and key rotation; monitor rejected deliveries without logging secrets.

  • Test expected and failure cases
  • Compare with the recorded baseline
  • Agree the next review date and owner

Questions to keep in view

When should a team use this authentication and api security guide?

Validate webhook signatures over the exact request bytes and define replay protection and delivery retry behavior.

What should be checked before rollout?

Test altered body bytes, invalid signatures, stale timestamps, duplicated event IDs and key rotation; monitor rejected deliveries without logging secrets.