---
title: "One number in the URL shows another user's data? Fix IDOR"
description: "IDOR happens when the server fetches a record by the ID in the request without checking that it belongs to the user. The fix is an access check on every object, with the user taken from the session, not the request."
url: https://ihsanalapsi.dev/articles/idor-object-access-check
lang: en
date: 2026-11-09
updated: 2026-11-09
tags: ["App security", "Web development"]
author: Ihsan Alapsi (إحسان العبسي)
---
# One number in the URL shows another user's data? Fix IDOR

You have an invoices page, and every invoice URL carries its number. A curious customer bumps that number up by one and gets another customer's invoice, with their name and address. No password cracked, no hacking tool: they changed a number. This article explains why that happens, how to test your site with two accounts, and where the line that fixes it goes.

## What is an IDOR vulnerability?

IDOR (Insecure Direct Object Reference) is a vulnerability where a user can read or change a record just by changing its identifier in the request, because the server never checks whether that record belongs to them.

The [OWASP IDOR Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Insecure_Direct_Object_Reference_Prevention_Cheat_Sheet.html) gives the simplest example: an account URL ending in `/users/123`, where an attacker changes the number to 124 and reaches another user's information. The cheat sheet puts the cause on a missing access control check, not on the number itself. The identifier does not have to sit in the URL either: it can be a hidden form field such as `user_id`, or a file name in a download request such as `GET /documents/financial-statement.pdf`.

## Why doesn't login alone protect you?

Login tells you who the user is, but not whether this particular record is theirs, and IDOR lives in the gap between those two questions.

That is why the [OWASP API Security Top 10 2023](https://api-security.owasp.org/editions/2023/en/0xa1-broken-object-level-authorization) puts this problem first, as API1:2023 Broken Object Level Authorization. One of its examples is an API that controls vehicles remotely by their Vehicle Identification Number (VIN) and never checks that the VIN belongs to the logged-in user, so an attacker can control vehicles they don't own. Another is a GraphQL mutation that deletes a document by its ID with no permission check, so one user deletes another user's document. In both cases the user is logged in normally, and the server trusted the ID it received.

## How do you test your site with two accounts?

The quickest IDOR test is to create two accounts and try to open the first account's records while logged in as the second.

1. Create two test accounts, call them A and B, and create a record in each: an order, an invoice, a file, an address.
2. Log in as A, open its record, and copy the URL. From the browser's developer tools (the Network tab), copy the API request that loaded the data.
3. Log in as B in a different browser, and open the same URL or send the same request.
4. If A's data shows up, you have an IDOR. If the request is refused, try updating and deleting the same record, because reads are often protected while writes are not.

The same OWASP list recommends writing tests that exercise the authorization mechanism, so turn this check into a test that runs with every code change.

## Where does the check go in the code?

The IDOR check goes into the query itself: the record is fetched by two conditions, its ID and its owner, and the owner is the user in the session, not an ID that came with the request.

The OWASP cheat sheet says to run an access control check for every object a user tries to reach, and to determine the current user from session information instead of taking their ID from the URL or the request body. Here is the mistake in Express, with the invoice fetched by its ID alone:

```javascript
app.get('/invoices/:id', requireLogin, async (req, res) => {
  const invoice = await db.invoice.findUnique({ where: { id: req.params.id } });
  res.json(invoice);
});
```

And here is the fix. The second condition ties the invoice to the session's user, and when nothing matches it returns the [404 Not Found status](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/404), which means the server cannot find the requested resource:

```javascript
app.get('/invoices/:id', requireLogin, async (req, res) => {
  const invoice = await db.invoice.findFirst({
    where: { id: req.params.id, userId: req.session.userId },
  });
  if (!invoice) return res.status(404).end();
  res.json(invoice);
});
```

The same goes for updates and deletes: the owner condition belongs inside the update statement itself, not in a read before it followed by an update by ID alone.

## Are UUIDs enough instead of sequential numbers?

1. A UUID makes it harder for an attacker to guess other people's IDs, but the access check on every record is still required.

The OWASP cheat sheet treats random identifiers as an extra layer of defense, and says plainly that access control checks are essential even with complex identifiers. The API list recommends random, unpredictable values (GUIDs) for record IDs, on top of a real authorization mechanism. The reason is practical: an ID ends up in a shared link, an email or the server logs, and then nothing protects the record except the check.

## Where do you start today?

Pick the most sensitive page on your site, such as invoices, orders or customer files, and run the two-account test on it today. Then search your code for every query that fetches a record by an ID from the request, and see whether it also has a condition on the session's user.

If you are reviewing the session itself, [check your session cookie flags](/articles/session-cookie-flags-check), because the access check relies on the session not being stolen. If your login page has a return link, see [how to close an open redirect](/articles/open-redirect-return-url). And if you want someone to test your platform the way an attacker would, every record and every request, that is the job of [Muhassan penetration testing](/muhassan).

On your site, how many URLs carry a record ID to the server without anyone asking whose record it is?

## FAQ

**If I use UUIDs instead of numbers, can I skip the access check?**

No. A random ID makes guessing harder, but OWASP says access control checks are still essential with complex identifiers, because an ID can leak through a link, an email or a log.

**Does IDOR only happen in APIs?**

No. It can happen anywhere an identifier comes from the user: a page URL, a hidden form field, a file name for download, or a GraphQL request.

**Is it enough to test reading only?**

No. Test updates and deletes too. The worst IDOR cases are the ones that let a user change or delete a record that is not theirs.
