Patient chart
Billirubin
Invoicing for freelancers. Fictional app, realistic findings.
- Stack
- Next.js App Router, TypeScript, Supabase, Stripe
- Built with
- Lovable, then Cursor
- Size
- 8,900 lines
- Review
- Second Opinion
- Diagnosis
- Not ready for real users yet. Fix the two critical problems before anyone else signs up.
Diagnosis
Slop Medic
- Patient
- Billirubin (fictional)
- Size
- 8,900 lines
Risk score61
| Problem | Urgency |
|---|---|
| Any user can read every invoice | Critical |
| Payments can be faked | Critical |
| Forms accept anything | High |
| Failed payments go unnoticed | Medium |
| An outdated login package | Medium |
Risk score: 0 is no known risk, 100 is not safe to use. A Second Opinion lists the five problems to fix first.
Red: fix these first.
How this review was made
- Your scan
- Lovable’s quick scan, pasted at booking: 4 findings. Each one checked in the code and on the live app; see "What your scan found".
- Software
- Automated checks for leaked keys, vulnerable and made-up packages and common security patterns, plus an AI search over the whole codebase for me to go through.
- Human
- I read the app first: what it is for, how invoices and payments flow, the routes and the database rules. Then every candidate that could put data, money or users at risk checked in the code. False alarms removed. The five most urgent made the report, four of them not on your scan’s list.
- Proof
- Both critical problems confirmed on the live app with two test accounts. No real user data was changed.
What your scan found
Lovable’s quick scan, pasted at booking. Each item checked in the code and on the live app. Anything listed here does not count toward the refund guarantee.
Your scanTable invoices: policy allows access to all rows (using (true))
My verdictConfirmed, critical: problem 1 below. The scan could not know that invoice_items and customers have the same hole; the fix covers all three.
Your scanTable products: row level security disabled
My verdictReal, but low for Billirubin: the table holds your public price list and nothing personal. Turn it on when you next touch the migrations; no rush.
Your scan2 packages with known vulnerabilities
My verdictReal but not urgent: both run only in your build step and never see user input. Update them when convenient.
Your scanStorage bucket logos is public
My verdictFine as it is: it holds company logos that appear on public invoice pages anyway.
Not on the scan’s list: the Stripe webhook (problem 2), the invoice form (problem 3) and the swallowed payment error (problem 4). Those are what a quick scan does not look for in an invoicing app.
Summary
Billirubin works, and the invoicing logic itself is better than most AI-built apps I see. It is not ready for more customers yet.
Your Lovable scan flagged the open invoices table, and it was right. It could not know that the same hole runs through invoice_items and customers, that the Stripe webhook believes anyone or that a failed payment update is silently ignored. Those are the problems that matter for an invoicing app. Fix the two critical ones first, then the other three. All five are small, contained fixes. When they are done, reply to my email and I check them again for free.
The five problems to fix first
Any signed-in user can read and edit every invoice
supabase/migrations/0004_invoices.sql:18Your own scan reported this tooThe select and update policies on invoices allow every row. Your publishable key (the anon key, in older projects) is public by design, so anyone with an account can list all invoices of all customers from the browser console, including names, addresses and amounts.
Proven on the live app: I signed up two test accounts. From the browser console, account B listed every invoice of account A, including the customer address. Screenshot in the full report.
create policy "Invoices are readable"
on invoices for select to authenticated
Removed: using (true);
Added: using (auth.uid() = owner_id);
Treatment: Restrict select, update and delete to the owner. Make inserts and updates check that the new row belongs to the user too. Then repeat for invoice_items and customers. Takes about an hour including a test with two accounts.
In supabase/migrations, add a new migration that replaces the policies on invoices, invoice_items and customers: select, update and delete only allow rows where owner_id = auth.uid() (using), and insert and update only accept rows where owner_id = auth.uid() (with check), so nobody can create or move a row into another user’s account. For invoice_items, check ownership through the parent invoice. Do not change any application code. List every policy you changed.
Signed
The Stripe webhook believes anyone
app/api/webhooks/stripe/route.ts:4The webhook parses the request body without checking Stripe’s signature. Anyone who finds the URL can send a fake checkout.session.completed event and mark any invoice as paid.
Proven on the live app: A hand-written request to the webhook URL marked one of my test invoices as paid. No money changed hands. Request and screenshot in the full report.
export async function POST(req: Request) {
Removed: const event = await req.json()
Added: const signature = req.headers.get('stripe-signature') ?? ''
Added: const event = stripe.webhooks.constructEvent(
Added: await req.text(), signature, env.STRIPE_WEBHOOK_SECRET
Added: )
if (event.type === 'checkout.session.completed') {
Treatment: Verify the signature with the raw body and your webhook secret, and return 400 when it fails.
In app/api/webhooks/stripe/route.ts, verify the Stripe signature before handling any event: read the raw body with req.text(), call stripe.webhooks.constructEvent with the stripe-signature header and STRIPE_WEBHOOK_SECRET. Return a 400 response if verification throws. Keep the existing event handling unchanged.
Signed
Creating an invoice trusts the whole request
app/invoices/actions.ts:12The server action inserts whatever object the form sends. A user can set owner_id to someone else, or create an invoice that is already marked as paid.
'use server'
Removed: export async function createInvoice(data: any) {
Removed: return supabase.from('invoices').insert(data)
Added: export async function createInvoice(input: unknown) {
Added: const { customerId, lines } = InvoiceInput.parse(input)
Added: const user = await requireUser()
Added: return supabase.from('invoices').insert({
Added: customer_id: customerId, lines, owner_id: user.id, status: 'draft'
Added: })
}
Treatment: Validate the input with a schema and set owner and status on the server. The same pattern applies to updateInvoice and createCustomer.
In app/invoices/actions.ts, change createInvoice to accept unknown, parse it with a zod schema that only allows customerId and lines, get the user from the session and insert owner_id = user.id and status = 'draft' on the server. Apply the same pattern to updateInvoice and createCustomer. Add the schemas to lib/validation.ts.
Signed
A failed payment update is silently ignored
app/api/webhooks/stripe/route.ts:31When marking an invoice as paid fails, the error is caught and thrown away, and Stripe is told everything went fine. Your customer has paid, the invoice still says unpaid and nobody finds out. The code swallows errors in 12 places; this is the one that touches money.
Treatment: Log the error and return a 500 response, so Stripe tries again and the failure shows up in your Stripe dashboard.
In app/api/webhooks/stripe/route.ts, find the try/catch around the update that marks an invoice as paid. In the catch block, log the error together with the Stripe event id and return a 500 response instead of 200, so Stripe retries the event. Do not change anything else in the file.
Signed
A deprecated auth package
package.json@supabase/auth-helpers-nextjs is deprecated and no longer supported. Fixes and security updates go to its replacement, @supabase/ssr, so a future problem in the old package will never be patched.
Treatment: Move to @supabase/ssr. The change is limited to the files that create the Supabase client and the middleware.
Replace @supabase/auth-helpers-nextjs with @supabase/ssr, following the official Supabase guide for the Next.js App Router. Only change the files that create the Supabase client and the middleware, keep the same session cookie behaviour and remove the old package from package.json. List every file you changed.
Signed
Discharge instructions for your AI
Paste these into your Lovable knowledge, Cursor rules or CLAUDE.md so the next session doesn’t bring the same problems back.
- Every server action and route handler validates its input with a schema from lib/validation.ts.
- Never use the secret key (the service role key, in older projects) outside supabase/functions.
- Every new table gets row level security and an owner policy in the same migration.
- No new dependencies without asking first.After the report
What comes next, and what you can ask for.
- One round of questions by email: send them all within 7 days of the report.
- A free follow-up check within 30 days, once the five problems are fixed.
- Rather I did the fixing? Problems 1 to 3 as a fix list: $199, $100 and $199, pull requests you merge, re-checked on your live app, with the start date before you pay. The Second Opinion’s price counts toward it, so $199 in total. Reply with the ones you want.
- Another look later: Aftercare, $249 for one check of what your AI changed, with who-sees-what and payments re-tested. Paid once, never a subscription.
- Or the price counts toward a Launch Review for Billirubin within 30 days.
That is the whole Second Opinion: five problems, each with a prescription. Want every problem, not just the top five? That is the Launch Review, and the Second Opinion’s price counts toward it within 30 days. Book a Second Opinion to get one for your app.