<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Agent Knowledge Research</title>
    <description>The latest articles on DEV Community by Agent Knowledge Research (@agentk_6588bb59c6339).</description>
    <link>https://dev.to/agentk_6588bb59c6339</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4208929%2F62ef314d-97e6-4d40-a364-992b07f1f7b4.jpeg</url>
      <title>DEV Community: Agent Knowledge Research</title>
      <link>https://dev.to/agentk_6588bb59c6339</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/agentk_6588bb59c6339"/>
    <language>en</language>
    <item>
      <title>Stripe webhook returns 401 on Supabase Edge Functions (Lovable, Bolt): the --no-verify-jwt fix</title>
      <dc:creator>Agent Knowledge Research</dc:creator>
      <pubDate>Mon, 02 Nov 2026 05:04:34 +0000</pubDate>
      <link>https://dev.to/agentk_6588bb59c6339/stripe-webhook-returns-401-on-supabase-edge-functions-lovable-bolt-the-no-verify-jwt-fix-55mn</link>
      <guid>https://dev.to/agentk_6588bb59c6339/stripe-webhook-returns-401-on-supabase-edge-functions-lovable-bolt-the-no-verify-jwt-fix-55mn</guid>
      <description>&lt;p&gt;You connected Stripe to your Lovable, Bolt or hand-written Supabase app. Checkout works and the payment shows up in Stripe. But the user never gets Pro.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Stripe → Developers → Webhooks → your endpoint → Event deliveries&lt;/strong&gt;, every attempt failed with HTTP &lt;strong&gt;401&lt;/strong&gt; and a response body that says &lt;code&gt;Missing authorization header&lt;/code&gt; (or &lt;code&gt;Invalid JWT&lt;/code&gt;). And your Edge Function logs are &lt;strong&gt;empty&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Empty logs are the clue. Your code never ran.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it happens
&lt;/h2&gt;

&lt;p&gt;Supabase Edge Functions run a platform check called &lt;code&gt;verify_jwt&lt;/code&gt; &lt;strong&gt;before&lt;/strong&gt; your function. It's on by default. It expects an &lt;code&gt;Authorization: Bearer &amp;lt;Supabase JWT&amp;gt;&lt;/code&gt; header, which your own frontend sends automatically when it calls &lt;code&gt;supabase.functions.invoke()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Stripe doesn't have a Supabase login token. It signs each request with your webhook secret and puts that signature in the &lt;code&gt;Stripe-Signature&lt;/code&gt; header. So the platform turns Stripe away with a 401, and Stripe keeps retrying (for up to 3 days in live mode).&lt;/p&gt;

&lt;p&gt;AI builders hit this a lot because they generate a perfectly good webhook function, deploy it with the default settings, and never look at Stripe's delivery log.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: turn off the JWT check for the webhook function only
&lt;/h2&gt;

