Authorization
Overview
This page contains recommendations for implementing authorization.
General
- 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/ordersinstead of- /users/1337/ordersto 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. 
- Handle all exceptions, errors and authorization failures no matter how unlikely they seem, see the Error and Exception Handling page. 
- Do not reveal the existence of a requested resource via the HTTP response code. Return - 404 Not Foundif an authorization check fails.- 403 Forbiddenmight be appropriate if you need to display a specific message to a user about why they can not access a resource.
- Log authorization attempts, at least authorization failures and operations requiring elevated privileges, see the Logging and Monitoring page. 
- 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. 
References
Last updated