Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

I built a SaaS with Lovable in one prompt, then audited it like a paying client would

Most "AI-built apps are insecure" posts are based on 2025 data: RLS switched off, service-role keys in the browser, unsigned Stripe webhooks. I wanted to know if that's still true, so I tested it. The setup

Most "AI-built apps are insecure" posts are based on 2025 data: RLS switched off, service-role keys in the browser, unsigned Stripe webhooks. I wanted to know if that's still true, so I tested it.

The setup

  • Lovable free plan, one prompt, about 3.5 credits.
  • The app: ClientNest, a small invoicing SaaS for freelancers. It has email/password login, clients and invoices (each user sees only their own), a free plan capped at 3 clients, a $9/month Pro plan via Stripe, an /admin page, and an AI button that drafts payment reminder emails.
  • Stack Lovable picked: TanStack Start (server functions + server routes), Lovable Cloud (Supabase), Drizzle SQL migrations, Stripe through its REST API, Lovable's AI gateway.

Then I ran the same static review I do for clients: scanners first (my own heuristics, semgrep, gitleaks, trufflehog, osv-scanner), then reading every flagged file and walking a 7-area checklist.

What Lovable got right

  • Row Level Security on every table, with a separate policy per operation tied to auth.uid(). The invoice insert/update policies even check that the client row belongs to the same user.
  • The plan flag can't be faked. plan lives in a subscriptions table that users can only read; only the server-side webhook writes it.
  • Admins can't self-appoint. Roles live in a separate user_roles table with no insert policy for users, and the admin list is checked on the server.
  • The Stripe webhook verifies signatures correctly: HMAC-SHA256 over the raw body, constant-time compare, 5-minute timestamp tolerance.
  • Secrets stay server-side: the service-role key, the Stripe secret key and all AI calls.

The scanner was wrong

My first automated pass scored the app 0/100 with six "critical" alerts. All six were false alarms. Five came from a rule that expected stripe.webhooks.constructEvent() and didn't recognise a hand-written HMAC check, and it fired once per mention of "stripe". The sixth flagged a committed .env that only holds public values (Supabase URL and publishable key), which Lovable commits by default.

Meanwhile, the scanner missed both real problems. A scan is a set of leads, not a verdict.

What was actually wrong: money

1. Uncapped AI spend (Medium). The reminder feature is a createServerFn behind auth middleware, which is good. But any signed-in user can call it as often as they like, with no per-user quota. One script on a free account can drain your AI budget.

export const draftReminder = createServerFn({ method: "POST" })
  .middleware([requireSupabaseAuth])
  .inputValidator(/* invoiceId */)
  .handler(async ({ data, context }) => {
    // ...loads the invoice, then calls the model. No quota check.
  });

Fix: an ai_usage(user_id, day, count) table, incremented in the same call, refusing over a limit (for example 20/day free, 200/day Pro), plus a spend alert.

2. Failed payments keep Pro (Medium). The webhook upgrades on checkout.session.completed and downgrades only on customer.subscription.deleted. When a card fails, Stripe marks the subscription past_due/unpaid and retries for days or weeks before deleting it. The whole time the user keeps Pro for free, and your database says they're paying.

Fix: handle customer.subscription.updated and keep plan = 'pro' only while the status is active or trialing.

Smaller ones (Low):

  • Parallel requests can beat the 3-client limit, because the trigger counts and then inserts without a lock (pg_advisory_xact_lock fixes it).
  • A Pro user can start a second checkout and get charged twice.
  • Webhook events aren't de-duplicated.
  • There's no error tracking or spend alerting.

Final score after manual verification: 81/100: 0 critical, 0 high, 3 medium, 7 low.

Takeaways if you're shipping on Lovable

  1. Your RLS is probably fine now, but check it table by table anyway: Lovable Cloud → Database → Policies.
  2. List every place your app spends money on your behalf (AI, email, SMS) and ask what stops one user from calling it 10,000 times.
  3. List which Stripe events change a user's plan. If it's only "checkout completed" and "subscription deleted", failed payments are a hole.
  4. Don't trust raw scanner output, mine included. Someone has to read the code behind every "critical".

The full, unedited report, with file names and line numbers, is here: https://chinh-launch-audit.netlify.app/sample-report.html

I do fixed-price launch-readiness reviews for AI-built apps. If you're about to launch something on Lovable, Bolt or Cursor and want a second pair of eyes, I'm doing a few free quick looks this week (read-only repo access, the 2 biggest risks by email, no call): https://chinh-launch-audit.netlify.app/intake.html?plan=quick

I used AI tools (Claude) to help run the review and draft this post; every finding was verified by reading the code.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.