IDOR in AI-built apps: change one number in the URL and see someone else's data (a 5-minute two-account test)
IDOR stands for insecure direct object reference. It means your app returns or changes a record because the user asked for its ID, without checking that the record belongs to them. If /api/invoices/1042 works for anyone
IDOR stands for insecure direct object reference. It means your app returns or changes a record because the user asked for its ID, without checking that the record belongs to them. If /api/invoices/1042 works for anyone who is logged in, then /api/invoices/1043 probably shows someone else's invoice. AI-generated apps ship this often, because the code that "gets the invoice by id" is simple and the ownership check is an extra line nobody asked for.
1. The pattern to look for
Unsafe:
app.get("/api/invoices/:id", requireLogin, async (req, res) => {
const invoice = await db.invoice.findUnique({ where: { id: req.params.id } });
res.json(invoice);
});
Safer:
const invoice = await db.invoice.findFirst({
where: { id: req.params.id, userId: req.user.id },
});
if (!invoice) return res.status(404).end();
2. Where it shows up
- Read routes: invoices, orders, messages, files, profiles
- Update and delete routes:
PATCH /api/projects/:id,DELETE /api/posts/:id - File downloads by ID or by guessable file name
- Sequential numeric IDs, which make guessing easy
- Direct database reads from the browser, where the row policy only checks "is logged in"
3. A 5-minute two-account test
- Create two test accounts in your own app, A and B.
- As A, create a record and copy the URL or request that fetches it.
- Sign in as B and send the same request with A's record ID.
- If B gets A's data, or can change or delete it, you have an IDOR.
- Repeat for reads, edits and deletes on every resource type.
Only test your own app with your own accounts.
4. Fixes that hold up
- Put the owner check in the query itself, as in the safer example.
- Return 404, not 403, for records the user does not own, so IDs are not confirmed.
- Use random IDs (UUIDs) as a second layer. They slow guessing, they do not replace the check.
- On Supabase or Firebase, write row-level policies that compare the row owner to the signed-in user.
- Add one automated test that fetches user A's record as user B and expects a 404.
What an outside scan can and cannot tell you
A scan that never signs in cannot see records behind a login, so it cannot confirm or rule out IDOR. That is why the two-account test above matters. Treat a clean outside scan as one piece of the check, not the whole audit.
Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.