Case file 001 · Folioport · 11 findings · 0 open · retested 22 Nov 2026

I broke into a Lovable-built invoicing app 11 ways. Then I closed every one.

Folioport is a client portal where small agencies send invoices and get paid through Stripe. It worked in preview. A stranger with the public key could read every agency's invoices, and a forged webhook could mark any invoice paid. This is the request-by-request record of the fix.

GET /rest/v1/invoices → 200 OK · 67 rowsLeaked
  • Rescue Audit, launch price$99 fixed
  • Turnaround72 hours
  • If you continuecredited to the fix

Finding F-04, severity Critical.

A forged Stripe webhook marks an unpaid invoice paid

An attacker needsThe webhook URL. No key, no login, no signature.

Requestas sent to the before app
POST /functions/v1/stripe-webhook
Content-Type: application/json

{"id":"evt_forged_0001",
 "type":"checkout.session.completed",
 "data":{"object":{"amount_total":0,
   "metadata":{"invoice_id":"e3f4828b…"}}}}
Response from
200 OKLeaked
{"received":true}

# then GET the invoice:
[{"number":"NLS-1019","status":"paid",
  "total":5580,"paid_at":"2026-11-22T16:05…"}]

What leaked: NLS-1019 ($5,580) went from sent to paid with a $0 payment row, and the client was emailed a $0 receipt.

400 Bad RequestFixed

Hardened route: POST /api/stripe/webhook, same body, no or fake signature

{"error":{"code":"invalid",
  "message":"Webhook signature verification failed", …}}

Why: The signature is checked on the raw body before anything is parsed. NLS-1019 stays unpaid.

Fix: The webhook verifies Stripe-Signature on the raw body before it parses anything, then compares amount and currency.

Failure mode FM7, FM8Transcript, before: evidence/before/fm07-forged-webhook.mdTranscript, after: evidence/after/f-04.md

Finding F-04 of 11. Switch to After to see the same attack against the hardened app.

working exploits, the same requests replayed F-01 to F-11 below
11 to 0
security advisor findings splinter rules, both schemas
28 to 0
requests to load the dashboard Playwright, cold load
77 to 2
invoice list query at 72,390 invoices EXPLAIN ANALYZE, median of 5
5.6ms to 0.8ms

What the builder shipped

React, Supabase and Stripe, generated from 19 prompts. Every screen worked. The problems were all in places the preview never shows: the database's own rules, the payment webhook, and what the browser is trusted to decide.

Frontend
Vite + React, shadcn/ui
Backend
Supabase: Postgres, Auth, Edge Functions
Payments
Stripe Checkout and one webhook
Tenants
Agencies, their staff, and a login for each client contact
Prompt log
before/LOVABLE_PROMPTS.md, 19 prompts
Before: as the builder generated it77 requests
The original Folioport dashboard for Northlake Studio: a white sidebar with a purple logo, four stat cards (total revenue $95,755, outstanding $25,951.18, 5 overdue, 5 active projects), a purple bar chart of revenue by month and a recent invoices table.
After: the hardened app2 requests
The hardened Folioport dashboard for the same agency: a navy sidebar, three totals (outstanding $22,330.00, overdue $20,945.00 marked past due, paid $95,755.00 marked settled), a recent invoices table with status labels and a list of active projects with budgets.
Fig. 2The same dashboard, signed in as Maya, the Northlake owner, on the same seed data. Left: the before app as generated, which makes 77 requests to draw it. Right: the hardened app, which makes 2. The before app is a fictional original, rebuilt to reproduce failure modes from real public reports.

11 findings, ranked by what they would cost you

