DEV Community

iloblique
iloblique

Posted on Originally published at iloblique.com

Hidden in the UI is not hidden: who can see what belongs in the database

The short answer. Hiding a field in the interface hides it from people who use the interface. It does not hide it from anyone who calls the database directly. On a Supabase or Lovable app the browser already holds everything it needs to make that call. So the rule "who can see what" has to live in the database. Write it as a table before the first prompt, put it in one shared place, and check it with one test: log in as user A, ask for user B's record, get nothing back.

Where this came from

After our LinkedIn carousel of 16 November ("what must survive the rewrite of v1"), a reader described their own case. On a Supabase app they work on, Premium fields were hidden only in the UI. The database still served those fields to anyone who asked. Moving the rule into the database took a two-step rollout so the live app never broke. They ended with a question: do we get founders to write these rules down before the first build?

This is not one unlucky app. A small r/vibecoding thread on 11 November listed the same failure from the reviewer's side: an admin button hidden in the UI while the API never checks permissions, and a frontend that filters records while the database does not enforce who may read them. A founder in an r/webhosting thread said they had no routine for checking auth, database changes, logs or backups once real users arrived. That is two small threads. Read it as a direction, not a measurement.

A reader under one of our Threads posts described a common version of the mistake: a route that checks the user is logged in, but not that they own the record. Nothing about that looks wrong to a pattern scanner.

Why the button does not protect anything

In a typical Supabase app the browser talks to the database through an auto-generated API, using a public key that ships inside the page. The interface decides what to show. What can be fetched is decided by the database, and only if you told it something.

browser ──(public key + user session)──► REST API ──► Postgres
   │                                                     │
   └ "don't render premium_notes"           RLS off: returns every row, every column
                                            RLS on:  returns what the policy allows
Enter fullscreen mode Exit fullscreen mode

If row-level security is off, or the policy only checks "is logged in", any signed-in user can open the browser console and ask for every row and every column. Hiding a column in React changes nothing about that request.

The same gap appears on your own server routes. This one looks finished:

// checks that someone is logged in, not that the invoice is theirs
app.get('/api/invoices/:id', requireAuth, async (req, res) => {
  const invoice = await db.invoice.findUnique({ where: { id: req.params.id } })
  res.json(invoice)
})

// the fix: the ownership check is part of the query
const invoice = await db.invoice.findFirst({
  where: { id: req.params.id, ownerId: req.user.id },
})
if (!invoice) return res.status(404).end()
Enter fullscreen mode Exit fullscreen mode

One Supabase detail decides more than it seems. A server route using the service_role key bypasses row-level security entirely. If your server code uses that key, the database policy is not protecting that route. In our view the default should be the user's own session, with service_role kept for the few jobs that really need it.

Step one: the table, before the first prompt

The rule has to exist somewhere before code can enforce it. We write it as a grid of roles against data. Here is a generic example:

data                    | anonymous | free user       | premium user    | admin
------------------------|-----------|-----------------|-----------------|-------
report summary          | read      | read            | read            | read
report forecast         | -         | -               | read            | read
own profile             | -         | read/write own  | read/write own  | read
other users' profiles   | -         | -               | -               | read
invoices                | -         | read own        | read own        | read
Enter fullscreen mode Exit fullscreen mode

Every cell is a decision the founder makes, not the model. Our view is that this grid is the cheapest artifact in the whole build. A coding agent asked to "add a premium tier" has to guess these cells. A coding agent given the grid does not.

To answer the reader's question: yes. We think founders should write this down before the first build, and it is the grid we ask for first. It is one page, and every later prompt can point at it.

Step two: enforce it in the database

Rows are handled by row-level security policies:

alter table public.invoices enable row level security;

create policy "owners read their invoices"
  on public.invoices for select
  to authenticated
  using ( owner_id = (select auth.uid()) );
Enter fullscreen mode Exit fullscreen mode

Columns are harder, because row-level security filters rows, not fields. The simplest pattern we know is to move the premium fields into their own table with their own policy:

create table public.report_premium (
  report_id uuid primary key references public.reports(id) on delete cascade,
  forecast  jsonb
);
alter table public.report_premium enable row level security;

create policy "premium users read forecasts"
  on public.report_premium for select
  to authenticated
  using ( public.is_premium() );
Enter fullscreen mode Exit fullscreen mode

Step three: one shared rule, not three copies

A reader under our X post described how agent-written features fail here. Each new feature re-implements permission and data-scope checks, so the same rule ends up in three places. Their advice was to put those rules in one shared layer that new code only calls. We agree. In Postgres that layer can be a function every policy calls:

create function public.is_premium()
returns boolean
language sql stable security definer
set search_path = ''
as $$
  select exists (
    select 1 from public.subscriptions s
    where s.user_id = (select auth.uid())
      and s.plan = 'premium'
      and s.status = 'active'
  );
