Short answer
An insecure direct object reference (IDOR) is an access control bug: the app takes a record ID from the user and returns or changes that record without checking that it belongs to them. Changing invoice 1 to invoice 2 in a request is enough. In a Supabase app the fix lives in the database: row level security policies that tie every row to its owner.
Ask an AI about this page:ChatGPTClaude
On this page
An insecure direct object reference (IDOR) is an access control bug where an app takes the ID of a record from the user, such as /invoices/2, and returns or changes that record without checking that the user may access it. Change the number, get someone else’s data. MITRE files it as CWE-639 (opens in a new tab), and OWASP lists it under broken access control, the first category of the OWASP Top 10.
IDOR in an AI-built app
A typical Lovable or Bolt app has an invoice page that loads one row by the ID in the URL:
const { id } = useParams();
const { data } = await supabase
.from("invoices")
.select("id, amount_cents")
.eq("id", id)
.single();The code looks harmless, and in the app every user only ever clicks on their own invoices. But the request goes straight from the browser to Supabase with the public anon key. If the invoices table has no row level security, or a policy that lets every signed-in user read every row, any user can open /invoices/1, /invoices/2 and so on and read other customers’ invoices. The same applies to update and delete calls.
How to check your app
Use two test accounts of your own. Sign in as user A, note the ID of one of their records, then sign in as user B and request that ID, through the app or the browser’s network tab. You should get nothing back. The OWASP cheat sheet recommends exactly this: test with several users and check reads, writes, deletes and exports.
You can run the same test in the Supabase SQL Editor. This asks for invoice 1 as a second user (replace the ID with a real user ID from Authentication → Users) and rolls everything back:
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub": "22222222-2222-2222-2222-222222222222"}';
select id, amount_cents from public.invoices where id = 1;
rollback;If invoice 1 belongs to someone else and the query returns it, you have an IDOR.
How to fix or prevent it
Put the owner check where the caller cannot remove it. In Supabase that is an RLS policy:
alter table public.invoices enable row level security;
create policy "Owners read their invoices"
on public.invoices for select
to authenticated
using ((select auth.uid()) = user_id);After this, the check query above returns no rows for the second user, while each owner still sees their own invoice. Add matching policies for insert, update and delete; the full pattern is in the Supabase row level security guide and the update and delete case in Missing ownership check.
If an edge function loads the record with the secret key, RLS does not apply. There the function must read the user from the verified session and compare it with the record’s owner before returning anything. Random IDs such as UUIDs are a good extra layer, but never the check itself.
Frequently asked questions
Do UUIDs instead of numbers prevent IDOR?
No. Random IDs make guessing harder, and OWASP recommends them as an extra layer, but IDs leak through links, logs, shared screens and API responses. The access check on every request is what prevents IDOR.
What is the difference between IDOR and BOLA?
They describe the same flaw from two angles. IDOR is the older web term; broken object level authorization (BOLA) is the name the OWASP API Security Top 10 uses for APIs. CWE lists both as alternate terms for CWE-639.
Is a filter like .eq(‘user_id’, userId) in my React code enough?
No. It runs in the browser, so anyone calling your API with the public key can leave it out or change it. The check has to happen in the database or on your server.
Sources
- 1.Insecure Direct Object Reference Prevention Cheat Sheet — OWASP Cheat Sheet Series
- 2.CWE-639: Authorization Bypass Through User-Controlled Key — MITRE
- 3.A01:2025 Broken Access Control — OWASP Top 10
- 4.Row Level Security — Supabase Docs