WEBVTT

00:00.096 --> 00:01.250
A Stripe signature check

00:01.250 --> 00:02.896
can go wrong two ways.

00:02.896 --> 00:03.689
It's missing,

00:03.689 --> 00:05.444
so anyone can fake a payment.

00:05.444 --> 00:06.358
Or it's broken,

00:06.358 --> 00:08.124
so real payments fail.

00:08.220 --> 00:09.313
Missing first.

00:09.313 --> 00:11.044
If your handler parses the JSON

00:11.044 --> 00:14.073
and grants access on checkout session completed,

00:14.073 --> 00:14.902
anyone who knows the URL

00:14.902 --> 00:17.306
can post a hand-written event.

00:17.306 --> 00:19.085
Webhook paths are predictable,

00:19.085 --> 00:21.576
so treat the URL as public.

00:21.684 --> 00:23.631
The free check at webhookproof.com

00:23.631 --> 00:24.460
tests this from the outside.

00:24.460 --> 00:26.359
It sends an unsigned event

00:26.359 --> 00:28.620
and a fake-signed one.

00:28.716 --> 00:29.713
A protected endpoint

00:29.713 --> 00:32.040
refuses both, like this.

00:32.136 --> 00:34.287
This demo endpoint answers 200

00:34.287 --> 00:35.705
to an unsigned event,

00:35.705 --> 00:37.620
so the check marks it critical.

00:37.716 --> 00:38.785
Now, broken.

00:38.785 --> 00:40.937
Stripe needs the raw request body.

00:40.937 --> 00:43.245
If your framework parses JSON first,

00:43.245 --> 00:45.156
the signature no longer matches,

00:45.156 --> 00:47.259
and you get: No signatures found

00:47.259 --> 00:49.290
matching the expected signature.

00:49.290 --> 00:51.081
Read the body as text,

00:51.081 --> 00:53.052
or use express raw on that route,

00:53.052 --> 00:55.944
and pass it unchanged to construct event.

00:56.040 --> 00:57.446
Also check the secret.

00:57.446 --> 00:58.852
Test and live endpoints

00:58.852 --> 01:00.739
have different signing secrets,

01:00.739 --> 01:02.218
and the stripe listen secret

01:02.218 --> 01:03.395
is different again.

01:03.395 --> 01:05.367
Ship the test one to production,

01:05.367 --> 01:07.572
and every live event fails.

01:07.668 --> 01:09.627
Don't fix it by deleting the check.

01:09.627 --> 01:11.598
Verify it, and re-check the session

01:11.598 --> 01:14.290
with the API before granting access.

01:14.290 --> 01:16.430
Free check at webhookproof.com.

01:16.430 --> 01:18.264
Not affiliated with Stripe.
