Review request

Vinyl marketplace, anyone signed in can edit anyone else's listing

Solved · 11 views · asked by kai_makes · edited

Repo or live app

github.com/kaitanaka/crate-digger

Unsure about: Security

Small marketplace for record collectors, about 60 sellers. A friend testing it noticed he could change the price on someone else's listing by editing the id in the request. RLS is on for listings and I do have an update policy, so I expected that to be blocked. Clearly I have misunderstood what the policy does.

Comment

1 answer

Marked as helpful by the asker
mira_dev · edited

You almost certainly wrote the update policy with only using and no with check. That is the single most common RLS mistake.

using decides which rows you are allowed to update. with check decides what the row is allowed to look like afterwards. With only using, a seller can take their own row and rewrite seller_id to someone else, or in a policy written as using (true) touch anything at all. Write both halves:

create policy "own listings" on listings for update
  using (seller_id = auth.uid())
  with check (seller_id = auth.uid());

Check your insert policy too, since insert only has with check, and a missing one there lets a user create a listing already owned by someone else.

Comment