Stripe webhook accepts fake payments: how to fix it
A Stripe webhook that grants access without a signature check lets anyone send a fake checkout.session.completed event and get a paid account. Verify the Stripe-Signature header on the raw body with the whsec_ secret before you do any work. After that, confirm the payment with Stripe and ignore events that you already handled.
This guide shows how to test your endpoint and how to fix it in Next.js, Express, and Supabase Edge Functions. It also shows how to find accounts that a fake event upgraded.
What does “unverified Stripe webhook” mean?
It means that your endpoint trusts a POST request because of its content. The request says “a payment worked.” The endpoint believes it and upgrades the account. Nothing proves that Stripe sent the request.
A webhook URL is not a secret. It has a common name, such as /api/webhook or /api/stripe/webhook. An attacker can guess it. The attacker can also read it in your public code or in a log. Then the attacker sends a JSON body that looks like a Stripe event.
The Stripe documentation on endpoint best practices states the risk. Without verification, an attacker can send fake webhook events to your endpoint. These events can fulfil orders, grant account access, or change records.
Most search results for “Stripe webhook signature” explain the error No signatures found matching the expected signature for payload. That error means that your check works but your input is wrong. This guide covers the opposite case. The endpoint has no check, or the check is not strict.
These are the usual causes:
- No check at all. The handler reads
req.json()and trusts thetypefield. - A check that does not stop the request. The code verifies the signature but continues when the check fails.
- A skipped check in development. A flag such as
if (process.env.NODE_ENV !== "production")turns the check off. The flag is wrong in production. - The wrong secret. The code uses the API key. A fixed or empty string also passes some bad examples.
- A trust in the event data. The code verifies the signature but never checks the amount or the product.
- A public Edge Function with no other check. The function has JWT checks turned off, as Stripe needs, but it has no signature check. The guide on Edge Functions with no JWT explains the risk.
AI coding tools often write the first version of a webhook with req.json(). The tool wants the code to run, so it skips the check. The app works in a test and the bug stays.
How do I confirm that my webhook accepts fake events?
Send a fake event to your own endpoint. Use a test account and a test project. Do not use real customer data.
- Find the endpoint URL. Open the Stripe Dashboard, open Developers, and select Webhooks. Copy the URL.
- Create a file named
fake-event.json. Use a test user id that you own.
{
"id": "evt_fake_0001",
"object": "event",
"type": "checkout.session.completed",
"data": {
"object": {
"id": "cs_test_fake",
"object": "checkout.session",
"client_reference_id": "YOUR_TEST_USER_ID",
"customer": "cus_fake",
"payment_status": "paid",
"mode": "subscription"
}
}
}
- Send the event with no signature.
curl -i -X POST https://your-app.example/api/stripe/webhook \
-H "Content-Type: application/json" \
--data @fake-event.json
- Send the event again with a false signature.
curl -i -X POST https://your-app.example/api/stripe/webhook \
-H "Content-Type: application/json" \
-H "Stripe-Signature: t=1700000000,v1=0000000000000000000000000000000000000000000000000000000000000000" \
--data @fake-event.json
A correct endpoint returns 400 for both requests. A 200 response is a failure. Open your app and check the test account. If it now has a paid plan, the endpoint accepts fake payments.
Warning: A request that works changes real data. Use a test account. Reset the plan after the test.
Check the other paths too. Common names are /api/webhook, /api/webhooks/stripe, /webhook, /stripe/webhook, and /functions/v1/stripe-webhook. Test each path that exists in your code.
The pattern guide on Stripe webhooks and paid trust lists more places where an app trusts a payment claim.
How do I fix it now?
Do these steps in order.
Caution: After you turn on the check, your own tests with a hand-made JSON body fail. This is correct. Use the Stripe CLI to send signed test events.
- Add the signature check. Use
constructEventwith the raw body. - Use the endpoint secret. Use the
whsec_value, not the API key. - Return
400when the check fails. Do no other work. - Confirm the payment with Stripe. Fetch the object from the Stripe API.
- Process each event once. Store the event id.
- Rotate the secret if the endpoint was open. See the section on the secret.
- Test again. Repeat the
curltests.
The Stripe documentation says that constructEvent() takes three values: the raw request body, the Stripe-Signature header, and the endpoint secret. If one value is wrong, the check fails.
How do I verify the signature in Next.js?
In the App Router, read the body with req.text(). Do not use req.json(). The check needs the exact bytes.
// app/api/stripe/webhook/route.ts
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(req: Request) {
const body = await req.text();
const signature = req.headers.get("stripe-signature");
if (!signature) return new Response("Missing signature", { status: 400 });
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(
body,
signature,
process.env.STRIPE_WEBHOOK_SECRET!
);
} catch {
return new Response("Invalid signature", { status: 400 });
}
// Use event here. Only a verified event reaches this line.
return new Response("ok");
}
The Stripe docs link to a working Next.js example in the stripe-node repository. In the Pages Router, turn off bodyParser for the route and read the raw buffer.
How do I verify the signature in Express?
Express parses JSON for the whole app if you add express.json() first. That parser changes the body. Put the webhook route before it, and use express.raw on that route.
import express from "express";
import Stripe from "stripe";
const app = express();
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
app.post(
"/webhook",
express.raw({ type: "application/json" }),
(req, res) => {
let event;
try {
event = stripe.webhooks.constructEvent(
req.body,
req.headers["stripe-signature"],
process.env.STRIPE_WEBHOOK_SECRET
);
} catch {
return res.sendStatus(400);
}
// Use event here.
res.sendStatus(200);
}
);
app.use(express.json()); // After the webhook route.
Stripe gives the same advice. It says that app.use(express.json()) must appear after the webhook route.
How do I verify the signature in a Supabase Edge Function?
Stripe cannot send a Supabase JWT. You must turn off the JWT check for this one function. Then the signature check is the only door. Set it in supabase/config.toml:
[functions.stripe-webhook]
verify_jwt = false
Deno has no Node crypto module. Use the async method and the Web Crypto provider:
// supabase/functions/stripe-webhook/index.ts
import Stripe from "npm:stripe";
const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!);
const cryptoProvider = Stripe.createSubtleCryptoProvider();
Deno.serve(async (req) => {
const signature = req.headers.get("stripe-signature");
if (!signature) return new Response("Missing signature", { status: 400 });
const body = await req.text();
let event: Stripe.Event;
try {
event = await stripe.webhooks.constructEventAsync(
body,
signature,
Deno.env.get("STRIPE_WEBHOOK_SECRET")!,
undefined,
cryptoProvider
);
} catch {
return new Response("Invalid signature", { status: 400 });
}
// Use event here.
return new Response("ok");
});
Set the secrets with the Supabase CLI. Do not put them in code:
supabase secrets set STRIPE_SECRET_KEY=sk_live_... STRIPE_WEBHOOK_SECRET=whsec_...
Which secret must I use?
Use the signing secret of the endpoint. It starts with whsec_. Do not use the API secret key that starts with sk_. The API key lets you call Stripe. The signing secret lets you check what Stripe sent to you.
Each endpoint has its own secret. The Stripe docs warn that two secrets exist. The secret for a CLI forwarded endpoint is different from the secret for a Dashboard endpoint. Do not mix them. To find the Dashboard value, open the endpoint in Workbench and select Reveal secret. The stripe listen command prints the CLI secret in the terminal.
Use two environment variables for two modes. A test-mode endpoint and a live-mode endpoint have different secrets.
If the endpoint was open, rotate the secret. In Workbench, open the endpoint and use Roll secret. Stripe lets you keep the old secret active for up to 7 days. During that time, Stripe signs each event with both secrets. Update your server in this window.
Caution: A rolled secret does not undo the damage of fake events. It only stops an attacker who has the old secret. Check your accounts as shown below.
Stripe also advises you to accept webhook requests only from Stripe IP addresses. Use this as an extra layer. A signature check is still required. Stripe says to use both protections.
How do I confirm the payment before I grant access?
A valid signature proves that Stripe sent the event. It does not prove that the event matches what you sold. Check the values. Then grant access.
- Get the object id from the verified event.
- Fetch the object from Stripe with your API key.
- Check
payment_status, the amount, the currency, and the price id. - Check that the user id belongs to a real user in your database.
- Grant access only when all values match.
if (event.type === "checkout.session.completed") {
const eventSession = event.data.object as Stripe.Checkout.Session;
const session = await stripe.checkout.sessions.retrieve(eventSession.id, {
expand: ["line_items"],
});
const priceId = session.line_items?.data[0]?.price?.id;
const ok =
session.payment_status === "paid" &&
priceId === process.env.PRO_PRICE_ID &&
!!session.client_reference_id;
if (!ok) return new Response("ignored", { status: 200 });
// Grant access for session.client_reference_id here.
}
This step also helps when a bug or a test event reaches the handler. The real state is in Stripe, not in the body of the request.
Set client_reference_id on your server when you create the Checkout Session. Do not take it from the browser at the time of the webhook.
Subscriptions need more events. Handle customer.subscription.updated, customer.subscription.deleted, and invoice.payment_failed. Then a user who cancels or fails to pay loses access.
How do I process each event only once?
Stripe can send the same event more than once. The Stripe docs say that webhook endpoints “might occasionally receive the same event more than once”. The docs advise you to store the event ids that you processed and skip the ids that you already logged.
A retry or a replay can grant a credit pack twice. The pattern guide on race conditions in money paths explains why two parallel requests also cause double grants.
Use the database to make the check atomic. A primary key does the work:
create table public.stripe_events (
id text primary key,
type text not null,
received_at timestamptz not null default now()
);
alter table public.stripe_events enable row level security;
revoke all on public.stripe_events from anon, authenticated;
Insert the id before you grant access. If the insert fails because the id exists, stop.
const { error } = await admin
.from("stripe_events")
.insert({ id: event.id, type: event.type });
if (error?.code === "23505") return new Response("duplicate", { status: 200 });
if (error) return new Response("error", { status: 500 });
Return a 200 status for a duplicate. Then Stripe stops its retries.
The table also gives you a record. You can compare it with Stripe in the next section.
How do I find accounts that a fake event upgraded?
Compare your records with Stripe. A fake event never exists in Stripe.
- List the paid accounts in your database. Note the Stripe customer id of each account.
- List active subscriptions in Stripe.
stripe subscriptions list --status active --limit 100
- Find the difference. A paid account with no matching subscription is a suspect. A customer id that Stripe does not know is a strong sign.
- Check the event ids. If you stored ids, test each one in Stripe. A fake id returns an error.
stripe events retrieve evt_1234567890
- Look for ids with a strange pattern. Ids such as
evt_fakeorevt_test_1are not from Stripe. - Read the request logs of the endpoint. Look for
200responses that came from IP addresses outside the Stripe list. - Check Workbench. Open the endpoint and read Event deliveries. A grant in your database with no delivery in Stripe has another source.
- Reset the accounts. Remove the plan from the wrong accounts after you close the endpoint.
This query shows paid accounts with no Stripe customer:
select user_id, plan, updated_at
from public.subscriptions
where plan <> 'free'
and (stripe_customer_id is null or stripe_customer_id like 'cus_fake%')
order by updated_at desc;
Also check for credits, coupons, and refunds. A fake charge.refunded or invoice.paid event can change a balance.
How do I stop this problem in the future?
- Write a test. Send an unsigned event and a false signature. Expect
400for both. Run the test in your build. - Use the Stripe CLI for local tests. Run
stripe listen --forward-to localhost:3000/api/stripe/webhook. The CLI signs each event. Use the secret that the CLI prints. - Never turn the check off in any mode. A flag that skips verification will reach production.
- Keep the keys out of the browser. Use only the publishable key in client code. Read the token leak checker result if you suspect a leak.
- Use a restricted key. Give the server key only the permissions that it needs.
- Log each rejected request. A spike of
400responses shows that someone tests your endpoint. - Review code from AI tools. Search for
req.json()andJSON.parsein the webhook file. Ask what proves the sender. - Scan the live app after each release.
When should I get help?
Get help in these cases:
- You find paid accounts with no Stripe record and you cannot say how many.
- Fake events changed credits, balances, or refunds.
- The
service_rolekey or the Stripe secret key was in a public place. Rotate both keys. - Your handler also writes data that other systems use, such as invoices or tax records.
- You cannot find the raw body in your framework. Ask an engineer to review the route.
After the fix, repeat the curl tests. Both fake requests must return 400. Then send a signed test event with the Stripe CLI. It must return 200 and grant access only once.
Common questions
Is the webhook URL a secret?
Which secret does constructEvent need?
Why does my signature check fail after I parse the body?
Is a valid signature enough to grant access?
Must I check each event only once?
Test your webhook endpoint
A VibeEval scan finds common webhook paths on your live app and tests if they accept an event with no valid signature.
14-day free trial · Cancel anytime