← All posts
·7 min read·GuardLayer

Case study: how any VivTrack user could give themselves Pro

SupabaseRLSSubscriptionsSECURITY DEFINERCase study

VivTrack stored each user's plan in their own profiles row, and an RLS policy let users update that row. RLS picks rows, not columns, so any signed-in user could set subscription_tier to pro on themselves. Two smaller gaps sat next to it: a SECURITY DEFINER function that changes a user's tier was callable by anyone, and two promo codes, one with unlimited uses, were seeded in the public repo. Daniel, who builds VivTrack, closed all three the same day the report arrived.

We reported this privately on November 18, 2026. The fix, commit da0de10, landed about an hour and a half later and went further than the report asked. This write-up is published with Daniel's permission. VivTrack is at vivtrack.vercel.app.

What VivTrack does

VivTrack is a tracker for people who keep reptiles, amphibians and invertebrates: animal profiles, weights and sheds, feedings, enclosures with misting reminders, breeding records and care sheets. It's an installable web app that works offline and syncs through Supabase when you sign in.

The free tier covers the basics. Pro is a Lemon Squeezy subscription (monthly, annual or lifetime), and a few promo codes grant it too. Both paths end in the same place: a subscription_tier column on the user's profiles row, which the app reads to decide what to unlock.

How did it work?

1. Users could edit their own plan. The profile table and its policies, simplified:

create table public.profiles (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null unique references auth.users (id) on delete cascade,
  subscription_tier text not null default 'free' check (subscription_tier in ('free', 'pro')),
  plan_type text check (plan_type in ('monthly', 'annual', 'lifetime')),
  ls_customer_id text,
  ls_subscription_id text,
  subscription_expires_at timestamptz,
  promo_code text
);
alter table public.profiles enable row level security;

create policy "Users read own profile" on public.profiles
  for select using (auth.uid() = user_id);
create policy "Users update own profile" on public.profiles
  for update using (auth.uid() = user_id);

The update policy looks reasonable: you can only touch your own row. But RLS decides which rows a statement may change, not which columns, and on a project like this one Supabase's default privileges give authenticated UPDATE on the whole table. So the browser client, with the user's own session, could send:

await supabase
  .from("profiles")
  .update({ subscription_tier: "pro", plan_type: "lifetime" })
  .eq("user_id", user.id);

and the row would say Pro.

2. A tier function anyone could call. update_ls_subscription() was written as a manual repair tool: give it a Lemon Squeezy customer id and a tier, and it updates the matching profile. It ran as SECURITY DEFINER and never checked who was calling. Supabase grants EXECUTE on new functions in public to anon and authenticated by default, so it was callable through /rest/v1/rpc with the public anon key. Someone who knew a user's Lemon Squeezy customer id could change that user's tier.

3. Promo codes in the repo. The schema file seeded two codes, VIVTRACK_BETA (unlimited uses) and FOUNDER2026 (50 uses). The redemption function itself was fine: it checks the caller, checks the code and allows one code per account. The problem is that the schema lives in a public repository, so anyone reading it could redeem the codes.

What could someone do?

Get Pro without paying, in two ways: by editing their own profile row, or by redeeming a code from GitHub. The open function was the least likely path, since it needs someone else's customer id, but it could also downgrade a paying user.

No other users' data was readable through these holes. The profile select policy was scoped to the owner, and the animal and enclosure tables have their own policies. We found this by reading the public schema and never tested anything against VivTrack's project.

How was it fixed?

Daniel's fix is a single migration, supabase/fix-2026-11-18-lock-down-pro.sql, plus the same changes folded into schema.sql. In short:

-- 1. Nobody signed in needs to write profiles: tiers come from the payment
--    webhooks (service role) and redeem_promo_code() (security definer).
drop policy if exists "Users update own profile" on public.profiles;
revoke insert, update, delete on public.profiles from anon, authenticated;

-- 2. The repair function is for the service role only.
revoke execute on function public.update_ls_subscription(text, text, text, text, boolean, timestamptz)
  from public, anon, authenticated;
grant execute on function public.update_ls_subscription(text, text, text, text, boolean, timestamptz)
  to service_role;

