Course contentsShow
← Security
Lesson 843 of 3,05217. Web Security - Authorization and Access ControlFree lesson

Indirect Object References

Use indirect object references and access tokens instead of direct database IDs to prevent enumeration and tampering.

Indirect Object References

What you'll learn: How to hide internal identifiers by using unpredictable tokens instead of exposing database IDs directly to users.

The Problem with Direct References

When your application uses database IDs directly in URLs or requests, attackers can easily guess other valid IDs. For example, if viewing invoice 123 shows /invoice?id=123, an attacker will try 124, 125, and so on to access others' data.

How Indirect References Work

Instead of exposing the real database ID, you create a mapping between an unpredictable reference token and the actual resource. Think of it like a coat check: you don't label coats with sequential numbers visible to customers. Instead, you hand out random claim tickets that only the coat check system can match to the right coat.

Implementation Approach

  1. Generate unpredictable tokens (random strings, UUIDs, or session-specific mappings)
  2. Store the mapping between tokens and actual database IDs (in session, cache, or database)
  3. Translate tokens server-side before accessing resources
  4. Still enforce access control — indirect references are not a substitute for authorization checks!

Example Flow

  • User requests their profile
  • Server generates token a7f3k9p2 → maps to user ID 42
  • URL becomes /profile?ref=a7f3k9p2
  • On subsequent request, server looks up a7f3k9p2 → finds ID 42 → verifies user owns it → serves data

Defense in Depth

Indirect references make enumeration attacks much harder, but they're not a complete solution. Always combine them with proper authorization checks at the resource level. An attacker might still obtain a valid token through social engineering or other means.

Key Takeaway: Replace predictable database IDs with unpredictable tokens or session-specific mappings to prevent enumeration attacks, but always validate authorization regardless of the reference type used.