Why it matters
A system that knows who you are has not decided what you may see. The common failure is an endpoint that authenticates the caller and then trusts an identifier from the request, so changing a number returns someone else's data. Authorisation has to be evaluated against the specific object and the caller's current entitlements, which is a different code path from verifying a token and needs its own tests.
Mental model
Authentication is the passport check at the border; authorisation is the visa that says where you may travel and for how long. The analogy breaks because a visa is checked once, while permissions change during a session and must be re-evaluated for every object a request touches.
How it works
- 1Separate the concerns in code: one middleware resolves identity, another resolves permission for a named action on a named resource.
- 2Model permissions as actions on resources, then map roles to permissions rather than checking role names inline.
- 3Enforce object-level checks in the data access layer, so a query cannot return rows the caller may not see.
- 4Deny by default and require an explicit allow for every route, including internal and admin endpoints.
- 5Keep the decision close to the data, and log it with subject, action, resource and outcome.
- 6Test with a matrix of identities against resources, including a second tenant and an expired entitlement.
Step 1 of 6
Separate the concerns in code: one middleware resolves identity, another resolves permission for a named action on a named resource.
Figure. The mechanism in this page's own steps. The figure adds sequence, not new claims.
What to notice. A step can be read alone, but the order is the mechanism. The control lets you stop on any one.
Text version
The page's steps: 1. Separate the concerns in code: one middleware resolves identity, another resolves permiss… 2. Model permissions as actions on resources, then map roles to permissions rather than chec… 3. Enforce object-level checks in the data access layer, so a query cannot return rows the c… 4. Deny by default and require an explicit allow for every route, including internal and adm… 5. Keep the decision close to the data, and log it with subject, action, resource and outcom… 6. Test with a matrix of identities against resources, including a second tenant and an expi…
- Separate the concerns in code: one middleware resolves identity, another resolves permission for a named action on a named resource.
- Model permissions as actions on resources, then map roles to permissions rather than checking role names inline.
- Enforce object-level checks in the data access layer, so a query cannot return rows the caller may not see.
- Deny by default and require an explicit allow for every route, including internal and admin endpoints.
- Keep the decision close to the data, and log it with subject, action, resource and outcome.
- Test with a matrix of identities against resources, including a second tenant and an expired entitlement.
Trade-offs
| Choice | Good for | Cost | Fails when |
|---|---|---|---|
| Role-based access control | Simple to reason about and audit | Role explosion as the product grows | Permissions depend on attributes or ownership |
| Attribute-based access control | Fine-grained and contextual | Complex policy and harder debugging | The policy language is unmanaged |
| Permissions in the token | No lookup per request | Stale until the token expires | Revocation must be immediate |
| Central policy service | Consistent decisions | A dependency on the request path | The latency budget is tight |
Good for
Simple to reason about and audit
Cost
Role explosion as the product grows
Fails when
Permissions depend on attributes or ownership
- Permissions depend on attributes or ownership
- The policy language is unmanaged
- Revocation must be immediate
- The latency budget is tight
Figure. Each choice with what it buys, what it costs, and the case where it loses.
What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.
Text version
Four trade-offs: Role-based access control is good for Simple to reason about and audit, costs Role explosion as the product grows, and fails when Permissions depend on attributes or ownership. Attribute-based access control is good for Fine-grained and contextual, costs Complex policy and harder debugging, and fails when The policy language is unmanaged. Permissions in the token is good for No lookup per request, costs Stale until the token expires, and fails when Revocation must be immediate. Central policy service is good for Consistent decisions, costs A dependency on the request path, and fails when The latency budget is tight
Failure modes
- Insecure direct object reference. A caller changes an id and reads another tenant's record. Debug: run the endpoint with a second tenant's identifier and assert a not-found or forbidden response.
- Role check instead of permission. A role name implies access to a resource it should not include. Debug: enumerate routes by required permission and diff against the role map.
- Stale token permissions. A revoked user keeps access until the token expires. Debug: measure the window between revocation and rejection, and shorten it with a session check.
In production
Log every authorisation decision with subject, action and resource, and alert on a spike in denials for one subject, which often means a broken policy rather than an attack. Review role assignments on a schedule, not only at creation.
Common misconceptions
People think: Authentication is enough if the interface hides the button.
Actually: Hidden interface elements are not a control; the endpoint is reachable and must decide for itself.
People think: A signed token is an authorisation system.
Actually: A token carries claims; the service still has to decide whether those claims permit this action on this resource.
Interview angle
Keep the two checks separate and put the authorisation decision next to the data, with an object-level test. Explain why a token claim is not a decision. Naming a role and trusting a hidden interface element is the weak answer.
Sources
- OWASP, Authorization Cheat Sheet — object-level checks and deny-by-default practice.
- NIST SP 800-63, Digital Identity Guidelines — identity assurance and authenticator requirements.