IDOR stands for Insecure Direct Object Reference. Put simply, the site fetches whatever record is requested without checking whether the requester owns it. Your cabinet shows your order at order.php?id=1001; change the number to 1002 and a stranger's name, phone and address appear. No special tools are needed, only the address bar, which is why IDOR is both common and one of the biggest sources of data leaks.
Why it is so common
Developers usually get authentication right: without logging in, the cabinet does not open. Authorization, the question "may this person see this particular record?", is what gets forgotten. The interface lists only the user's own orders, so the developer assumes nobody will type another number, but the server answers any request, and requests can be crafted by hand. IDOR is not limited to id: file names, invoice numbers, API paths like /api/users/57, hidden user_id fields and cookie values are all candidates, and the bug can affect editing and deleting as well as viewing.
Vulnerable and fixed code
The vulnerable version looks up a record by ID alone:
<?php
// order.php?id=1001 : VULNERABLE
$stmt = $pdo->prepare('SELECT * FROM orders WHERE id = ?');
$stmt->execute([$_GET['id']]);
$order = $stmt->fetch();
The fix puts the ownership condition into the query itself, takes the user ID only from the server-side session, and returns 404 when nothing matches, so an attacker cannot even tell whether the order exists:
<?php
session_start();
if (empty($_SESSION['user_id'])) {
http_response_code(401); exit;
}
$stmt = $pdo->prepare('SELECT * FROM orders WHERE id = ? AND user_id = ?');
$stmt->execute([(int)($_GET['id'] ?? 0), $_SESSION['user_id']]);
$order = $stmt->fetch();
if (!$order) {
http_response_code(404); // do not reveal whether the order exists
exit;
}
Updates and deletes follow the same rule; checking the affected row count tells you when someone tried to touch another user's record:
<?php
// Updating or deleting: the same rule, and check the affected row count
$stmt = $pdo->prepare('UPDATE addresses SET street = ? WHERE id = ? AND user_id = ?');
$stmt->execute([$_POST['street'], (int)$_POST['id'], $_SESSION['user_id']]);
if ($stmt->rowCount() === 0) {
http_response_code(404); exit;
}
Frameworks make this easier. In Laravel, query through the user's own relation or use a Policy:
// Laravel: look the record up through the user's own relation
$order = $request->user()->orders()->findOrFail($id);
Are UUIDs enough?
Replacing sequential numbers with long random UUIDs makes guessing harder but does not fix the bug. IDs leak through emails, browser history, server logs and shared links. A UUID can be an extra layer, never a substitute for checking ownership on every request.
Example: a school's electronic gradebook
A private school in Namangan gives parents a cabinet where grades appear at grades.php?student=318. One parent changes the number by accident and sees another child's grades, their parents' phone number and home address; the report download page turns out to work the same way. The developer adds one check to every page (is this student linked to the current parent?), a separate rule letting teachers see only their own classes, and reviews logs for mass requests. Children's personal data had been exposed without any hacking at all, just by editing a number.
Testing your site for IDOR
Use two test accounts. As user A, note the URLs of orders, files and profile pages; as user B, open the same URLs. If B can see or change A's data, you have IDOR. You can automate the check with curl:
# Log in as user B, copy the session cookie, then request user A's order
curl -s -o /dev/null -w "%{http_code}\n" \
-b "PHPSESSID=B_USER_SESSION" \
"https://example.uz/cabinet/order.php?id=1001"
# Expected: 404 or 403, never 200
- List every identifier in URLs, forms and API calls.
- Test view, edit, delete and download separately.
- Try changing hidden
user_idorrolevalues. - Alert when one session walks through many IDs in a row.
If your site on sayt.uz hosting stores customer data behind a login, run this check before launch; a few hours of testing can prevent a serious leak.