Teardown · Lovable
Our Lovable expense app locks approved expenses. It doesn't lock the receipts.
An employee can swap the receipt on an approved expense, and the manager's screen still says approved. How we found it, the test that proved it, and the one-rule fix.
We had Lovable build an expense approval app, then tested whether an employee could change a receipt after their manager approved it. They can. The app locks the expense record correctly, but the receipt photo lives in file storage under separate rules, and those rules let the employee delete it and upload a different one under the same name. The fix is one database policy, and we tested that too.
What we built
One prompt in Lovable on November 14, 2026, using its TanStack Start template with Lovable Cloud (Supabase) for the database, sign-in and file storage. We kept the setup defaults: anyone can sign up, with email and password.
Build an expense approval app for my company. Employees log in, submit expenses with an amount, category, description, and a photo of the receipt. Managers see their team’s expenses and can approve or reject them. Admins can see everything and manage users. Add a dashboard with totals by month.
We changed nothing by hand. We tested on a local Supabase instance running the app’s own database migration, not the live deployment.
Most of the approval logic is solid. The browser talks directly to the database, so every access rule lives in row-level security, and Lovable wrote them with care:
- Employees have no permission to edit an expense at all, so they can’t change an amount after the fact.
- Status changes go through a single database function that checks the caller is an admin or the employee’s manager.
- That function refuses to let anyone review their own expense.
- Receipts sit in a private storage bucket, and managers view them through short-lived signed links.
A reviewer checking “can employees tamper with approved expenses?” would try editing the record, see it fail, and move on.
What we found
| # | Finding | Severity | Checklist item |
|---|---|---|---|
| 1 | An employee can replace the receipt on an approved expense | High | 21: Kept record of who did what |
| 2 | A manager can reverse a decision that’s already made | Medium | 02: Roles enforced on the server |
These are two of thirteen findings from the full checklist review of this app. This article covers the two we reproduced.
1. The approved receipt can be swapped
The expense record and the receipt photo are stored in different places. The record is a row in the expenses table. The photo is a file in Supabase Storage, in a folder named after the employee. Storage has its own policies, and two of the generated ones matter here:
-- drizzle/migrations/0000_migration.sql, as generated
create policy "Upload own receipts" on storage.objects for insert to authenticated
with check (bucket_id = 'receipts' and (storage.foldername(name))[1] = auth.uid()::text);
create policy "Delete own receipts" on storage.objects for delete to authenticated
using (bucket_id = 'receipts' and (storage.foldername(name))[1] = auth.uid()::text);
Each rule makes sense alone. The delete rule exists so an employee can withdraw a pending expense and clean up its photo. Neither rule asks whether the expense the file belongs to is still pending.
We scripted the attack with three accounts: an admin, a manager, and an employee who reports to the manager.
| Step | Who | Result |
|---|---|---|
| Submit a $12.40 lunch with receipt A | Employee | Allowed |
| Approve it | Manager | Allowed |
| Edit the approved expense | Employee | Blocked |
| Overwrite receipt A in place | Employee | Blocked |
| Delete receipt A | Employee | Allowed |
| Upload receipt B under the same filename | Employee | Allowed |
| Open the receipt from the approval screen | Manager | Shows receipt B |
After the swap, the expense still reads approved, $12.40, with the manager’s name on the approval. Nothing on screen shows that anything changed.
The evidence behind an approval can change after the approval. Any receipt check (an audit, a reimbursement dispute, a tax question) sees a file the manager never reviewed, attached to a record that says they did.
The two blocked steps are why this survives review. Both obvious tampering paths fail. The gap only shows up when you ask what the approval is meant to protect, then check every place that thing is stored.
The fix narrows the delete policy so it refuses once a reviewed expense points at the file:
- create policy "Delete own receipts" on storage.objects for delete to authenticated
- using (bucket_id = 'receipts' and (storage.foldername(name))[1] = auth.uid()::text);
+ create policy "Delete own receipts unless reviewed" on storage.objects for delete to authenticated
+ using (bucket_id = 'receipts'
+ and (storage.foldername(name))[1] = auth.uid()::text
+ and not exists (select 1 from public.expenses e
+ where e.receipt_path = storage.objects.name and e.status <> 'pending'));
We ran the same script again with the fix applied. The delete removed nothing, and the re-upload failed because the original file was still there. Withdrawing a pending expense still worked, because the app deletes the expense row before the file. A rule written the other way round (“allow only if a pending expense exists”) would have broken that.
For stronger evidence, record a hash of the receipt on the expense when it’s submitted, so a swap is detectable even if a storage rule is later loosened.
2. Decisions can be reversed after the fact
The review function checks who is calling, but not whether the expense is still pending. The approval screen hides the Approve and Reject buttons once an expense is decided, so in the app it looks final. Called directly, the function accepts a new decision on an expense that’s already approved.
In the same test run, the manager changed the approved $12.40 lunch to rejected with one call. Each call overwrites the reviewer, the time and the note, so there’s no trace of the original approval.
The fix is a status check at the top of review_expense, so it raises an error unless the expense is still pending. If decisions do need reversing, give that its own audited action rather than reusing approval.
Hiding a button is not access control. The browser holds the same key the app uses, so anything the database allows, a user can do without the button.
What it would take to ship
Both fixes are small. The receipt fix is one policy, already tested. The status check is a few lines in one function. We estimate under an hour for both, plus asking Lovable to apply them, since Lovable manages this project’s database schema.
The design decision is the audit trail. Today an approval is a single row that later actions overwrite. An expense app that will face an audit needs an append-only history of submissions, decisions and receipt files, and that’s a schema change, not a patch.
These two fixes don’t make the app shippable. It passed 4 of the 24 items on our production checklist. The most urgent of the rest: anyone on the internet can sign up, every signed-in user can read the whole staff directory, and the first account to sign up becomes admin.
Before you rely on this: we tested the app’s migration on a local Supabase instance, not the live deployment. The repository doesn’t create the receipts bucket, so we created it as private, as the project’s notes describe. The live project’s storage settings could differ.
We build every app in this series ourselves for the teardown. No customer code is shown.