Last updated
Last updated
This page contains recommendations for implementing authorization.
You can use Role-Based Access Control (RBAC) approach to implement authorization if having a particular role by a user is sufficient to grant access.
Use Attribute-Based Access Control (ABAC) approach to implement authorization if it is necessary to provide more granular access.
Give the minimum level of permissions that is necessary to complete an assigned operation.
Give permissions only for a minimum amount of time that is necessary to complete the operation.
Deny access by default. Grant required permissions only after successfully validating an access control policy.
Check permissions on every action. Make sure that a user or process has the necessary permissions before performing any action.
Take a consistent permission validation approach and implement it at the same application level. Do not spread this functionality over different levels.
Create unit and integration tests that validate enrolled access control policy.
Make sure that the permissions mapped out in accordance with business flows are being correctly enforced.
Create tests based on the actors (users) and objects involved in the authorization process.
Create tests that explicitly check that certain actions can not be performed by specified actors (users).
Avoid exposing identifiers to users when possible. For example, use /user/orders
instead of /users/1337/orders
to fetch orders for a current user.
Do not provide access based on knowledge of an entity ID. Even if an ID is long and random enough to be unguessable, always check permissions before providing access.
Make sure static content is covered by access control policy when appropriate.
Do not reveal the existence of a requested resource via the HTTP response code. Return 404 Not Found
if an authorization check fails. 403 Forbidden
might be appropriate if you need to display a specific message to a user about why they can not access a resource.
Regularly review an access control policy to avoid "privilege creep" and possible abuse of a policy for privilege escalation.
Document an access control policy. It must include each user role, actions that an application supports, and permissions that are required to perform those actions.
Handle all exceptions, errors and authorization failures no matter how unlikely they seem, see the page.
Log authorization attempts, at least authorization failures and operations requiring elevated privileges, see the page.