Verify webhook senders by checking signatures, stored secrets, event IDs and payload versions before allowing trial or onboarding actions.
Key takeaways
- Confirm the sender before trusting the payload.
- Protect the secret and confirm the endpoint.
- Use event IDs to prevent repeated actions.
- Validate required fields and test version changes.
A payment succeeds, a subscription is created, or a form is submitted in a partner tool, and a webhook arrives at your product to say so. Your code then starts a trial, adds the account to an onboarding email sequence, or changes a plan flag. Each of those actions costs something. A free trial may go to someone who never signed up, an email may go out twice, or an account may be marked as paying when it is not.
A webhook is a plain HTTP request. Your endpoint is a public URL, so anyone who finds it can send a request to it. The sender may be your billing provider, a tester checking your setup, or someone hoping for a free trial. Your endpoint cannot tell these apart from the request alone, so it needs checks.
This post covers four checks to finish before a webhook event is allowed to trigger trial logic, an onboarding email, or an account update. Each check is small. Together they close the gap between "a request arrived" and "a real event happened once, in a format we understand." The examples come from the public developer docs of PayPal, Square, Asana, and Stripe. They show the rules clearly, but your own billing tool may work differently, so read its pages too.
You can use this list without writing the code yourself. A growth lead can ask engineering to confirm each check, then ask the vendor for the page that supports it. If the answer is missing from the docs, take that question back to the vendor before launch. For the wider setup, see trial settings for a billing stack.
Why trial events need more than a status check
Many teams start with a simple rule: if the webhook says "trial started," start the trial. That works until the first unexpected request. A test tool sends a sample payload to the live URL. Someone outside the company posts a made-up event. A real event is retried after a timeout and arrives a second time. Each case is ordinary, and none of them should give an account a trial.
Trial events deserve extra care for a second reason. They often sit at the start of a chain. A trial start can lead to a welcome email, a seat assignment, a usage quota, a sales task, and a report that counts the account as a lead. A wrong event at the top spreads into all of those places. Cleaning up later means refunds, apology emails, and corrected reports.
So the checks belong before any business logic, not inside it. The webhook handler should check the sender, secret and endpoint, event ID, and payload shape and version before starting the trial or sending the email.
It helps to name the boundary. Many teams put a small receiver in front of their logic. The receiver accepts the request, runs the checks, writes a record of what it decided, and returns a response. The trial logic reads from that record. This split also makes testing simpler, because you can send the receiver bad input and confirm it stops there.
Check 1: Verify the sender before you trust the payload
The first check is about identity. Your endpoint should confirm the request came from the provider before it trusts the body. PayPal's webhook documentation states the risk in one sentence: "If you do not verify a message, you will not have a way to validate that its sender was in fact PayPal." Skipping verification does not just leave a gap. It removes your ability to say who sent the event at all.
With a shared-secret signature, the provider computes a value from the request and a secret that only you and the provider share. Your server computes the same value and compares the two. If they match, the request came from someone holding the secret. If they do not, the request is rejected.
Asana describes its method in plain terms. Its signature is "a SHA256 HMAC signature computed on the request body using the shared secret transmitted during the handshake," as set out in Asana's webhook guide. You do not need to memorize the algorithm. What matters is that the signature depends on the body. If anything changes the body, the check fails, which is what you want.
That dependence creates a common bug. The bytes you hash may then differ from the bytes the provider signed, even though the data looks the same. The check then fails for real events. The reverse problem is also possible: a changed body passes because your code hashed something other than what arrived. Compute the signature over the raw bytes, exactly as they came in, before any parsing.
A good verification step does four things in practice:
- It reads the raw request body and the signature header.
- It computes the expected value with the stored secret and compares the two using a constant-time comparison function, if available in your language or framework.
- It rejects the request with a client error when they do not match, and writes a log line with the event type and time, but never the secret.
- It does nothing else with the payload when verification fails. No database writes, no emails, no trial starts.
Ops teams often ask whether to alert on failures. A rise in rejected requests can mean a bad secret after a rotation, a changed endpoint, or someone probing your URL. Alert on the count, and check the logs when it moves. Do not treat every rejection as an attack, but do not ignore a sudden change either.
Check 2: Confirm the handshake and guard the secret
Some providers require a setup step before they send any events. Asana is one example. Its guide describes a handshake in which your server receives a secret in a header, echoes it back, and the provider then confirms the webhook. The guide says, "Once the handshake has completed, Asana returns a 201 Created response as the webhook is successfully established." Until you see that response, the webhook is not live, and your team should not assume it is.
The same guide has two rules about the secret that are worth copying into your own process. The first: "The secret should match the value returned in the X-Hook-Secret header from Step 2." The second: "We recommend that you verify this by comparing it with the X-Hook-Secret stored by your webhook server (Step 3)."
Not every provider uses a handshake, and those that do may name the step differently. Find the equivalent in your billing tool's docs and confirm three things: when the secret is issued, where it is stored, and who can read it.
Treat the secret like a password. Keep it in a secrets manager or in your platform's protected settings, not in source code, a shared document, or a chat thread. Limit who can read it. When someone leaves the team, check whether they had access.
Rotation needs a plan too. When a secret changes, there is a window where the old and new values both matter. The safe pattern is to accept the new secret, confirm events are passing, and then retire the old one. If your provider lets you keep two secrets active during rotation, use that. If it does not, schedule the change for a quiet period and watch the rejection count while it happens.
Finally, confirm the endpoint is still the one you think it is. A handshake proves the provider reached your URL at setup time. It does not prove that URL still belongs to your product. If a domain or path changes, repeat the setup and remove the old webhook registration.
Compare provider requirements before launch
Each provider handles verification, repeat deliveries, and versioning in its own way. Before you commit a flow, collect the answers for every tool that can start a trial. For each vendor, ask three things: how the signature is built, how a repeated event shows up, and which API version the payload uses.
Stripe allows up to 16 event destinations, which matters for planning. A team that creates a new destination for every experiment can run out. Plan a small set of destinations up front, with a separate destination for each environment and purpose, and reuse them. If you add a destination, record why, so a later cleanup does not remove the one your trial logic depends on.
Check 3: Ignore repeats using the event ID
The third check protects you from the same event arriving twice. Retries are normal. A network timeout on your side can make the provider send the event again even though your code already handled it. Square's documentation gives a clear path: "You can bypass the processing of repeated notifications using the idempotency value included as the event_id field in the body of each event notification."
The implementation is simple to describe and easy to get wrong. Store each processed event ID in a table with a unique constraint on that column. After the sender check passes and before any trial or email logic runs, try to insert the event's ID. If the insert succeeds, the event is new, and your code runs the trial or email logic. If the insert fails because the ID already exists, the event is a repeat, and your code returns a success response without acting.
The order matters. If you run the trial logic first and record the ID afterward, two copies of the same event can arrive at nearly the same moment and both pass the check. The unique constraint is what makes the database enforce the rule, even when two requests race. Where your database allows it, put the insert and the trial action in one transaction, so that a failure in the action also rolls back the record of the ID. Otherwise you risk marking an event as handled when nothing happened.
Keep the ID record for a long enough period that retries cannot slip past it. Choose a retention period with your engineering team and write it down. Do not assume a provider's IDs will never repeat across different event types, so store the event type alongside the ID when your provider supplies one.
If a provider does not offer an event ID in the body, look for another stable identifier in its docs before you build your own. An ID built from the account and timestamp can collide with a real second event, so use it only as a last resort and test it hard. For the email action, see prevent duplicate welcome emails.
Check 4: Record the API version and validate fields
The fourth check is about the shape of the payload. Your code maps fields like plan, status, and customer ID into your own records. That mapping was written against one version of the provider's data format. If the format changes, the mapping can silently read the wrong field or find nothing at all.
Stripe's documentation includes an example that shows how this can happen. In its words: "For example, if your account is set to an older API version, such as 2015-02-16, and you change the API version for a specific request with versioning, the Event object generated and sent to your destination is still based on the 2015-02-16 API version." Your code should not assume the payload matches the version you tested against.
Three habits reduce this risk. First, record the API version each event was built with, in your logs or in the receiver's record. When something breaks, you can then tell whether the cause is your code or a version change. Second, check that the fields your trial logic needs are present and have the expected type before you act. If a required field is missing, send the event to a review queue rather than starting the trial. Third, when your provider announces a version change, run your mapping against sample events from the new version before the change reaches production traffic.
This check also limits the damage from a bad event that passes the first three checks. A signed event from a real sender can still carry a field your code does not expect. If your code refuses to act on an unknown shape, that event becomes a support ticket instead of a trial granted in error.
Ask the vendor whether it offers a test mode or sandbox where you can trigger sample events. Use it to check your mapping against the version you plan to run, and keep the sample payloads in your repository next to the tests. When the vendor changes its version, those saved samples show exactly which fields moved.
Putting the checks in order
The four runtime checks follow the pre-launch provider comparison. First, verify the signature on the raw body and reject anything that fails. Second, confirm that the stored secret is current and that the endpoint still belongs to your product. Third, check whether the event ID has been processed, and record it in the same transaction as the action. Fourth, confirm the payload shape and version. Only then should the trial, the onboarding email, or the account update run.
Before you launch, test the whole path with four cases. Send a correctly signed event and confirm it triggers one trial. Send the same event again and confirm it is skipped. Send an event with a bad signature and confirm it is rejected with nothing written. Send a correctly signed event with a missing required field and confirm it goes to review. If any case behaves differently, fix the receiver before turning the webhook on for real customers.
Finally, keep a short document for each billing tool. List the signature method, the setup step, the event ID field, the API version in use, and the vendor page that supports each answer. The growth lead does not need to read the code to check this list. They need to know that each trial event has passed the checks, that the record exists, and that the page behind each answer is one the team can point to. That document is what keeps the next integration from starting with the same gaps.
Illustrative example: A repeated trial event
All have a valid signature and the expected fields. The first delivery starts 1 trial; the remaining 9 find the recorded ID and trigger 0 additional trials. Check the trial record and email action to confirm the repeated deliveries caused no extra work.
Your next step today
Ask engineering to run the four test cases above against your receiver and record the result of each before enabling customer events.
Related guides: Phone number format: 4 checks for a signup text sender · Verify a signup email: 4 Auth0 checks before the link · Signup workflow limits: 5 to check before you launch.
Questions before launch
Does a valid signature prevent duplicate trials?
No, a valid signature checks the sender; the event ID check prevents repeated processing.
What should happen when a required field is missing?
Send the event to a review queue without starting the trial.
Can setup confirmation replace later sender checks?
No, setup confirmation establishes the webhook; later requests still need verification.