Change the invoice id: an IDOR test you can finish in ten minutes
You are logged in as user A and the invoice page lives at /invoices/1042. Change the number to 1043 and the page shows a stranger's invoice. That is an insecure direct object reference, and it is still one of the most co
You are logged in as user A and the invoice page lives at /invoices/1042. Change the number to 1043 and the page shows a stranger's invoice. That is an insecure direct object reference, and it is still one of the most common access control bugs in web apps and APIs.
The test takes ten minutes. Doing it properly takes a little discipline.
Use two accounts, not one guess
Create two test users. Log in as A, open an invoice, and copy the request. Log in as B and replay A's request with B's session cookie. If B gets A's data, you have a finding. If you only change an id while logged in as A, you may just be reading your own records through a different path and calling it a bug.
Read the status code, then the body
A 403 is a clean answer. A 404 is also fine; some apps use it to avoid confirming an id exists. A 200 with an empty body, or a 200 with a "not found" message inside, can hide a bug or hide nothing. Compare the response length against a real invoice before deciding.
Check the other ids in the request too. The one in the URL is obvious. The one in a JSON body, a header or a second request that loads the invoice lines is where the check is often forgotten.
Keep notes as you go: the two accounts, the exact request, the response length for the owner and for the other user. A report that says "B can read A's invoice, same 2 KB response, tested with two accounts" is easy for a developer to reproduce. One that says "IDs are guessable" is not, and it will sit in a queue.
Sequential ids make this easy to exploit, but they are not the bug. If ids were random UUIDs and the ownership check were still missing, a leaked link would expose the same data. Test the check, not the format of the id.
What the fix looks like
Hiding ids behind random strings slows guessing and fixes nothing. The server has to check, on every request, that the logged-in user owns the object. A one-line query change, WHERE id = ? AND owner_id = ?, closes most of these.
Practise on something legal
The free IDOR lab on Codelivly has you change an id to read another user's invoice in a fictional app. The HelpHub IDOR challenge does the same against a support portal, with the fix explained afterwards.
When the same bug shows up in JSON APIs, with object ids in bodies and nested routes, the API Hacking Book for Beginners is the next step at 227 pages.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.