Clients could see more than their own deal
The July security review found that older, broad access rules on three core tables were wider than the owner-scoped ones. A signed-in client could read records that were not theirs.
Why it was hard, what I decided, how AI helped
- Why it was hard
- Each rule looked fine on its own. Postgres combines permissive rules with OR, so one broad rule quietly overrode the careful ones. File downloads were a second gap, because signing a storage link does not check table rules.
- My approach
- I had the review check every finding against the live database, not just the code, before calling it real or fixed.
- How AI helped
- Claude Code wrote the SQL to drop the broad rules and add owner-or-admin rules through helper functions, and added an ownership check before any document link is signed or a document deleted.
- The decision
- Fix it in the database, where every path into the data is covered, and add the code check only where the database cannot help.
- Evidence
- commit 7fcbec3 · sql/add-core-rls-policies.sql · 23 Jul 2026