$$;
Enter fullscreen mode Exit fullscreen mode

When the pricing changes, one function changes. Every policy follows, and you can still say where each rule lives.

Step four: the test

The test does not need a security tool. It needs two accounts.

# signed in as user A, ask for user B's invoice
curl "$SUPABASE_URL/rest/v1/invoices?id=eq.$INVOICE_OF_B&select=*" \
  -H "apikey: $ANON_KEY" \
  -H "Authorization: Bearer $JWT_OF_A"
# expected: []

# signed in as a free user, ask for a premium field
curl "$SUPABASE_URL/rest/v1/report_premium?select=forecast" \
  -H "apikey: $ANON_KEY" \
  -H "Authorization: Bearer $JWT_OF_FREE_USER"
# expected: []

# no session at all
curl "$SUPABASE_URL/rest/v1/invoices?select=*" -H "apikey: $ANON_KEY"
# expected: []
Enter fullscreen mode Exit fullscreen mode

Run it once per row of the grid. Run it before a change and after it. Some buyers who hire outside help ask exactly this: how will you prove tenant A cannot read tenant B, on every endpoint, before and after? The same source adds a piece of advice: price the tenant isolation as a separate piece of work, not as a quote for a full rewrite. We think that is right.

If the app is already live

Dropping a column the live client still reads breaks the app. So the move takes two releases, the same shape as the reader's two-step rollout. This is our version:

release 1  create report_premium, copy the data, add the policy,
           ship a client that reads forecasts from the new table
release 2  once no client reads the old column:
           alter table public.reports drop column forecast;
           run the A-asks-for-B tests again
Enter fullscreen mode Exit fullscreen mode

Between the two releases nothing breaks, and the old column still leaks. Keep that window short.

What we cut, and what would change our mind

We left out audit logs, secrets in client code and backups. They matter, but they are other posts. If your app reads data only through server routes that check ownership on every query, and never exposes the database to the browser, the policies are a second lock rather than the only one. We still keep them. In a clinic booking system we built, role access is enforced twice, in application logic and again in row-level security. A bug in one layer is then not a data leak. Patient contact details there are scoped per appointment, so an anonymous request cannot fish for someone else's.

FAQ

Is row-level security enough on its own?
It covers rows. Fields need either a separate table or column privileges, and server routes using the service_role key skip it entirely. Check all three.

Does this apply if I'm not on Supabase?
Yes. Any app where the client can reach an API that does not check ownership has the same gap. The grid and the A-asks-for-B test work on any stack.

My app has a few dozen users. Is this urgent?
The leak does not depend on the number of users. One curious person with a browser console is enough. In our view the grid is worth writing on day one, because it costs one page.

Can the coding agent write the policies?
It can write them well from the grid. Without the grid it guesses the rules. Either way, the test is what tells you whether it worked.

Related case

RE Intelligence, our analytics product for the Dubai property market, organises access by job: CEO, Broker and Analyst get different module sets, and its in-page assistant is limited to read-only queries. The case is at iloblique.com/re-intelligence.

If you have something worth building, we'd like to hear about it.

Sources

  • A reader's comment under our LinkedIn carousel, 16 November 2026 (anonymous).
  • r/vibecoding thread, 11 November 2026, and an r/webhosting thread: two small threads, a direction rather than a measurement.
  • A reader's comment under our Threads post (anonymous).
  • A reader's comment under our X post (anonymous).
  • A buyer-side question about proving tenant isolation, as buyers phrase it.
  • Supabase documentation on row-level security and API keys.

Originally published at iloblique.com.?utm_source=devto&utm_medium=social&utm_campaign=devto_article_v1&utm_content=f909b28a

Top comments (3)

Collapse
 
alex_simakov_d5176f3977ad profile image
Alex Simakov •

The "log in as user A, ask for user B's record, get nothing back" test is the right one. A cheaper first pass that catches the worst case: with only the public anon key (no login at all), request each table through the REST API. If any table returns rows, RLS is off or has a using (true) policy, and no UI hiding matters. That's the pattern behind CVE-2025-48757.

Collapse
 
sunnatulla_dev profile image
Sunnatulla •

One gap in the curl test: [] is also what you get for a wrong $INVOICE_OF_B, an empty report_premium, or RLS enabled with no policy at all. I ran all three locally and every one "passed". Run the same request with B's JWT first and require one row, then A's [] means something.

Collapse
 
nexusverify profile image
Nexus Verify •

One place the two-account curl test won't catch it: your own server routes. A route that uses the service_role key bypasses row-level security entirely, so the direct REST call can come back empty while /api/invoices/:id still hands user B's invoice to user A.

So run the same A-asks-for-B test against the server route too, not just the REST API — and keep service_role out of any route that serves a single user's data. If a route needs it, it should re-check ownership itself before returning anything.