Review request

Bolt dashboard for warehouse pick rates, is the anon key in the browser a problem?

Open · 82 viewsasked by tomvibes

Repo or live app

git.example.com/tomachterberg/pickrate-board ↗

Unsure about: SecurityDeployment

Bolt built a dashboard on top of a pick_events table so our floor managers can see rates per shift. I opened the Network tab and the Supabase URL and anon key are sitting right there in the request headers. Our HR person is now asking whether anyone can read the table. I don't know how to answer that.

Comment
The anon key being visible is expected, it's meant to be public. The real question is whether pick_events has RLS on. Table Editor shows it next to the table name. mira_dev
It says RLS disabled. So... anyone can read it? tomvibes
Anyone with that key, yes, and probably write too. Enable RLS first, then add a select policy for the managers. mira_dev

1 answer

jb_supa

Mira's right. Here's how to answer your HR person with evidence instead of a guess. Run this in the SQL editor:

It's not just pick_events. With RLS off, the anon key (which every browser that opens the dashboard has) can select, insert, update and delete in all three tables. So yes, anyone can read it, and anyone can also change the pick rates.

Fix, in this order. Create a managers table with the user ids of your floor managers, then:

alter table pick_events enable row level security;
alter table shifts enable row level security;
alter table employees enable row level security;

create policy "managers read" on pick_events for select
  using (exists (select 1 from managers m where m.user_id = auth.uid()));

Same select policy for shifts and employees. Then rerun the query above until it returns nothing. Since employees probably holds names, tell HR honestly that it was readable, and since when.

Comment
Three tables, not one. RLS is on for all three and the query returns nothing now. The dashboard is blank though. tomvibes
Blank is the policy doing its job. Add the managers to the managers table and log in as one of them. jb_supa
Added our four floor managers, numbers are back. Going to talk to HR now. tomvibes