LAST MILE RULES (free starter v2.0): launch-security rules for this app.
Where to paste: Lovable → Project settings → Knowledge. Bolt → Knowledge (Bolt also reads an AGENTS.md in the project root). v0 → + in the prompt bar → Instructions → New Instruction, then keep it checked. Replit → add to replit.md in the project root. Any other tool: paste at the top of your first message.

This app will hold real user data or take real money. Follow these rules on every change.

HOW TO WORK
- Before changing code, tell me which rules (LM-01 to LM-10) the change touches.
- Make small changes. Don't touch files I didn't ask about. Don't add packages, secrets or services without asking.
- When you finish, tell me exactly how to check the change worked (the "Check" line of each rule). Never say "this is secure". Say what passed and what I still need to check.

LM-01 SECRETS STAY ON THE SERVER. Only publishable keys go in browser code (Supabase anon or sb_publishable_ key, Stripe pk_ key). Never put sk_live_, sk_test_, whsec_, sb_secret_, the Supabase service_role key, a database URL or an AI provider key in browser code or in a NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_, PUBLIC_ or REACT_APP_ variable. Use them only in server code or edge functions.
Check: run your live URL through the free scanner (https://last-mile-kit.vercel.app/check?src=pastein). No secret-key or service_role findings. It decodes Supabase keys, so it catches a service_role key that plain search misses.

LM-02 ROW LEVEL SECURITY ON EVERY TABLE. Every Supabase table in public has RLS on. Every policy checks ownership, like (select auth.uid()) = user_id. No "using (true)" or "with check (true)" for insert, update or delete. Views over private tables use security_invoker = true. Storage buckets have policies too.
Check: Supabase → Database → Security Advisor shows no RLS warnings.

LM-03 SUPABASE GRANTS (from Oct 30, 2026). New tables in public are no longer granted to anon, authenticated and service_role automatically. Every new table gets, in the same migration: grants for only the roles that need it, RLS enabled, and policies. If you see error 42501 "permission denied for table", add the missing grant for that table and role. Never disable RLS, never grant to anon "to make it work", never run "grant all on all tables".
Check: the feature works when logged in and is blocked when logged out.

LM-04 STRIPE WEBHOOKS ARE SIGNED AND IDEMPOTENT. Verify every Stripe webhook signature with the raw request body and the webhook secret before doing anything. Return 400 if it fails. Give or remove access only from verified webhook events, never from the success page. Save each event ID and skip repeats.
Check: sending a fake unsigned POST to the webhook URL returns 400 and unlocks nothing.

LM-05 PRICES COME FROM THE SERVER. The browser sends a plan ID. The server picks the Stripe price. Never accept an amount, price or discount from the browser. Create checkout sessions only on the server.
Check: the Stripe checkout page always shows the real price, even if the request is edited.

LM-06 OWNERSHIP CHECKS. Any server code that uses the service_role or sb_secret_ key skips RLS, so it must filter by the logged-in user's ID from the session, never an ID sent by the browser. Return 404 when the record isn't theirs.
Check: with two accounts, open user A's record URL while logged in as user B. You get "not found", never A's data.

LM-07 PROTECTED FILES NEED ME. Before changing anything about login/auth, payments, webhooks, database tables or policies, environment variables or these rules: stop, explain the change in plain words, and wait for my yes. Never show secret values. Never weaken a check to make an error go away.
Check: ask for a small change to the login code. You should stop and ask first.

LM-08 NOTHING PRIVATE IS SERVED. No .env, .git, backups or database dumps in public folders or the build. No browser source maps in production builds. Remove test and debug pages before launch.
Check: visiting yoursite.com/.env and yoursite.com/.git/config shows a 404 page, not a file. The free scanner checks these and source maps for you.

LM-09 EVERY ROUTE CHECKS LOGIN ON THE SERVER. Every API route, server function and edge function that touches private data checks the session on the server. Hiding a button is not security. Roles and plans live in a server-side table or app_metadata, never user_metadata, because users can edit their own user_metadata.
Check: logged out, opening a private API URL returns an error, not data.

LM-10 PAID ENDPOINTS HAVE LIMITS. Anything that calls a paid API (AI, email, SMS, maps) requires login, has a per-user rate limit, and caps input size and max_tokens. Remind me to set a spend limit in each provider's dashboard.
Check: spamming the AI feature quickly hits a "too many requests" message.

Full pack (100 checks as rules, security headers per host, a retest routine after every AI edit): https://skotbot.gumroad.com/l/yrpthn?src=pastein
Free scanner: https://last-mile-kit.vercel.app/check?src=pastein
