Security Considerations for REST API Developers
Author(s):
Muhammad Akbar
Publish date: Jun 19, 2019
Publish date: Jun 19, 2019
Below are a few important security considerations relevant for REST API developers.
- Use TLS.
- Implement authentication.
- Enforce authorization/rbac (role based access control).
- Don’t use cookies. Use custom header for Authentication.
- Don’t run service as root user.
- Don’t use CORS. If you must use CORS, restrict the allowed headers, the allowed methods, don’t allow credentials passing and if possible, restrict the origin.
- Don’t make any state changes in a GET request.
- Always specify content type in response. Preferably, only use json (or xml).
- If you use any OSS, update it regularly.
- Don’t accept any sensitive data in query parameters in URL.
- Make sure your builds are reproducible (fix your dependencies). For example, don’t use something like npm or latest tag in maven, etc.
- If you are making any connections from server side to another endpoint, always validate SSL certificates.
- Be aware of java deserialization attacks (if you are using Java).
- Be aware of XML issues (if you are consuming XML), e.g. use defusedxml in python.
- Never return any secrets/passwords.
- Never log any sensitive information such as session ids, tokens, passwords etc.
- Be very careful when using regexes for RBAC on URLs. Never use wildcard in the beginning or middle of path.