- Guidelines and Recommendations for Handling OAuth API Access Tokens
This document provides guidelines and recommendations for handling OAuth API tokens for the Metadata Bank API. Security is paramount, and the following practices ensure that tokens are managed securely and efficiently. This document is in adherence to CISA/DOD and the IETF best practice documentation 1.This guideline will mitigate OWASP's top 10 CI/CD security risks 1. While the majority of the content was authored by the Metadata Bank API Team, it incorporates valuable contributions and expert security guidance from our Cybersecurity Team.
- Environment Variables: Store the consumer key and secret in environment variables or a secure configuration manager.
- Automate the discovery of secrets: Use a centralized management tool and a secret vault to store various credentials1.
- Avoid Hardcoding and embedded secrets: Never hardcode these values within your codebase.
- Use Encryption: If storing in a file, make sure the file is encrypted and accessible only to authorized applications and users.
- Use Strong Encryption Algorithms: Encrypt tokens using robust algorithms like AES.
- Key Management: Manage encryption keys securely, rotating them periodically.
- Use HTTPS: Always transmit tokens over HTTPS to ensure they are encrypted during transit2.
- Use TLS: Use a minimum of TLS 1.2 to send keys, secrets, and tokens1.
- Validate Tokens: Validate tokens on the server-side to ensure they are not tampered with.
- Use Short Expiration Times: Set short expiration times (e.g., one hour).
- Implement Refresh Tokens: Use refresh tokens for obtaining new access tokens.
- Privilege Limitation: Access tokens should have the minimum privileges required for the specific application or use case1.
- Resource & Action Restriction: Access tokens should be limited to particular resource servers and actions on those resources1.
- Rotate and Revoke: Rotate tokens regularly and revoke old ones.
- Auto-Refresh Logic: Implement logic to refresh tokens automatically.
- Dynamic Token Refresh: Implement dynamic token refresh1.
- Graceful Error Handling: Handle refresh errors gracefully.
- Monitor and Log Securely: Monitor token refresh activities and log securely.
- Balance Security with Usability Ensure a smooth user experience.
- Follow Provider's Recommendations: Adhere to specific OAuth provider guidelines.
By following these guidelines and recommendations, you can ensure that OAuth API access tokens are handled securely and efficiently. Frequent token refreshing, secure storage, encryption, and compliance with best practices are essential to maintaining the integrity and confidentiality of the tokens.