IDOR: when changing a number in the URL leaks other people’s data
IDOR (Insecure Direct Object Reference) is the simplest attack there is: you change an id in a URL or request from yours to someone else’s, and the server hands back their data because it never checked whether the object is really yours.
It is the most common flavour of "broken access control", which sits at the top of the OWASP Top 10.
Why it matters
If /api/invoice/1041 shows your invoice, an attacker just tries 1040, 1039, and so on, and reads every customer’s invoice. The same applies to baskets, messages, profiles, and uploads. It needs no special tools, just curiosity, which is why it leaks data so often.
How do I know if I have it?
Log in as one user, note an object id, then request that object while authenticated as a different user.
- If you get the other user’s data back, you have an IDOR.
- Sequential or guessable ids (1, 2, 3) make it worse, but even random ids are not a fix on their own.
- Scanwright’s agent does exactly this test across your endpoints and proves which ones leak.
Check ownership on the server for every object you return or modify. The rule is simple: never trust the id from the request alone; confirm the signed-in user is allowed to touch that specific object. In Supabase, RLS enforces this for you at the database layer.
- For every read or write, scope the query to the current user, not just the requested id.
- On custom APIs, load the object and verify its owner matches the session before returning it.
- In Supabase, enable RLS so the database refuses rows that are not the user’s.
- Re-test by requesting another user’s object and confirming you get denied.
// Bad - trusts the id from the URL
const invoice = await db.invoice.findUnique({ where: { id } });
return invoice;
// Good - the object must belong to the signed-in user
const invoice = await db.invoice.findFirst({
where: { id, userId: session.user.id },
});
if (!invoice) return new Response('not found', { status: 404 });
return invoice;
FAQ
Do random UUIDs fix IDOR?
No. Hard-to-guess ids make bulk scraping slower, but ids leak through the app all the time (links, exports, referrers). The real fix is an ownership check on every request.
Does Supabase RLS solve this?
Yes, when it is enabled with correct policies. RLS makes the database itself refuse to return rows that are not the user’s, which stops IDOR at the source.