Highlights

Contents

BACKEND ENGINEERING / UNIT IV / FIELD GUIDEAuthorizationand validationWhat this user may do, and whether this input makes senseuser 42order 123order 124admin panelpolicyevery request, every resource, checked on the serverModelsRBAC, ACL, ABAC, ReBACIDORownership on every objectValidationschema, semantics, attacksTenancyisolation and fairness
Before we start

How to read this chapter

Unit III proved who is calling. This unit decides what that caller may do, whether the data they sent makes sense, and which customer’s data they may touch. Most serious API breaches in the last decade failed one of these three checks, not authentication.

The unit has three threads. Parts I to IV cover authorization, from the basic rules through the access control models to the single most common API bug, IDOR, and the policy engines that centralise the rules. Parts V and VI cover input validation and the attacks that slip past weak validation. Parts VII and VIII cover multi-tenancy, where one backend serves many customer organisations that must never see each other’s data. Part IX traces one request through every check.

Each section opens with a concrete Wren situation, explains the mechanism, works an example with numbers and then shows a figure. Picture this boxes give analogies, notes add detail, Watch out names a real mistake, and Interview lens gives an answer to say aloud. In one breath closes each part.

By the end you should be able to look at any endpoint and list, in order, the checks it must perform and the status code each failure returns.

The running system

Meet Wren

Wren is the illustrative food-ordering service from earlier units. In this unit it is also a platform. Restaurants manage their menus and orders in a Wren dashboard, so each restaurant group is a tenant. All numbers are assumptions chosen for readable arithmetic.

Setting Value What it controls
Customer accounts 1,000,000 Size of role and permission tables
Restaurant tenants 2,000 Multi-tenancy design
Roles customer, restaurant manager, cook, courier, support, admin RBAC examples
Permissions 40 Role-permission table size
Orders 5,000,000, ids assigned in sequence IDOR enumeration example
Peak requests 2,000 per second Policy and cache load
Policy decision cache 30 s How long a revoked permission lingers
Body limit, JSON depth, array length 1 MB, 32, 100 items Input bounds
Money integer paise (1 rupee = 100 paise) Overflow example

The cast for this unit is user 42, a customer called Asha who also manages restaurant 9 for the Spice Group tenant, user 43, another customer, and an attacker who holds a perfectly valid Wren account of their own.

The map

What is inside

Draw how a request that is already authenticated is checked for permission, for sane input, and for the right tenant.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Authentication vsauthorization2Access control models3Resource ownership andIDOR4Policy engines andtesting5Input validation6Input attacks7Multi-tenancy models8Running a multi-tenantbackend9Authorization end to end
  1. 01Authentication vs authorizationSections 1 to 3. We separate proving who someone is from deciding what they may do, and set the ground rules for every check that follows.
  2. 02Access control modelsSections 4 to 8. We compare the four standard ways to express who may do what.
  3. 03Resource ownership and IDORSections 9 to 11. We look at the single most common real authorization bug in APIs, and the simple discipline that prevents it.
  4. 04Policy engines and testingSections 12 to 14. We move authorization rules out of scattered if-statements into one place that can be reviewed, cached and tested.
  5. 05Input validationSections 15 to 17. We learn how to decide whether data sent by a client is acceptable before the code acts on it.
  6. 06Input attacksSections 18 to 24. We study the specific ways attackers exploit weak input handling.
  7. 07Multi-tenancy modelsSections 25 to 27. We design how one backend serves 2,000 restaurant groups that must never see each other's data.
  8. 08Running a multi-tenant backendSections 28 to 30. We deal with what happens after tenants are isolated on paper but still share CPUs, connections, caches and queues.
  9. 09Authorization end to endSections 31 to 32. We follow one write request through every check from this unit, in the order a well-built backend runs them.
  10. +Interview prepInterview question bank, graded exercises and worked solutions.