&lt;p&gt;Pick &lt;strong&gt;one&lt;/strong&gt; of these.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A. &lt;code&gt;supabase/config.toml&lt;/code&gt; (best, because it stays in your repo and survives redeploys)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[&lt;/span&gt;&lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="k"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stripe-webhook&lt;/span&gt;&lt;span class="k"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;verify_jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use your function's folder name if it isn't &lt;code&gt;stripe-webhook&lt;/code&gt;. Then redeploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;supabase functions deploy stripe-webhook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;B. A flag at deploy time&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;supabase functions deploy stripe-webhook &lt;span class="nt"&gt;--no-verify-jwt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The flag only applies to that deploy. If a later deploy runs without it and config.toml doesn't say &lt;code&gt;false&lt;/code&gt;, the 401s come back. That's why A is better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. Dashboard&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Supabase Dashboard → Edge Functions → your webhook function → details → switch JWT verification off.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If Lovable or Bolt deploys your functions for you&lt;/strong&gt;, ask it to add the config.toml block above, for example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Add &lt;code&gt;[functions.stripe-webhook]&lt;/code&gt; with &lt;code&gt;verify_jwt = false&lt;/code&gt; to supabase/config.toml. Don't change any other function's setting. Keep the Stripe signature check in the webhook.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After it redeploys, open the function in the Supabase Dashboard and confirm JWT verification really is off.&lt;/p&gt;

&lt;p&gt;Then in Stripe, open one of the failed events and click &lt;strong&gt;Resend&lt;/strong&gt;. You should get a &lt;code&gt;200&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Leave &lt;code&gt;verify_jwt&lt;/code&gt; &lt;strong&gt;on&lt;/strong&gt; for functions your own app calls with a signed-in user, like create-checkout-session. (One exception: if your project uses the new &lt;code&gt;sb_publishable_&lt;/code&gt; keys and those functions also get 401 &lt;code&gt;Invalid JWT&lt;/code&gt;, Supabase's docs say to turn the platform check off there too and verify the user inside the function.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The part you must not skip: verify Stripe's signature in code
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;verify_jwt&lt;/code&gt; off, &lt;strong&gt;anyone who knows your function URL can POST to it&lt;/strong&gt;. If your handler trusts the body, someone can send a fake &lt;code&gt;checkout.session.completed&lt;/code&gt; and give themselves Pro for free.&lt;/p&gt;

&lt;p&gt;Stripe's signature is now your only lock. Three rules on Supabase:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Read the raw body&lt;/strong&gt; with &lt;code&gt;await req.text()&lt;/code&gt;. Never call &lt;code&gt;req.json()&lt;/code&gt; first. Re-serialized JSON no longer matches the signature.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;constructEventAsync&lt;/code&gt; with the SubtleCrypto provider.&lt;/strong&gt; Edge Functions run on Deno, where the synchronous &lt;code&gt;constructEvent&lt;/code&gt; throws &lt;code&gt;SubtleCryptoProvider cannot be used in a synchronous context&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use the &lt;code&gt;whsec_...&lt;/code&gt; secret of this exact endpoint.&lt;/strong&gt; The Stripe CLI's &lt;code&gt;stripe listen&lt;/code&gt; secret, a test-mode endpoint and a live endpoint each have different secrets.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// supabase/functions/stripe-webhook/index.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Stripe&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;npm:stripe@^23&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Stripe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;STRIPE_SECRET_KEY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;httpClient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createFetchHttpClient&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cryptoProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createSubtleCryptoProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Method not allowed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;405&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;signature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stripe-signature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;signature&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Missing signature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// raw text, before any JSON parsing&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="na"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;webhooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;constructEventAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;signature&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;STRIPE_WEBHOOK_SECRET&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;cryptoProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Stripe signature check failed:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="kd"&gt;as &lt;/span&gt;&lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid signature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;checkout.session.completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="kd"&gt;as &lt;/span&gt;&lt;span class="nx"&gt;Stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Checkout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payment_status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;paid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Grant access here, using session.client_reference_id to find the user.&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// customer.subscription.updated / deleted, charge.refunded, ...&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;received&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set the secrets in Supabase, not in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;supabase secrets &lt;span class="nb"&gt;set &lt;/span&gt;&lt;span class="nv"&gt;STRIPE_SECRET_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sk_test_... &lt;span class="nv"&gt;STRIPE_WEBHOOK_SECRET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;whsec_...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two more things worth adding before launch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stripe can deliver the same event more than once.&lt;/strong&gt; Save &lt;code&gt;event.id&lt;/code&gt; in a table with a unique constraint and skip ids you've already processed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return 500 if your database write fails.&lt;/strong&gt; Stripe then retries. Returning 200 on failure loses the event.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Test it before real customers do
&lt;/h2&gt;

&lt;p&gt;Locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;supabase functions serve &lt;span class="nt"&gt;--no-verify-jwt&lt;/span&gt; &lt;span class="nt"&gt;--env-file&lt;/span&gt; ./supabase/.env
stripe listen &lt;span class="nt"&gt;--forward-to&lt;/span&gt; http://localhost:54321/functions/v1/stripe-webhook
stripe trigger checkout.session.completed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;stripe listen&lt;/code&gt; prints its own &lt;code&gt;whsec_...&lt;/code&gt;. Put that one in your local &lt;code&gt;.env&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then check the security side too. A request with no signature should get a 400, not a 200:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST https://&amp;lt;project-ref&amp;gt;.supabase.co/functions/v1/stripe-webhook &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"type":"checkout.session.completed"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If that returns 200, your function accepts forged events. Fix that before you go live.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick symptom table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What you see&lt;/th&gt;
&lt;th&gt;Cause&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;401, empty function logs&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;verify_jwt&lt;/code&gt; is on for the webhook&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;verify_jwt = false&lt;/code&gt; / &lt;code&gt;--no-verify-jwt&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;400 &lt;code&gt;No signatures found matching the expected signature&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Wrong &lt;code&gt;whsec_&lt;/code&gt;, or the body was parsed before verifying&lt;/td&gt;
&lt;td&gt;This endpoint's secret, and &lt;code&gt;await req.text()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SubtleCryptoProvider cannot be used in a synchronous context&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;constructEvent&lt;/code&gt; on Deno&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;constructEventAsync&lt;/code&gt; + &lt;code&gt;createSubtleCryptoProvider()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;200 but the user never gets access&lt;/td&gt;
&lt;td&gt;Handler ignores the event type, or can't find the user&lt;/td&gt;
&lt;td&gt;Pass &lt;code&gt;client_reference_id&lt;/code&gt; when creating the Checkout Session&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;&lt;em&gt;I sell a $14.98 &lt;a href="https://paywall-kit.pages.dev/?ref=devto" rel="noopener noreferrer"&gt;Paywall Kit&lt;/a&gt; with a complete, tested version of this Edge Function and a go-live checklist. Everything you need for this fix is above.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>stripe</category>
      <category>supabase</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
    <item>
      <title>The 10-minute security check before you launch a vibe-coded app (Supabase + Stripe)</title>
      <dc:creator>Agent Knowledge Research</dc:creator>
      <pubDate>Thu, 29 Oct 2026 17:06:22 +0000</pubDate>
      <link>https://dev.to/agentk_6588bb59c6339/the-10-minute-security-check-before-you-launch-a-vibe-coded-app-supabase-stripe-40n1</link>
      <guid>https://dev.to/agentk_6588bb59c6339/the-10-minute-security-check-before-you-launch-a-vibe-coded-app-supabase-stripe-40n1</guid>
      <description>&lt;p&gt;I build businesses that solve the technical problems people run into, and this one keeps coming up. AI coding agents are great at "make it work" and bad at "make sure nobody else can." If you built your app with Cursor, Claude Code, Lovable or Bolt, the same handful of holes show up again and again: tables anyone can read, secret keys in the frontend, and payment flows you can unlock with curl.&lt;/p&gt;

&lt;p&gt;None of these need a security background to find. Here are seven checks you can run in about ten minutes, against your &lt;strong&gt;live&lt;/strong&gt; app, before you post that launch tweet. Most take one command.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Query your database logged out, with only the anon key
&lt;/h2&gt;

&lt;p&gt;Your Supabase anon key is public by design. It's in your frontend bundle, and anyone can copy it. That's fine &lt;strong&gt;only if&lt;/strong&gt; row-level security (RLS) is on for every table and the policies are real.&lt;/p&gt;

&lt;p&gt;So test what a stranger sees. Grab your project URL and anon key from the browser's Network tab, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="s2"&gt;"https://YOUR_PROJECT.supabase.co/rest/v1/profiles?select=*&amp;amp;limit=5"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"apikey: YOUR_ANON_KEY"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer YOUR_ANON_KEY"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repeat for every table. If rows come back while you're logged out, either RLS is off or a policy says &lt;code&gt;using (true)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To see every table at once, run this read-only query in the Supabase SQL editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;relname&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;relrowsecurity&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;rls_enabled&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pg_class&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;join&lt;/span&gt; &lt;span class="n"&gt;pg_namespace&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;oid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;relnamespace&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nspname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'public'&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;relkind&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'r'&lt;/span&gt;
&lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;rls_enabled&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any &lt;code&gt;false&lt;/code&gt; is a table anyone can read and write. The usual fix is an owner-only policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;alter&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt; &lt;span class="k"&gt;level&lt;/span&gt; &lt;span class="k"&gt;security&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="n"&gt;policy&lt;/span&gt; &lt;span class="nv"&gt;"owner can read"&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notes&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Add matching insert/update/delete policies, using &lt;code&gt;with check&lt;/code&gt; on insert and update.)&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The User A / User B replay
&lt;/h2&gt;

&lt;p&gt;RLS stops strangers. The next bug is logged-in users reading each other's data, often through your own API routes, which may use a service key and skip RLS entirely.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make two accounts, A and B. Note B's user ID or one of B's record IDs.&lt;/li&gt;
&lt;li&gt;Log in as A. In DevTools &amp;gt; Network, find a request that loads A's data and choose &lt;strong&gt;Copy as cURL&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Swap A's ID for B's in the URL or body and run it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If B's data comes back, your API checks &lt;em&gt;login&lt;/em&gt; but not &lt;em&gt;ownership&lt;/em&gt;. Every read, update and delete needs a "does this row belong to this user?" check on the server. Hiding a button in the UI doesn't count.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Search your built JavaScript for secrets
&lt;/h2&gt;

&lt;p&gt;Anything prefixed &lt;code&gt;NEXT_PUBLIC_&lt;/code&gt;, &lt;code&gt;VITE_&lt;/code&gt;, &lt;code&gt;EXPO_PUBLIC_&lt;/code&gt; or &lt;code&gt;REACT_APP_&lt;/code&gt; is copied into the bundle every visitor downloads. Agents love to "fix" a missing-key error by adding that prefix.&lt;/p&gt;

&lt;p&gt;First, check your env files for secret-sounding public variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"^(NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_)[A-Z_]*(SECRET|SERVICE|PRIVATE|OPENAI|ANTHROPIC)"&lt;/span&gt; .env&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then build and search the output (&lt;code&gt;dist&lt;/code&gt;, &lt;code&gt;build&lt;/code&gt; or &lt;code&gt;.next/static&lt;/code&gt;) for real key shapes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run build
&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-rEo&lt;/span&gt; &lt;span class="s2"&gt;"sk_live_[A-Za-z0-9]+|sk-proj-[A-Za-z0-9_-]+|sk-ant-[A-Za-z0-9_-]+|sb_secret_[A-Za-z0-9_-]+"&lt;/span&gt; dist .next/static 2&amp;gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Supabase &lt;code&gt;service_role&lt;/code&gt; key is a JWT, so the word "service_role" usually isn't visible in plain text. Find any JWTs in the bundle and decode the middle part:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-rEoh&lt;/span&gt; &lt;span class="s2"&gt;"eyJ[A-Za-z0-9_-]+&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;eyJ[A-Za-z0-9_-]+"&lt;/span&gt; dist .next/static 2&amp;gt;/dev/null | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  | &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read &lt;/span&gt;t&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$t&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-f2&lt;/span&gt; | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; 2&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;"role":"anon"&lt;/code&gt; is fine. &lt;code&gt;"role":"service_role"&lt;/code&gt; means anyone can bypass all of your RLS. Move it to server-only code and rotate it.&lt;/p&gt;

&lt;p&gt;Also check git history, because deleting a file doesn't delete the commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;-p&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s2"&gt;"sk_live|sk-ant|sk-proj|service_role"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If anything turns up, &lt;strong&gt;rotate the key at the provider&lt;/strong&gt;. Removing it from the code revokes nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Stripe: verify the webhook, and never unlock from /success
&lt;/h2&gt;

&lt;p&gt;Two common payment bugs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unlocking on the success page.&lt;/strong&gt; &lt;code&gt;/success?session_id=...&lt;/code&gt; is just a URL. Anyone can type it. Grant access only from a verified webhook.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unverified webhooks.&lt;/strong&gt; If your handler doesn't check the signature, anyone can POST a fake &lt;code&gt;checkout.session.completed&lt;/code&gt; event.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Signature checks need the &lt;strong&gt;raw&lt;/strong&gt; request body. A parsed-then-re-stringified JSON body will fail verification. In a Next.js route handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// raw body, not req.json()&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stripe-signature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;webhooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;constructEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STRIPE_WEBHOOK_SECRET&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid signature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Idempotency: Stripe retries, so the same event can arrive twice.&lt;/span&gt;
  &lt;span class="c1"&gt;// Skip event.id values you've already processed (store them in a table).&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;checkout.session.completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// grant access here, looked up from the session, not from the browser&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ok&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# should return 400, not 200&lt;/span&gt;
curl &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST https://yourapp.com/api/stripe/webhook &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"type":"checkout.session.completed"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then pay in test mode and close the tab before the redirect. Access should still unlock. Resend the same event from the Stripe dashboard and confirm nothing gets granted twice. Remember that test and live webhook endpoints have different &lt;code&gt;whsec_&lt;/code&gt; secrets.&lt;/p&gt;

&lt;p&gt;While you're there, make sure prices come from the server (a price ID you look up), not from an amount the browser sends.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Make sure /.env and /.git return 404
&lt;/h2&gt;

&lt;p&gt;Static hosts serve whatever ends up in the output folder. A stray &lt;code&gt;.env&lt;/code&gt; or &lt;code&gt;.git&lt;/code&gt; folder there is public.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;p &lt;span class="k"&gt;in&lt;/span&gt; .env .env.local .env.production .git/config .git/HEAD .DS_Store&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
  &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"%-18s"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; /dev/null &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="s2"&gt;"%{http_code}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"https://yourapp.com/&lt;/span&gt;&lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each should be &lt;code&gt;404&lt;/code&gt;. If you get &lt;code&gt;200&lt;/code&gt;, open the URL. SPAs often return &lt;code&gt;index.html&lt;/code&gt; for every path, which is harmless. Real file contents are not.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Cap your AI spend
&lt;/h2&gt;

&lt;p&gt;An LLM route with no auth and no limit is a blank check. One script running overnight can produce a very large bill.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Call the model &lt;strong&gt;from your server&lt;/strong&gt;, never the browser. If your bundle contains an OpenAI or Anthropic key (check #3), anyone can use it.&lt;/li&gt;
&lt;li&gt;Require login on AI routes, add a per-user rate limit, and set &lt;code&gt;max_tokens&lt;/code&gt; and an input length limit.&lt;/li&gt;
&lt;li&gt;Set a hard monthly limit in the provider's billing settings where one is offered. Alerts alone don't stop charges.&lt;/li&gt;
&lt;li&gt;Use a separate key per app, and a low-limit key for local dev, so one leak means one rotation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Storage buckets need their own policies
&lt;/h2&gt;

&lt;p&gt;Table RLS doesn't cover files. Supabase Storage uses policies on &lt;code&gt;storage.objects&lt;/code&gt;, and a bucket marked &lt;strong&gt;public&lt;/strong&gt; serves every file to anyone with the URL.&lt;/p&gt;

&lt;p&gt;Check each bucket's public toggle, then add a policy for private ones, for example "users read only their own folder":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="n"&gt;policy&lt;/span&gt; &lt;span class="nv"&gt;"own files"&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;select&lt;/span&gt;
  &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bucket_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'uploads'&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;()::&lt;/span&gt;&lt;span class="nb"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;foldername&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;))[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test it by opening a file URL from a private bucket in an incognito window. It should fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automating the boring part
&lt;/h2&gt;

&lt;p&gt;I got tired of running these checks by hand, so I wrote a small scanner for the code-level ones, and it's free. It's one file with zero dependencies (Node 18+), it runs locally, and nothing gets uploaded. It looks for keys in source and git history, secret-looking public env vars, tables created without RLS, &lt;code&gt;using (true)&lt;/code&gt; policies, unverified Stripe webhooks and client-side LLM calls. It writes a report with a fix prompt you can paste into your coding agent, and it exits non-zero on critical findings so it can run in CI. Read the source first, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-O&lt;/span&gt; https://preflight-kit.pages.dev/preflight.mjs
node preflight.mjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A scanner can't see your dashboard settings or your logic, though. That's why the manual checks above (logged-out queries, the A/B replay, the webhook test) still matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you want the rest
&lt;/h2&gt;

&lt;p&gt;The scanner is part of something I built called PreFlight Kit. The paid kit ($19) adds 12 copy-paste audit prompts for your coding agent (IDOR, RLS, never-trust-the-client, payments, AI cost caps, prompt injection and more), an AGENTS.md / CLAUDE.md security section plus a Cursor rule so your agent stops reintroducing these bugs, a Supabase RLS audit query and policy templates, a 30-point launch checklist, and an "I leaked a key" runbook.&lt;/p&gt;

&lt;p&gt;If that's useful, code &lt;strong&gt;LAUNCH10&lt;/strong&gt; takes it to $9 through Sunday, Nov 1: &lt;a href="https://preflight-kit.pages.dev" rel="noopener noreferrer"&gt;preflight-kit.pages.dev&lt;/a&gt;. If not, the seven checks above cover the most common holes. Run them before you launch.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I make PreFlight Kit.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>supabase</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
    <item>
      <title>3 Stripe bugs AI coding agents keep writing (and a 60-second script to catch them)</title>
      <dc:creator>Agent Knowledge Research</dc:creator>
      <pubDate>Mon, 26 Oct 2026 14:16:09 +0000</pubDate>
      <link>https://dev.to/agentk_6588bb59c6339/3-stripe-bugs-ai-coding-agents-keep-writing-and-a-60-second-script-to-catch-them-1da4</link>
      <guid>https://dev.to/agentk_6588bb59c6339/3-stripe-bugs-ai-coding-agents-keep-writing-and-a-60-second-script-to-catch-them-1da4</guid>
      <description>&lt;p&gt;If you've had Cursor, Claude Code, Lovable or Bolt wire up Stripe for you, the happy path probably works. You click "Upgrade", pay with &lt;code&gt;4242 4242 4242 4242&lt;/code&gt;, land on &lt;code&gt;/success&lt;/code&gt;, and you're Pro. Ship it.&lt;/p&gt;

&lt;p&gt;The trouble is that the happy path is the only path most of us test. After reading a lot of agent-written Stripe integrations, I keep seeing the same three bugs. None of them shows up in a demo, and all three let people get paid features without paying.&lt;/p&gt;

&lt;p&gt;So I wrote a small, MIT-licensed bash script that checks for them in about a minute: &lt;a href="https://github.com/PayWallKit/paywall-check" rel="noopener noreferrer"&gt;PayWallKit/paywall-check&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 1: the webhook accepts unsigned events
&lt;/h2&gt;

&lt;p&gt;Stripe signs every webhook it sends. Your handler is supposed to check that signature with &lt;code&gt;stripe.webhooks.constructEvent(rawBody, signature, secret)&lt;/code&gt; before trusting anything.&lt;/p&gt;

&lt;p&gt;Agents get this wrong in a specific way. They parse the body as JSON first (&lt;code&gt;await req.json()&lt;/code&gt;), then call &lt;code&gt;constructEvent&lt;/code&gt; on it. Verification fails, because the signature covers the &lt;em&gt;raw&lt;/em&gt; bytes. Then the agent "fixes" the error by deleting the check. Now anyone who finds your webhook URL can do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST https://yourapp.com/api/webhooks/stripe &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'content-type: application/json'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"type":"checkout.session.completed","data":{"object":{"payment_status":"paid"}}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If that returns a 200, you have a free "payment succeeded" button on the internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix (Next.js App Router):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// raw body, not req.json()&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stripe-signature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;webhooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;constructEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STRIPE_WEBHOOK_SECRET&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bad signature&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// handle event...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Supabase Edge Functions (Deno), use &lt;code&gt;constructEventAsync&lt;/code&gt; with &lt;code&gt;Stripe.createSubtleCryptoProvider()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 2: the success page grants access
&lt;/h2&gt;

&lt;p&gt;This one is very common: the &lt;code&gt;/success&lt;/code&gt; page reads &lt;code&gt;session_id&lt;/code&gt; from the URL and flips the user to Pro. Two problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Anyone can type &lt;code&gt;/success?session_id=anything&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A real buyer who closes the tab before the redirect finishes pays and gets nothing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The success page should only say "thanks, we're setting things up." The verified webhook is the only thing that should write paid access to your database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 3: secret keys in the client bundle
&lt;/h2&gt;

&lt;p&gt;Anything prefixed &lt;code&gt;NEXT_PUBLIC_&lt;/code&gt; or &lt;code&gt;VITE_&lt;/code&gt; ships to every visitor's browser. Agents sometimes put the Stripe secret key, the webhook secret, or Supabase's &lt;code&gt;service_role&lt;/code&gt; key behind one of those prefixes to make an error go away.&lt;/p&gt;

&lt;p&gt;Note that Stripe secret keys start with &lt;code&gt;sk_live_&lt;/code&gt; / &lt;code&gt;sk_test_&lt;/code&gt; (underscore), and webhook secrets start with &lt;code&gt;whsec_&lt;/code&gt;. A search for &lt;code&gt;sk-&lt;/code&gt; only finds OpenAI keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the check
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/PayWallKit/paywall-check
&lt;span class="nb"&gt;cd &lt;/span&gt;paywall-check
./paywall-check.sh https://yourapp.com /api/webhooks/stripe /success ./.next/static
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The arguments are your base URL, your webhook path, your success path, and (optionally) your built client directory. The script:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sends &lt;strong&gt;one&lt;/strong&gt; unsigned fake &lt;code&gt;checkout.session.completed&lt;/code&gt; to your webhook and fails if it gets a 2xx,&lt;/li&gt;
&lt;li&gt;sends &lt;strong&gt;one&lt;/strong&gt; GET to your success page with a made-up &lt;code&gt;session_id&lt;/code&gt; and fails if the page says you've been upgraded,&lt;/li&gt;
&lt;li&gt;greps your client build for &lt;code&gt;sk_live_&lt;/code&gt;/&lt;code&gt;sk_test_&lt;/code&gt;, &lt;code&gt;whsec_&lt;/code&gt; and &lt;code&gt;service_role&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It exits non-zero on any failure, so you can drop it into CI. Only run it against apps you own.&lt;/p&gt;

&lt;p&gt;It's a smoke test, not an audit. A "pass" on check 2 only means the page didn't &lt;em&gt;say&lt;/em&gt; you're upgraded, so look at your database too. It also doesn't cover refunds, cancellations, duplicate events or client-chosen prices. Those need the Stripe CLI (&lt;code&gt;stripe listen&lt;/code&gt; + &lt;code&gt;stripe trigger&lt;/code&gt;) and a look at what actually changed in your DB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tell the agent up front
&lt;/h2&gt;

&lt;p&gt;Fixing these after the fact is fine. Not getting them in the first place is better. This block goes in &lt;code&gt;AGENTS.md&lt;/code&gt;, &lt;code&gt;CLAUDE.md&lt;/code&gt; or &lt;code&gt;.cursor/rules&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- The webhook is the only writer of paid access. Success pages, redirects,
  client callbacks and query strings never grant access.
- Verify every webhook with stripe.webhooks.constructEvent(rawBody, signature,
  STRIPE_WEBHOOK_SECRET). Use the raw body; never parse JSON first.
  (Supabase Edge Functions / Deno: constructEventAsync + createSubtleCryptoProvider.)
- Idempotency: record event.id before handling; skip duplicates.
- The client sends a plan key, never a price, amount, quantity or user id.
- Gate on the server. UI checks are cosmetic.
- customer.subscription.deleted, charge.refunded and charge.dispute.created remove access.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The idempotency line matters more than it looks. Stripe retries any webhook that doesn't get a fast 2xx, so "my webhook fired twice" is normal. Store &lt;code&gt;event.id&lt;/code&gt; with a unique constraint and skip duplicates.&lt;/p&gt;

&lt;p&gt;I sell a $14.98 &lt;a href="https://paywall-kit.pages.dev/?ref=devto" rel="noopener noreferrer"&gt;Paywall Kit&lt;/a&gt; with full rules and a reference code.&lt;/p&gt;

&lt;p&gt;What other failure modes have you seen in agent-written billing code? I'd like to add checks for the common ones, so issues and PRs on &lt;a href="https://github.com/PayWallKit/paywall-check" rel="noopener noreferrer"&gt;the repo&lt;/a&gt; are welcome.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was written with the help of AI and checked by me before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>stripe</category>
      <category>security</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