Each card is a recorded request against the "before" app, and the same attack against the hardened app: its database for direct calls, its Worker for webhooks and checkout. The four critical ones that cost money first are open below; the rest open on click.

  1. Finding F-01, severity Critical.

    Anyone with the public key reads every agency's invoices and client emails

    An attacker needsOnly the public anon key, which ships in your website's JavaScript.

    Requestas sent to the before app
    GET /rest/v1/invoices?select=*&order=total.desc
    apikey: $ANON
    Response from
    200 OKLeaked
    [{"number":"TWS-1005","status":"paid",
      "total":11330,"stripe_session_id":null, …},
     {"number":"TWS-1004","status":"paid",
      "total":9660, …},
     "… 64 more (67 total)"]

    What leaked: 67 invoices from 2 agencies, to a caller who never signed in. The same key lists all 9 client contact emails.

    401 UnauthorizedFixed

    Hardened route: GET /rest/v1/invoices?select=*&order=total_cents.desc apikey: $ANON

    {"code":"42501",
     "message":"permission denied for table invoices"}

    Why: Same request against the hardened schema. RLS is on for every table and the anon role has no grants in public, so Postgres refuses before any row is read. The clients table answers the same way.

    Fix: RLS enabled on every table, with policies that check membership of the row’s agency.

    Failure mode FM1, FM14Transcript, before: evidence/before/fm01-anon-reads-everything.mdTranscript, after: evidence/after/f-01.md

  2. Finding F-02, severity Critical.

    The service_role key ships in the JavaScript bundle

    An attacker needsView source on your site, then one search.

    Requestas sent to the before app
    grep -Eo 'eyJ[A-Za-z0-9_.-]+' dist/assets/*.js
      | decode the payload of each token
    Response from
    2 tokens foundLeaked
    {"iss":"supabase-demo",
     "role":"anon", …}
    {"iss":"supabase-demo",
     "role":"service_role", …}

    What leaked: With the second key: 46 private messages from 2 agencies (the anon key gets 0) and 14 projects with budgets. It can write and delete anything too.

    0 secretsFixed

    Hardened route: scripts/scan-bundle.ts after/dist (runs on every build)

    scan-bundle: 27 files in after/dist, no secrets found

    Why: The browser talks only to the Worker, so the bundle holds no Supabase key at all. The service key and Stripe secrets are Worker secrets, and the build fails if a secret pattern appears in dist/.

    Fix: No Supabase key ships to the browser. The service key is a Worker secret used only by the payment pipeline, and a key that ever shipped gets rotated on day one.

    Failure mode FM4Transcript, before: evidence/before/fm04-service-key-in-bundle.md

  3. Finding F-03, severity Critical.

    A client contact marks her own invoice paid, for $1, from the browser console

    An attacker needsA client contact login. Every customer of the agency gets one.

    Requestas sent to the before app
    PATCH /rest/v1/invoices?id=eq.4023ce2e…
    apikey: $ANON
    Authorization: Bearer $JWT_PRIYA
    {"status":"paid","total":1,"paid_at":"…"}
    Response from
    200 OKLeaked
    [{"number":"NLS-1006","status":"paid",
      "total":1,
      "paid_at":"2026-11-22T16:05:25.779+00:00"}]

    What leaked: NLS-1006 went from $3,640 sent to $1 paid. She also cut another client’s invoice from $5,410 to $0.01 and made herself owner.

    200 OK, 0 rows changedFixed

    Hardened route: PATCH /rest/v1/invoices?id=eq.… (same token, same body)

    []

    Why: Client contacts have no update policy on invoices, and a trigger lets only the payment pipeline set paid or the total. Through the app the same edit returns 404.

    Fix: Status and totals are written server-side only; WITH CHECK and a column guard on invoices.

    Failure mode FM3, FM5Transcript, before: evidence/before/fm03-client-edits-invoices.mdTranscript, after: evidence/after/f-03.md

  4. Finding F-04, severity Critical.

    A forged Stripe webhook marks an unpaid invoice paid

    An attacker needsThe webhook URL. No key, no login, no signature.

    Requestas sent to the before app
    POST /functions/v1/stripe-webhook
    Content-Type: application/json
    
    {"id":"evt_forged_0001",
     "type":"checkout.session.completed",
     "data":{"object":{"amount_total":0,
       "metadata":{"invoice_id":"e3f4828b…"}}}}
    Response from
    200 OKLeaked
    {"received":true}
    
    # then GET the invoice:
    [{"number":"NLS-1019","status":"paid",
      "total":5580,"paid_at":"2026-11-22T16:05…"}]

    What leaked: NLS-1019 ($5,580) went from sent to paid with a $0 payment row, and the client was emailed a $0 receipt.

    400 Bad RequestFixed

    Hardened route: POST /api/stripe/webhook, same body, no or fake signature

    {"error":{"code":"invalid",
      "message":"Webhook signature verification failed", …}}

    Why: The signature is checked on the raw body before anything is parsed. NLS-1019 stays unpaid.

    Fix: The webhook verifies Stripe-Signature on the raw body before it parses anything, then compares amount and currency.

    Failure mode FM7, FM8Transcript, before: evidence/before/fm07-forged-webhook.mdTranscript, after: evidence/after/f-04.md

  5. F-05CriticalPay $1 for a $3,621.18 invoice by editing the request200 before, now 400

    Finding F-05, severity Critical.

    Pay $1 for a $3,621.18 invoice by editing the request

    An attacker needsA client login and the browser's network tab.

    Requestas sent to the before app
    POST /functions/v1/create-checkout
    Authorization: Bearer $JWT_PRIYA
    {"invoice_id":"3f1c9a52…","amount":1,
     "customer_email":"priya@bramblecoffee.example"}
    Response from
    200 OKLeaked
    {"sessionId":"cs_test_q0qkb3ptvdmws136ut",
     "url_params":{"amount_total":"100",
       "name":"Invoice NLS-1035", …}}

    What leaked: A $1.00 checkout for the $3,621.18 invoice NLS-1035. Opening the success URL without paying marks it paid anyway.

    400 Bad RequestFixed

    Hardened route: POST /api/invoices/:id/checkout {"amount":100}

    {"error":{"code":"invalid",
      "message":"\"amount\" is set by the server and cannot be sent",
      "request_id":"4105da6e…"}}

    Why: Checkout takes no body. Line items come from the invoice in integer cents, and only the verified webhook marks it paid.

    Fix: Checkout line items are built on the server from the invoice; client-sent prices are rejected.

    Failure mode FM6Transcript, before: evidence/before/fm06-pay-one-dollar.mdTranscript, after: evidence/after/f-05.md

  6. F-06HighA stranger who signs up reads every agency, member and phone number7 rows before, now own row

    Finding F-06, severity High.

    A stranger who signs up reads every agency, member and phone number

    An attacker needsA free account from the signup endpoint, which is open even though the app has no signup page.

    Requestas sent to the before app
    GET /rest/v1/profiles?select=full_name,email,phone
    apikey: $ANON
    Authorization: Bearer $JWT_STRANGER
    Response from
    200 OKLeaked
    [{"full_name":"Maya Okafor",
      "email":"maya@northlake.example",
      "phone":"+1 555 0101"},
     {"full_name":"Jonas Berg",
      "email":"jonas@northlake.example", …},
     …]

    What leaked: The stranger belongs to no agency, yet sees 2 organizations, 6 memberships and 7 profiles.

    200 OK, only their own rowFixed

    Hardened route: GET /rest/v1/profiles?select=id,full_name (a freshly signed-up stranger)

    [{"id":"33aef54e…","full_name":"Stranger"}]

    Why: Profiles are visible to yourself and people who share an agency with you. Memberships returns []. Emails and phone numbers are no longer copied into profiles.

    Fix: Always-true policies replaced with ownership and membership checks.

    Failure mode FM2Transcript, before: evidence/before/fm02-stranger-reads-tenants.mdTranscript, after: evidence/after/f-06.md

  7. F-07HighOne webhook event, delivered three times, records three payments3 rows before, now duplicate

    Finding F-07, severity High.

    One webhook event, delivered three times, records three payments

    An attacker needsNothing. Stripe retries a delivery on its own after a timeout.

    Requestas sent to the before app
    POST /functions/v1/stripe-webhook
    {"id":"evt_1QReplay000000001",
     "type":"checkout.session.completed", …}
    
    (the identical body, delivered 3 times)
    Response from
    200 OK × 3Leaked
    [{"amount":3235,"stripe_session_id":"cs_…0001"},
     {"amount":3235,"stripe_session_id":"cs_…0001"},
     {"amount":3235,"stripe_session_id":"cs_…0001"}]

    What leaked: One $3,235 payment became three rows totalling $9,705, and the client got three receipts.

    200 OK, duplicateFixed

    Hardened route: POST /api/stripe/webhook (the exact signed delivery, replayed)

    {"received":true,"duplicate":true}

    Why: The event id is stored first under a unique key, so the replay is logged and ignored. The invoice still has exactly 1 payment.

    Fix: An idempotency table, stripe_events, keyed on event.id.

    Failure mode FM9Transcript, before: evidence/before/fm09-webhook-replay.mdTranscript, after: evidence/after/f-07.md

  8. F-08HighSetting your own profile metadata to "admin" opens the other agency6 rows before, now 0 rows

    Finding F-08, severity High.

    Setting your own profile metadata to "admin" opens the other agency

    An attacker needsAny signed-in account. The app’s own Settings page has the dropdown.

    Requestas sent to the before app
    PUT /auth/v1/user
    Authorization: Bearer $JWT_PRIYA
    {"data":{"role":"admin"}}
    
    GET /rest/v1/projects?org_id=eq.$TIDEWATER
    Response from
    200 OKLeaked
    [{"name":"Spring campaign 2026",
      "status":"active","budget":11351, …},
     {"name":"Website refresh 2026", …},
     …]

    What leaked: Before the update: 0 of Tidewater’s projects. After it: 6 projects with budgets and 16 messages, and the right to edit them.

    200 OK, 0 rowsFixed

    Hardened route: PUT /auth/v1/user {"data":{"role":"admin"}}, refresh, then the same projects query

    []

    Why: Writing role=admin into user_metadata still succeeds, as it does on any Supabase project. It just grants nothing: roles live in the memberships table, which only the server writes, and no policy reads user_metadata.

    Fix: Policies check a memberships table instead of user_metadata.

    Failure mode FM12Transcript, before: evidence/before/fm12-user-metadata-escalation.mdTranscript, after: evidence/after/f-08.md

  9. F-09HighA database function hands any agency's revenue to anonymous callers200 before, now 401

    Finding F-09, severity High.

    A database function hands any agency's revenue to anonymous callers

    An attacker needsThe public key and an agency id, which the organizations table gives away.

    Requestas sent to the before app
    POST /rest/v1/rpc/get_org_revenue
    apikey: $ANON
    {"org":"396a94a8…"}
    Response from
    200 OKLeaked
    [{"month":"2026-05","revenue":15940,"invoice_count":4},
     {"month":"2026-06","revenue":4195,"invoice_count":1},
     … 5 more months]

    What leaked: Seven months of Tidewater’s paid revenue, $88,985 in total, with no login.

    401 UnauthorizedFixed

    Hardened route: POST /rest/v1/rpc/invoice_summary {"p_org":"<Tidewater>"} (apikey: $ANON)

    {"code":"42501",
     "message":"permission denied for function invoice_summary"}

    Why: The old function is gone (404). Its replacement runs as the caller, under RLS, and anon can't call it: a Northlake client asking for Tidewater gets [].

    Fix: The definer function was replaced by a SECURITY INVOKER one with a pinned search_path, revoked from anon, so it runs under the caller’s RLS.

    Failure mode FM11Transcript, before: evidence/before/fm11-definer-rpc-and-auth-users.mdTranscript, after: evidence/after/f-09.md

  10. F-10HighThe team page's view hands out every login email from auth.users200 before, now 404

    Finding F-10, severity High.

    The team page's view hands out every login email from auth.users

    An attacker needsOnly the public key.

    Requestas sent to the before app
    GET /rest/v1/team_directory?select=*
    apikey: $ANON
    Response from
    200 OKLeaked
    [{"email":"jonas@northlake.example", …},
     {"email":"leo@tidewater.example", …},
     {"email":"ruth@saltmarshbakery.example", …},
     "… 4 more (7 total)"]

    What leaked: Every account on the platform, across both agencies and their clients, with the time each last signed in.

    404 Not FoundFixed

    Hardened route: GET /rest/v1/team_directory?select=* (apikey: $ANON)

    {"code":"PGRST205",
     "message":"Could not find the table 'public.team_directory'"}

    Why: The view over auth.users is gone. In the app the roster is staff-only (a client contact gets 403) and lists only your own agency.

    Fix: The auth.users view was dropped; the roster comes from a scoped API route.

    Failure mode FM11, FM14Transcript, before: evidence/before/fm11-definer-rpc-and-auth-users.mdTranscript, after: evidence/after/db-replay.md

  11. F-11Medium50 invoice emails in 0.26 seconds, no login, no limit200 ×50 before, now 401

    Finding F-11, severity Medium.

    50 invoice emails in 0.26 seconds, no login, no limit

    An attacker needsOnly the public key. The email function never checks who is calling.

    Requestas sent to the before app
    for i in $(seq 1 50); do
      POST /functions/v1/send-invoice-email
      {"invoice_id":"cf7e5b03…",
       "to":"target$i@victim.example"} &
    done
    Response from
    200 OK × 50Leaked
    {"status_counts":{"200":50},
     "wall_ms":262,"any_429":false}

    What leaked: Fifty copies of another agency’s invoice TWS-1002, sent to addresses the caller chose and billed to the agency’s email account.

    401, then 409 ConflictFixed

    Hardened route: POST /api/invoices/:id/send (anonymous, then as staff, twice)

    {"error":{"code":"conflict",
      "message":"Only a draft invoice can do that; this one is sent", …}}

    Why: Staff send a draft once, to the contact on record; a "to" field gets 400. The 6th wrong password in a minute gets 429.

    Fix: Only staff can send, once per draft, to the contact on the client record. Sign-in, checkout and error reports are rate limited per user and IP.

    Failure mode FM13, FM17Transcript, before: evidence/before/fm13-email-function-abuse.mdTranscript, after: evidence/after/f-11.md

Before and after, measured the same way

Folioport before and after the rescueSame seed data, same machine, same requests. Notes below say how each row was measured.
MeasureBeforeAfter
Working exploits1110
Security advisor findings (ERROR / WARN)2280
Secrets in the JavaScript bundle310
Requests to load the dashboard4772
Invoice list query at 72,390 invoices (median of 5)55.6 ms0.8 ms
Two-user leak test: critical and high findings6200
Automated tenant-isolation tests70132
  1. Each finding above was run as a scripted request against the local before app, then the same request against the hardened app (database and Worker). Source: evidence/after/
  2. Supabase Database Advisors lint rules (splinter), run against both schemas applied from scratch: 9 ERROR and 19 WARN before, none after. Source: evidence/audit/
  3. scripts/scan-bundle.ts searches the production build for service_role, sb_secret_, sk_ and whsec_ patterns, and decodes every JWT it finds. Before, it found the service_role key in the before app’s bundle. Source: evidence/before/fm04-service-key-in-bundle.md
  4. Playwright loads the production build of the dashboard signed in as the agency owner and counts API requests; median of three runs. After: GET /api/me and GET /api/dashboard (evidence/after/dashboard-requests.json). Source: evidence/before/n-plus-one.md
  5. EXPLAIN (ANALYZE, BUFFERS) on the bulk seed (Seq Scan before, index scans after), run as the signed-in owner so RLS is in the plan; first run discarded, median of the next five. Postgres in WASM on a laptop, so compare the two columns, not absolute times. Source: evidence/after/query-plans.md
  6. The free leak test (download it further down this page), signed in as Maya (Northlake) and Leo (Tidewater): 18 critical and 2 high before, none after. Source: evidence/leak-test/
  7. Tests that sign in as two agencies and a client contact and try every table and API route. Source: after/tests/isolation/

Same stack, different trust boundaries

The database says no.

RLS on every table, membership checks in SECURITY DEFINER helpers with a pinnedsearch_path, and composite foreign keys that include the agency id, so a row can't point at another tenant's row.

Secrets live on the server.

The browser talks to a Cloudflare Worker. It holds the Stripe and Supabase secrets and decides every action before the database checks it again.

Payments are proven by Stripe.

The webhook verifies the signature on the raw body, records the event id first, and only marks an invoice paid when the amount and currency match.

Fig. 1: request path of the hardened appThe browser sends requests with an HttpOnly session cookie to a Cloudflare Worker, which checks the session, decides authorisation and applies rate limits before running a query scoped to the user. Postgres checks again with row level security on every table. Stripe sends signed events to the Worker's /api/stripe/webhook route, which verifies the signature, records the event id in the stripe_events table under a unique key, and checks the amount before marking an invoice paid. Repeat deliveries are logged and ignored. Secrets exist only in the Worker.Browsersession cookie onlyno keys, no pricesStripesigns every eventretries on its ownCloudflare Workersecrets live only here/api/*decides every actionsessionauthzrate limit/api/stripe/webhookverifysignaturerecordevent.idmatchamountPostgreschecks againtablesRLS on every tablemembership checksagency id in each FKstripe_eventsevent_id is uniquea repeat delivery islogged, not appliedHTTPSsignedscopedqueryuser JWTinsertfirstpaidFig. 1: request path of the hardened appThe browser sends requests with an HttpOnly session cookie to a Cloudflare Worker, which checks the session, decides authorisation and applies rate limits before running a query scoped to the user. Postgres checks again with row level security on every table. Stripe sends signed events to the Worker's /api/stripe/webhook route, which verifies the signature, records the event id in the stripe_events table under a unique key, and checks the amount before marking an invoice paid. Repeat deliveries are logged and ignored. Secrets exist only in the Worker.Browsercookie onlyno keys, no pricesStripesigns every eventretries on its ownHTTPSsignedCloudflare Workersecrets live only here/api/*sessionauthzrate limit/api/stripe/webhookverifysignaturerecordevent.idmatchamountscoped queryuser JWTinsertfirstPostgreschecks againtablesRLS on everytablemembershipchecksagency id ineach FKstripe_eventsevent_id isuniquea repeatdelivery islogged, notapplied
Fig. 1Request path of the hardened Folioport. The Worker decides first and Postgres checks again, so a mistake in one layer is caught by the other. Stripe events are verified and recorded before anything is marked paid.

What stayed

Every screen, the data model, and React + Supabase + Stripe. You can keep editing the UI in Lovable; the fixes live in the database, the Worker and the webhook, which the builder doesn't rewrite.

A leak test that runs on every change

132 tests sign in as two agencies and a client contact and try every table and every API route. A new table nobody wrote a test for fails the suite.

Run the same two-user check on your app, free

One file you run with Node. On Folioport it found 18 critical and 2 high leaks before the rescue, and none after.

Download leak-test.mjs17 KB · Node 20+ · nothing to install

SHA-256 (check it with shasum -a 256 leak-test.mjs)e37d63692a0ed0071a2bc2861c80d8f4ff2c6986080e499685aa75cb3b158828

Run it against a project you own
node leak-test.mjs --i-own-this-project \
  --url https://<ref>.supabase.co \
  --anon-key <publishable key> \
  --user-a a@you.dev:pass \
  --user-b b@you.dev:pass

after/tests/isolation: what the tests try

Signed in asTriesExpects
Tidewater ownera Northlake invoice by id404
Bramble contactanother client's invoice404
Bramble contactdraft invoicesnone listed
Anonymousevery table, public key401, refused
Northlake staffan invoice with "total" set400
The suite itselfa new table it does not coversuite fails

Sign in as an agency owner, a client, or the other agency

The live demo runs the hardened app with two fictional agencies. Your changes stay in your own sandbox for 24 hours. The attack console replays the findings above against it.

  • Maya OkaforOwner, Northlake Studioowner
  • Jonas BergStaff, Northlake Studiostaff
  • Priya RamanClient contact, Bramble Coffee Roastersclient
  • Leo MarshOwner, Tidewater Social (the other tenant)other tenant

Want this for your app? It starts with a 72-hour audit.

$99, fixed. A ranked list of what leaks, each with the request that proves it and the fix. Credited in full if you go on to the Rescue Sprint.

I reply within one business day with a start date and a payment link. Write to rescue@jagritvats.com with your app's URL, or see jagritvats.com.