List every table the anonymous role can reach and turn RLS on
Find tables in the exposed schema without RLS, enable it, then revoke the default grants and grant back only what each role needs. With RLS on and no policies, the API returns no data until you create them. That is the safe starting point.
select schemaname, tablename
from pg_tables
where schemaname = 'public' and not rowsecurity;
alter table public.orders enable row level security;
revoke all on table public.orders from anon, authenticated;
grant select, insert on table public.orders to authenticated;
create policy "own rows" on public.orders
for select to authenticated
using ( auth.uid() = user_id );
Test every table as two different users
Switch identity inside a transaction and confirm user A sees none of user B's rows. A using filter that matches nothing raises no error, so assert an empty result instead of expecting an exception. Keep these tests in CI (Supabase documents pgTAP files run with supabase test db).
begin;
set local role authenticated;
set local request.jwt.claim.sub = '<user-a-uuid>';
select count(*) from public.orders
where user_id = '<user-b-uuid>'; -- expect 0
rollback;
Make the webhook handler verify, acknowledge, then work
Read the raw body, verify the Stripe-Signature header with the endpoint's own whsec_ secret, return a 2xx quickly and do the slow work afterwards. Record processed event ids, because Stripe can deliver the same event twice and does not guarantee order.
export async function POST(req: Request) {
const body = await req.text(); // raw, not req.json()
const sig = req.headers.get("stripe-signature")!;
const event = stripe.webhooks.constructEvent(
body, sig, process.env.STRIPE_WEBHOOK_SECRET!
);
// skip if event.id was already stored, else enqueue the work
return new Response(null, { status: 200 });
}
Read the delivery log, fix the status code, replay what was missed
In Workbench, open the endpoint's Event deliveries tab to see Delivered, Pending or Failed and the HTTP status of each attempt. After fixing the cause, list undelivered events (Stripe returns events from the last 30 days) and resend them. The CLI can resend events up to 30 days old, the dashboard up to 15.
curl -G https://api.stripe.com/v1/events \
-u "$STRIPE_SECRET_KEY:" \
-d "types[]=checkout.session.completed" \
-d delivery_success=false
stripe events resend evt_123 --webhook-endpoint=we_123
Send one real email through the production path
Use your own provider with a verified sending domain and SPF or DKIM records, not the platform default. From the production host, check that the SMTP port you use is not blocked (see the host's docs). If the host restricts SMTP, use your provider's HTTP API. Raise any low default send cap before launch.
Handle bounces, suppression and unsubscribe headers
Open a bounced message in your provider to see its type. Resend, for example, separates permanent, transient and undetermined bounces, and lets you remove an address from its suppression list. Stop sending to permanent bounces. Google requires senders of 5,000 or more messages a day to authenticate with SPF, DKIM and DMARC. It also requires marketing and subscribed messages to support one-click unsubscribe with the List-Unsubscribe and List-Unsubscribe-Post headers. Keep promotional content out of receipts and codes.
List-Unsubscribe-Post: List-Unsubscribe=One-Click
List-Unsubscribe: <https://example.com/unsubscribe/abc123>
Alert on silence, and stop swallowing errors
When a handler cannot record a payment, return a non-2xx status so Stripe retries it. Alert on failed webhook deliveries, email send errors and bounce rates. Log refused access attempts and alert on repeats.