Deutsch
Fix libraryHighSupabase · Payments

Credits, paid status or prices set by the client: stop trusting the browser with money

If the browser writes the price, the payment status or the credit balance, users can set their own. Lock these columns with grants and compute them in the database.

By Tim GeithnerPublished 3 min read

ShipRely's Security audit checks for this today.

Short answer

Columns that decide money, such as a price, a payment status or a credit balance, must never be writable from the browser. RLS limits which rows a user can write, not which columns, so an open insert or an owner update policy lets users mark orders as paid, pay one cent or give themselves credits. Grant clients only the columns they may set, compute the rest in the database, and let only your payment webhook change payment status and balances.

Ask an AI about this page:ChatGPTClaude

On this page

When the browser writes the price, the payment status or the credit balance, the user decides how much they pay. In a Supabase app the browser talks to the database directly, so any column it is allowed to set, a user can set to anything: an order marked paid, a total of one cent, a balance of a million credits. It is rated high because it costs you money directly and needs nothing but a free account and the browser console.

Why it matters

This is the order table from one of our test apps, a small shop where customers order products for pickup:

VulnerableThe vulnerable migration
create type public.payment_status as enum ('pending', 'paid', 'refunded');

create table public.orders (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null references auth.users (id) on delete cascade,
  product_id uuid not null references public.products (id),
  quantity integer not null,
  total_cents integer not null,
  payment_status public.payment_status not null default 'pending',
  pickup_date date not null,
  created_at timestamptz not null default now()
);

alter table public.orders enable row level security;

revoke all on table public.orders from anon, authenticated;
grant select, insert on table public.orders to authenticated;

create policy "Customers can view their own orders"
  on public.orders for select
  to authenticated
  using ((select auth.uid()) = user_id);

create policy "Customers can place orders"
  on public.orders for insert
  to authenticated
  with check (true);

The shop page computes total_cents from the product price and always sends payment_status: "pending", and a comment says the payment webhook will set the status later. But the insert grant covers every column and the policy accepts any row. A user can insert an order that is already paid, costs one cent or belongs to another customer, and staff see a paid order at pickup. Our audit engine found exactly this in our test apps and reported the open insert policy and the client-computed values as one high finding. It is the same mistake whether the column is a price, a plan or a credits column on a profile that users can update: OWASP’s insecure design category lists it as client-side enforcement (CWE-602 (opens in a new tab)) and as trusting values that look fixed but are not (CWE-472 (opens in a new tab)).

How to find it in your app

In your frontend, search for inserts and updates that send money-like fields: price, total, amount, status, paid, credits, balance, plan. Then list which of those columns signed-in users are allowed to write:

Money-like columns the browser can write
select table_name, column_name, privilege_type
from information_schema.column_privileges
where table_schema = 'public'
  and grantee in ('anon', 'authenticated')
  and privilege_type in ('INSERT', 'UPDATE')
  and column_name ~* 'credit|balance|plan|status|paid|price|total|amount'
order by 1, 2, 3;

A row matters when an insert or update policy lets the user reach that table. Always-true insert policies such as with check (true) are also what the Security Advisor’s lint 0024 (permissive_rls_policy) is about.

How to fix it

Let the client send only what a customer really chooses, and let the database fill in the rest. In a new migration:

SafeFix: the database owns price, status and owner
create schema if not exists private;

revoke insert on table public.orders from authenticated;
grant insert (product_id, quantity, pickup_date) on table public.orders to authenticated;

alter table public.orders alter column user_id set default auth.uid();
alter table public.orders add constraint orders_quantity_range check (quantity between 1 and 50);

drop policy "Customers can place orders" on public.orders;

create policy "Customers can place their own pending orders"
  on public.orders for insert
  to authenticated
  with check (
    (select auth.uid()) = user_id
    and payment_status = 'pending'
  );

create or replace function private.set_order_total()
returns trigger
language plpgsql
set search_path = ''
as $$
begin
  select p.price_cents * new.quantity
    into new.total_cents
    from public.products p
   where p.id = new.product_id and p.active;

  if new.total_cents is null then
    raise exception 'Unknown or inactive product';
  end if;

  return new;
end;
$$;

create trigger orders_set_total
  before insert on public.orders
  for each row execute function private.set_order_total();

The column grant means an insert that mentions payment_status, total_cents or user_id is rejected with permission denied. The owner comes from the session, the status from its default, and the total from the product table, computed by the trigger before the row is stored. The frontend now sends insert({ product_id, quantity, pickup_date }) and nothing else. Only your payment webhook, running with the secret key after verifying the provider’s signature, sets paid (see Stripe webhook without signature check). If the quantity check fails on old rows, clean them up first.

For credit balances the rule is the same: no client grant on the balance column, and credits added only by a function that the webhook calls. The SECURITY DEFINER fix shows how to lock down such a function, and the paywall bypass guide covers plans and subscriptions.

Stop the browser from setting prices and payment status

In public.orders (and any other table where the browser writes money-related columns), the client can set payment_status, total_cents and user_id. Add a new Supabase migration that: revokes table-level insert on public.orders from authenticated and grants insert only on product_id, quantity and pickup_date; sets the default of user_id to auth.uid(); adds a check that quantity is between 1 and 50; replaces the insert policy with one for the authenticated role that requires (select auth.uid()) = user_id and payment_status = ‘pending’; adds a before insert trigger with set search_path = ‘’ that sets total_cents from public.products.price_cents times quantity and rejects unknown or inactive products.

Then change the frontend insert to send only product_id, quantity and pickup_date. Only the payment webhook may change payment_status, using the secret key after verifying the signature. Do not edit existing migrations.

Check that the fix works

Act as a customer and try to place an order that is already paid and almost free:

Check as a customer
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub": "22222222-2222-2222-2222-222222222222", "role": "authenticated"}';
insert into public.orders (product_id, quantity, pickup_date, total_cents, payment_status)
values ('33333333-3333-3333-3333-333333333333', 1, current_date + 1, 1, 'paid');
rollback;

With a real customer ID and a real product ID, this must fail with permission denied for table orders. Remove the last two columns and their values and run it again: the order must be stored with your user ID, pending and the full price. Then check that your webhook can still mark it as paid in Stripe’s test mode.

Frequently asked questions

My frontend always sends payment_status ‘pending’. Why is that a problem?

Because the database accepts whatever arrives. Anyone can send the same insert with ‘paid’ instead, using your public key and their own session. Your code’s good behaviour does not limit what others send.

Doesn’t RLS stop users from writing columns they shouldn’t?

No. A policy decides which rows a user may insert or change. Within an allowed row, every column the user has a privilege on can be set. Column-level grants are the tool for columns.

How should credits be added after a purchase?

By your payment webhook on the server, after it has verified the provider’s signature, calling a function that only the service role can execute. Never from the checkout success page in the browser.

What about existing orders that might have been tampered with?

Compare paid orders in your database with the payments your provider recorded. Any order marked paid without a matching payment should be reviewed before you fulfil it.

Sources

  1. 1.Privileges — PostgreSQL Documentation
  2. 2.Row Level Security — Supabase Docs
  3. 3.Performance and Security Advisors — Supabase Docs
  4. 4.CWE-472: External Control of Assumed-Immutable Web Parameter — MITRE
  5. 5.CWE-602: Client-Side Enforcement of Server-Side Security — MITRE
  6. 6.A04 Insecure Design — OWASP Top 10

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt