# Webhook Security
# Why this is required now
Automated attack tools, including AI agents, make it cheap to forge a webhook or to replay one that was sent before. A forged activate gives someone a free license. A replayed activate can switch a refunded license back on.
So AppSumo now requires this for every listing, new or revised:
- verify the signature of every webhook, and
- refuse a webhook that is more than 5 minutes old (or 5 minutes in the future).
AppSumo's QA check sends a webhook with a bad signature and a correctly signed webhook dated 10 minutes ago. If your server accepts either one, the listing fails QA. If you built your handler earlier without these checks, add them now.
# The rules
| # | Rule | What to do | When the check fails |
|---|---|---|---|
| 1 | Verify the signature | HMAC-SHA256 of the timestamp and the raw request body, with your private key. Compare in constant time. | Answer 401. Do not process the event. |
| 2 | Refuse old and future requests | Reject when X-Appsumo-Timestamp is more than 5 minutes (300,000 ms) from your server's clock, either direction. | Answer 401. Do not process the event. |
| 3 | Apply events in order | For each license key, ignore an event that is older than the last event you applied. Compare created_at. | Answer 200 with "success": true. The event is handled; nothing changes. |
| 4 | Make every handler idempotent | The same event can arrive more than once. A repeat must give the same result. | Answer 200 with "success": true. |
| 5 | Answer only after the change is saved | 200 with "success": true only when the event is applied. | On your own error, answer 5xx. AppSumo sends it again. |
| 6 | Keep the key secret | HTTPS only. Never log the signature header, your private key or full request bodies. | Rotate the key if it leaks. |
# How AppSumo signs a webhook
Every webhook, including test webhooks, has two headers:
| Header | Value | Example |
|---|---|---|
X-Appsumo-Timestamp | The time AppSumo sent this request, in milliseconds since the Unix epoch, as decimal digits. | 1763560000000 |
X-Appsumo-Signature | HMAC-SHA256 of the message below, as 64 lowercase hex characters. | 5f0c…e91a |
The signed message is the X-Appsumo-Timestamp value followed directly by the raw request body, with nothing between them:
message = X-Appsumo-Timestamp + raw request body
signature = lowercase_hex( HMAC_SHA256( key = your private key, message ) )
- The key is your private key: the API key on your product's Redemption page in the AppSumo Partner Portal (opens new window). It is the same key you send in
X-AppSumo-Licensing-Keyto the Licensing API (See API: Getting started). - The body must be the exact bytes AppSumo sent. Read it before you parse the JSON. If your framework parses the JSON and you encode it again, the spacing, key order or escapes can change, and the signature does not match.
- Each delivery is signed again with the current time. This includes retries. So a real webhook is never more than a few seconds old when it arrives, and the 5-minute window never refuses a real retry.
Where to get the raw body:
| Framework | Raw body |
|---|---|
| Express | express.raw({ type: '*/*' }) on the webhook route, then req.body (a Buffer). Not express.json(). |
| Next.js (route handler) | Buffer.from(await request.arrayBuffer()) |
| Flask | request.get_data() |
| Django | request.body |
| Laravel | $request->getContent() |
| Plain PHP | file_get_contents('php://input') |
Go net/http | io.ReadAll(r.Body) |
# Verify the signature and the timestamp
Both checks are required. Do them before you read anything from the body.
- Read the raw body,
X-Appsumo-TimestampandX-Appsumo-Signature. - Refuse the request if the timestamp is not a number, or if it is more than 5 minutes from your server's clock in either direction. Keep your server's clock in sync (NTP).
- Compute the HMAC-SHA256 of
timestamp + raw bodywith your private key, as lowercase hex. - Compare it with
X-Appsumo-Signatureusing a constant-time compare (crypto.timingSafeEqual,hmac.compare_digest,hash_equals,hmac.Equal). A normal==leaks timing. - If any check fails, answer
401and stop. Refuse the request if your private key is not set: an empty key is a key anyone can sign with.
Each example below is a complete webhook handler. Set the APPSUMO_PRIVATE_KEY environment variable to your private key.
1
# Check your code with a known example
Sign these exact inputs with your code. If it does not give the signature below, your code does not sign webhooks the way AppSumo does.
| Input | Value |
|---|---|
| Private key | c73455d8-0f64-4354-bd64-1f454a227104 |
X-Appsumo-Timestamp | 1625165884119 |
| Raw body | {"license_key":"3794577c-3dbc-11ec-9bbc-0242ac130002","event":"purchase","event_timestamp":1625165884119,"created_at":1625165884100,"license_status":"inactive","tier":1,"extra":{"reason":"Purchased by customer"}} |
X-Appsumo-Signature | 461692dfb71bd544a78f38c5896886a7c3326611d55d15dc5f5231c6a377e5c3 |
Each example below prints true. It checks only the signature: this timestamp is years old, so the 5-minute check in your handler refuses it.
1
# Apply events in order, and only once
AppSumo retries a webhook that your server did not accept, up to 5 times (See Retries). So:
- The same event can arrive more than once. Applying it twice must give the same result as applying it once. For example, an
activatefor a license that is already active changes nothing and answers"success": true. AppSumo's QA check sends the sameactivatetwice. - An older event can arrive after a newer one. For example: the
activatefails because your server is down, the customer gets a refund, thedeactivatearrives, and then the retry of the oldactivatearrives. If you apply thatactivate, the refunded customer gets the product again.
To stop this, for each license_key, save the created_at of the last event you applied. When an event arrives with a smaller created_at for the same license_key, do not apply it, and answer 200 with "success": true so AppSumo stops retrying it.
| Field | Meaning | Use it for ordering? |
|---|---|---|
created_at | The time AppSumo created the event, in milliseconds. It does not change when AppSumo retries. | Yes |
event_timestamp | The time AppSumo sent this delivery, in milliseconds. It changes on every retry. | No. A retry of an old event has a new event_timestamp. |
X-Appsumo-Timestamp | The time this request was signed. Use it only for the 5-minute check. | No |
Two different events for one license_key can share a created_at. For example, an add-on bought for a parent deal that is already active gets a purchase and an activate created in the same millisecond. Break a tie by the event's rank:
| Rank | Events |
|---|---|
| 0 | purchase |
| 1 | activate, upgrade, downgrade, migrate |
| 2 | deactivate |
Apply an event when its (created_at, rank) is the same as or later than the last one you applied for that license_key. On a full tie, apply it: a repeat of the same event changes nothing, and a different event of the same rank (for example an add-on's migrate) still takes effect. A tie between activate and deactivate keeps the license inactive, so a refund always wins.
One way to do it is a single conditional update, so two deliveries at the same time cannot both win:
UPDATE appsumo_licenses
SET status = :status, tier = :tier,
last_event_created_at = :created_at, last_event_rank = :rank
WHERE license_key = :license_key
AND (last_event_created_at IS NULL
OR last_event_created_at < :created_at
OR (last_event_created_at = :created_at AND last_event_rank <= :rank));
If you add these columns to a table that already has licenses, fill them for every existing key before the new handler goes live, with the created_at and the rank of the last event you applied to that key. If you did not save that event, do not put in a time of your own: a local time can be later than an event that is still being retried, and that event is then skipped. Leave those rows empty, and once AppSumo has stopped retrying older events (See Retries), compare each of them with AppSumo's state from GET /v2/licenses/:license_key and correct any license whose status is different.
For an upgrade or downgrade, the event has a new license_key. Find the account by prev_license_key, save the new key and tier with the event's created_at, and mark the old key inactive. AppSumo also sends a deactivate for the old key as its own event; applying it again changes nothing.
# Answer correctly and quickly
| Situation | Answer |
|---|---|
| The signature or the timestamp check fails | 401 (or 403). Do not process the event. |
| The event is applied, or was applied before, or is older than the last one applied | 200 with {"success": true, "event": "<event>"} |
| Your own error (for example, your database is down) | 5xx. AppSumo sends the event again later. |
- Answer
"success": trueonly after the change is saved. AppSumo marks the license as active or inactive on its side when you answer"success": true. - Answer within 10 seconds. AppSumo stops waiting after 30 seconds and retries. Do slow work, such as sending email, after you answer.
- Use
401or403for a failed check, not200with"success": false. During a planned key rotation, AppSumo sends a webhook refused with400,401or403again at once, signed with your old key, so you do not miss events while you deploy the new key.
# Keep your private key secret
- Use an
https://webhook URL. Over plainhttp://, anyone on the network path can read and change the request. - Keep the private key in an environment variable or a secret manager. Never put it in source code, in a repository or in code that runs in a browser.
- Never log the
X-Appsumo-Signatureheader, your private key or full request bodies. Log thelicense_key, theeventand your answer. - If the key leaks, rotate it at once (See How do I rotate my private key or client secret?).
# What AppSumo's QA check tests
The QA check plays a full test customer through your webhook URL with test license keys. These are the webhook steps, in order:
| Step | What AppSumo sends | A pass |
|---|---|---|
activate | A signed activate for a test license key. | 2xx with "success": true. The key is active in your database. |
activate_again | The same activate again. | 2xx with "success": true. Nothing changes: the handler is idempotent. |
bad_signature | An activate signed with a key that is not yours. | Your server refuses it: 401 or 403. |
stale_timestamp | An activate correctly signed, with X-Appsumo-Timestamp 10 minutes in the past. | Your server refuses it: 401 or 403. |
upgrade | An upgrade with a new license_key, and prev_license_key set to the active key. | 2xx with "success": true. The new key is active with the new tier. The old key is inactive. |
downgrade | A downgrade with a new license_key, and prev_license_key set to the upgraded key. | 2xx with "success": true. The new key is active with the new tier. The old key is inactive. |
deactivate | A deactivate for the downgraded key. | 2xx with "success": true. The key is inactive. |
If your server accepts the bad_signature or the stale_timestamp request, the listing fails QA. The check also tests your redirect URL, your private key, the OAuth flow and how fast your server answers.