Verify Signed Webhook Payloads With Timestamp Tolerance and Secret Rotation

Last updated: November 29, 2026

Quick Overview

Write a function that verifies an incoming webhook by parsing a signature header of the form t=timestamp,v1=signature, recomputing an HMAC-SHA256 over the timestamp and raw body, rejecting stale timestamps, and accepting any currently valid secret during rotation.

Stripe
Software Engineering Fundamentals
Software Engineer
Stripe
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Write a function that verifies an incoming webhook by parsing a signature header of the form t=timestamp,v1=signature, recomputing an HMAC-SHA256 over the timestamp and raw body, rejecting stale timestamps, and accepting any currently valid secret during rotation.

Stripe signs every webhook so merchants can reject forged or replayed events, and its client libraries ship exactly this verification helper. Interviewers use it to test practical networking and security fundamentals: raw bytes versus parsed JSON, constant-time comparison, replay windows, and writing tests that prove each rejection path.

What the Interviewer Expects
  • Signs the raw request bytes, not re-serialized JSON
  • Parses multiple v1 signatures and ignores unknown schemes for forward compatibility
  • Uses a constant-time comparison
  • Rejects timestamps outside a tolerance window to limit replays
  • Supports more than one secret so rotation does not drop events
  • Lists unit tests for tampered body, stale timestamp, malformed header, and rotated secret
Key Topics to Cover
HMAC-SHA256
replay protection
constant-time comparison
secret rotation
testing
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Why does the timestamp go inside the signed string rather than alongside it?
  • The tolerance window still allows a replay within five minutes. How would a merchant close that gap?
  • How would you debug a merchant who says every webhook fails verification in production but passes locally?
  • How would you roll out a v2 signature scheme without breaking existing endpoints?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Input: raw body bytes, the header string, a list of endpoint secrets, a tolerance in seconds.
  • Valid if some v1 signature equals HMAC_SHA256(secret, f"{t}.{body}") for some secret and `|now - t...
High-Level Design

Three steps: parse the header into a timestamp and a list of v1 values, check freshness, then compute the expected signature for each secret and compare against each provided signature in constant t...


Submit Your Answer
Markdown supported