Review a Webhook Receiver for Forged Requests, Replays, Duplicate Deliveries, and Out-of-Order Events
You are a senior backend engineer reviewing the code of a webhook receiver: an HTTP endpoint that third-party systems call to notify us of events. Review the code I paste below and report only problems you can tie to specific lines. Work through these areas in order, and for each one say "no issue found" or give a finding: 1. Authenticity. Is the signature verified over the raw request bytes, before any JSON parsing or re-serialization? Is the comparison constant-time? Is the secret loaded from configuration rather than hard-coded? Is there a timestamp check, and does the tolerance window make sense? 2. Replay and duplicates. Providers usually deliver at least once. Is there a stored event ID checked atomically before side effects run? Is the check-then-act sequence racy if two deliveries arrive together? What happens if the handler crashes after the side effect but before the ID is recorded? 3. Ordering. Can an older event arrive after a newer one and overwrite fresher state? Does the code compare version numbers or timestamps from the payload, or does it assume arrival order equals event order? 4. Response behavior. Does the endpoint acknowledge quickly and defer slow work, or does it do heavy work inline and risk provider timeouts and retry storms? Which error conditions return 2xx (dropping the event forever) versus 5xx (inviting a retry)? Is a permanently bad payload distinguished from a transient failure? 5. Unknown input. What happens with unknown event types, missing fields, or a payload larger than expected? Output format: a numbered list of findings. For each: severity (high, medium, low), the line or function, a one-sentence description of the failure, a concrete sequence of events that triggers it, and a minimal fix. Finish with a short list of tests you would add, each stated as input and expected result. Do not rewrite the whole file, and do not comment on style. --- When to use this: before merging a new webhook integration, or when a provider's dashboard shows delivery failures or duplicate side effects you cannot explain. How to adapt it: name the provider and paste its signature documentation into the prompt if the scheme is unusual. If your system already has a queue in front of the handler, tell the model, so it focuses on the enqueue step. Add your framework if body parsing middleware is a concern, since raw-body access differs between frameworks. Example input: a 60-line Express or Flask handler that parses JSON, calls a billing library to mark an invoice paid, and returns 200. Good output flags that the signature is computed over the re-serialized body, that the invoice is marked paid twice when the provider retries, and that a "payment_failed" event arriving late reopens a paid invoice, each with a trigger sequence and a fix such as raw-body verification, a unique-constraint insert of the event ID, and a version comparison before update.
Sign in to upvote this prompt.