-- 3. The codes table isn't readable from the app at all any more.
drop policy if exists "Authenticated users can check codes" on public.promo_codes;
revoke all on public.promo_codes from anon, authenticated;

-- 4. Stop new redemptions of the published codes.
update public.promo_codes set is_active = false
  where code in ('VIVTRACK_BETA', 'FOUNDER2026');

It goes beyond the report in three ways. Step 3 closes a gap we hadn't raised: any signed-in user could list every active code through the codes table's select policy, and the redemption function doesn't need that policy because it runs as definer. The migration also pins search_path on the three definer functions. And it ends with an audit query that sorts every Pro account into paid, promo or unexplained:

select user_id, subscription_tier, promo_code, ls_subscription_id,
       case when ls_subscription_id is not null then 'paid'
            when promo_code is not null then 'promo: ' || promo_code
            else 'UNEXPLAINED' end as how
from public.profiles
where subscription_tier = 'pro'
order by how desc;

That last step is worth copying. Closing a hole stops new abuse, but only an audit tells you whether anyone used it.

Does my app have the same problem?

It's a common pattern: in our study of 844 public Supabase projects, 8.6% let users edit their own role, plan or balance this way.

Check three things.

Own-row update policies on tables that hold a plan or role. This lists the policies that let users update a table, next to that table's privileged-looking columns:

select p.tablename, p.policyname, p.cmd,
       string_agg(c.column_name, ', ') as sensitive_columns
from pg_policies p
join information_schema.columns c
  on c.table_schema = p.schemaname and c.table_name = p.tablename
where p.schemaname = 'public'
  and p.cmd in ('UPDATE', 'ALL')
  and c.column_name ~ '(role|plan|tier|subscription|credit|balance|is_admin|is_pro|premium|verified)'
group by 1, 2, 3;

Every row is a column the owner can rewrite unless something else stops them. Fix it with a column grant (revoke update on public.profiles from authenticated; grant update (display_name, avatar_url) on public.profiles to authenticated;), or, like VivTrack, by not letting the client write the table at all.

Definer functions the API roles can run. The query in the Kagelin case study lists every SECURITY DEFINER function in public and whether anon or authenticated can execute it. A repair or admin function should come back false for both.

Secrets in seed files. Search your migrations and seeds for promo codes, invite codes and test accounts. If the repo is public, so are they:

grep -rniE "insert into .*(promo|coupon|invite|voucher)" supabase/

Does GuardLayer catch this?

Yes, for the first two. The code scan reads your migrations together and flags the "Users update own profile" policy because subscription_tier and plan_type sit on a row users can update with no column grant or guard trigger in front of them. It flags update_ls_subscription() because the API roles can execute it, it changes data, and it never checks who is calling. It also flags the codes table's select policy, which lets every signed-in user read every active code. Live check finds the same things on the running project: it reads the real policies and grants and reports users who can change their own plan and definer functions anon can run.

It doesn't flag the seeded codes. A promo code in an insert statement looks like any other seed data, so that one needs the grep above.

FAQ

Doesn't RLS stop users from changing columns they shouldn't? No. RLS policies choose which rows a statement can see or change. Which columns it can write is decided by grants: revoke UPDATE on the table and grant it back on the columns users may edit.

Is a WITH CHECK clause enough? Only if it pins every sensitive column, for example by comparing it with the stored value. A WITH CHECK (auth.uid() = user_id) checks ownership, not what changed. Column grants are simpler and harder to get wrong.

Where should the subscription tier live? Somewhere only your server writes: a column the client can't update, or a separate table written by your payment webhook with the service role. The client should only ever read it.

Should promo codes be in the schema file? Not in a public repo. Create them from the SQL editor or an admin tool, and keep the redemption logic, not the codes, in your migrations.

See which of your Supabase tables anyone can read, free

Connect your Supabase project read-only. GuardLayer checks RLS, policies, grants and functions as they are right now, and gives you the SQL to fix each problem. It never reads your rows and can't change anything.

Check my Supabase project

Prefer to check code instead? Scan your repo, no signup.

Keep reading