Authentication is not authorization
Authentication establishes who is making a request. Authorization determines whether that identity may perform a specific action on a specific resource. A valid session or API token does not imply access to every record.
Establish identity once
Verify credentials at a trusted boundary and create a request-scoped identity object. Validate token issuer, audience, expiry and scope when using bearer tokens. Never accept a user ID from the request body as proof of identity.
Authorize the resource
Check permissions using both the actor and the target resource. For tenant-owned data, include tenant scope in the repository query. Avoid fetching an unrestricted record and relying on the frontend to hide unauthorized actions.
Deny by default
Define route-level requirements and resource-level policies. New endpoints should not become public simply because an authorization check was forgotten. Use explicit policy methods and test both allowed and denied cases.
Return safe errors
Use appropriate status codes without exposing whether sensitive resources exist when that would leak information. Log denied access with a correlation ID and minimal context; do not log bearer tokens.
Checklist
- Separate authentication from authorization.
- Derive identity from verified credentials.
- Check permissions for every resource operation.
- Enforce tenant boundaries in data access.
- Deny by default.
- Test horizontal and vertical privilege escalation.
- Never log credentials.
References
OWASP Authorization Cheat Sheet · OWASP REST Security Cheat Sheet