An accountant at a customer company opens an invoice from an email link, mistypes one digit in the address bar, and gets another company's invoice: its name, its address, every line item. She reports it to support, a little alarmed. The endpoint required a login, and she was logged in. The app only ever listed her own company's invoices. Nobody had asked the one question that mattered: is invoice 1043 hers?
The common misconception
The belief: once a request is authenticated, you can trust the IDs it sends. The login proved who the user is, and the app only shows them links to their own data.
It's an easy belief, because each part sounds reasonable. Frameworks make authentication a one-liner: add [Authorize] or RequireAuthorization() and anonymous requests get a 401. The screens are built for honest users, so testers never see another tenant's data. And the IDs feel internal: they come from your database, travel in your own links, and are often long GUIDs nobody could guess. But a logged-in attacker is still an attacker, now with a valid session and full control over every byte of the request.
OWASP's Authorization Cheat Sheet draws the line: is distinct from authentication, and "A user who has been authenticated (perhaps by providing a username and password) is often not authorized to access every resource and perform every action that is technically possible through a system." It also names the abuse logged-in users are best placed for: "Horizontal privilege escalation (i.e. being able to access another user's resources) is an especially common weakness that an authenticated user may be able to take advantage of."
The ID in the request is input
The OWASP Top 10 2025 keeps Broken Access Control at A01, and its page reports that "100% of the applications tested were found to have some form of broken access control." One of the common failures it lists is "Permitting viewing or editing someone else's account by providing its unique identifier (insecure direct object references)".
The IDOR Prevention Cheat Sheet breaks an into three ingredients: an object, a reference to it ("an ID, UUID, account number, token or slug"), and "A missing object-level authorization check". The reference can sit in the path, the query string, a hidden form field or a JSON body. Hiding it in the UI changes nothing, because the attacker doesn't need your UI. The A01 page shows the classic case: when access control lives only in front-end JavaScript, the attacker "can simply execute" curl against the URL from the command line.
[Authorize] runs before the record exists
An endpoint-level check can only decide what it knows before the handler runs: is there a user, do they have a role. Microsoft's docs explain why that isn't enough: "Attribute evaluation occurs before data binding and before execution of any method that loads a resource. Declarative authorization with an [Authorize] attribute doesn't suffice for resource-based authorization." The decision about invoice 1043 can only be made once you know whose invoice it is.
Unguessable IDs aren't access control
GUIDs make guessing harder, and OWASP suggests them as defense in depth. But IDs leak: into logs, browser history, screenshots, support tickets and shared links. The cheat sheet is clear: "even with complex identifiers, access control checks are essential. If attackers obtain URLs for unauthorized objects, the application should still block their access attempts."
Scope the lookup to the caller
C# · Program.cs
app.MapGet("/invoices/{id:int}", async (int id, BillingDb db) =>{ // Logged in, so any invoice id is accepted var invoice = await db.Invoices.FindAsync(id); return invoice is null ? Results.NotFound() : Results.Ok(invoice);}).RequireAuthorization();
C# · Program.cs
app.MapGet("/invoices/{id:int}", async ( int id, ClaimsPrincipal user, BillingDb db) =>{ // The tenant comes from the signed-in user, never from the request var tenantId = user.FindFirstValue("tenant_id"); var invoice = await db.Invoices.SingleOrDefaultAsync( i => i.Id == id && i.TenantId == tenantId); // Another tenant's invoice and a missing one get the same 404 return invoice is null ? Results.NotFound() : Results.Ok(invoice);}).RequireAuthorization();
Both versions require a login. Only the second asks whose invoice it is, and it asks inside the query, the pattern the IDOR cheat sheet prefers: "a lookup limited to documents owned by the current user." Returning 404 in both cases is deliberate. When the existence of a record is itself sensitive, OWASP's advice is to "map both cases to the same public response, such as a 404 (Not Found) response."
When the rule is richer than ownership, such as "only the assigned approver can approve" or "paid invoices are read-only", ASP.NET Core offers resource-based authorization: load the object, then call IAuthorizationService.AuthorizeAsync(user, invoice, "PolicyName"), and let one handler make the decision everywhere. That matches the A01 advice to "Implement access control mechanisms once and reuse them throughout the application".
Defense
Stops IDOR?
Why
RequireAuthorization() on the endpoint
No
It proves there's a user, before any record is loaded
Only showing the user's own links
No
Attackers send requests with curl, not through your UI
Random GUIDs instead of 1, 2, 3
No, it only slows guessing
IDs leak through logs, history and shared links
A role check such as "Customer"
No
Two customers have the same role
A lookup scoped to the caller's tenant
Yes
The record is found only if it's theirs
How to apply it in your project
List every endpoint that takes an IDPath, query string, body and headers. Include file downloads, exports, bulk actions and webhooks that look records up.
Scope the query, not the responseFilter by owner or tenant inside the query, using the identity from the token. For multi-tenant data, an EF Core on the tenant makes that the default; Microsoft says it "provides strong tenant isolation for your queries by default".
Write the richer rules oncePut rules like approvers, states and team membership in resource-based authorization handlers, and deny by default. The A01 page puts it plainly: "Except for public resources, deny by default."
Add two-user tests to CIFor every endpoint with an ID, assert that user B gets a 404 or 403 for user A's records, on reads and on writes.
Log denied accessA01 recommends you "Log access control failures, alert admins when appropriate (e.g., repeated failures)." A user walking through IDs one by one shows up fast in those logs.
Key takeaways
Authentication tells you who the caller is; authorization decides what they may do with each record.
Every ID in a request is attacker-controlled input, whether it's in the URL, a hidden field or the body.
[Authorize] runs before the record is loaded, so it can't make object-level decisions.
GUIDs slow guessing down, but only a server-side check on the specific object stops IDOR.
Scope lookups to the caller, centralize richer rules, and test every endpoint as two users.
التعليقات (0)