liveBook · Manning

Insecure direct object reference

As explained in ASP.NET Core in Action, 3e

An insecure direct object reference is a security vulnerability in which a user gains access to an unauthorized resource by manipulating a direct identifier in a request URL or other input.

An insecure direct object reference (IDOR) occurs when a user changes a direct identifier in a request and reaches a resource they should not access. Exposing database IDs in URLs makes this especially easy when identifiers follow predictable patterns. section 29.4.3 section 24.5

Changing a recipe ID

A recipe application displays an edit link such as /Recipes/Edit/120. A user changes it to /Recipes/Edit/121. If the application allows editing or viewing a recipe the user does not own, it has an IDOR vulnerability. Hiding the Edit button does not prevent the user from entering the URL directly. section 29.4.3

Prevent IDOR by enforcing authorization on the requested resource:

  • Load the requested entity, determine its ownership or access information, and authorize the current user inside the endpoint handler. section 24.5
  • Return a permission-denied error when the user is not authorized; do not rely on hidden or disabled interface elements. section 29.4.3 section 29.5
  • Treat GUIDs as a way to make guessing harder, not as a replacement for authorization checks. section 29.4.3
Listing 24.13 The Edit.cshtml page must load the Recipe
public IActionResult OnGet(int id)             #1
{
    var recipe = _service.GetRecipe(id);       #2
    var createdById = recipe.CreatedById;      #2
    // Authorize user based on createdById     #3
    if(isAuthorized)                           #4
    {                                          #4
        return View(recipe);                   #4
    }                                          #4
}
#1 The id of the recipe to edit is provided by model binding.
#2 You must load the Recipe from the database before you know who created it.
#3 You must authorize the current user to verify that they’re allowed to edit this specific Recipe.
#4 The action method can continue only if the user was authorized.

Shows the endpoint flow: bind the requested ID, load the resource, authorize the user, and continue only after authorization succeeds. section 24.5

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the attack pattern, demonstrates identifier substitution, and prescribes resource-based authorization while stopping short of implementation details beyond endpoint flow.
Examples
Uses a recipe editor where changing /Recipes/Edit/120 to /Recipes/Edit/121 tests access to another entity.
What it assumes
Assumes familiarity with URLs, database entity identifiers, users, and endpoint handlers.
What you can do after
Diagnose IDOR by testing alternate resource identifiers and prevent it with authorization checks in endpoint handlers.
How it connects
Connects insecure direct object references with resource-based authorization, UI access control, database identifiers, and GUIDs.

Also explained in

Compare how 2 books explain insecure direct object reference →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.