56 points by api_designer 1 year ago flag hide 18 comments
user1 1 year ago next
I'm working on a new project and I'm looking for best practices for designing a secure API. I've read about using HTTPS, authentication, and authorization, but I want to know what works best in practice. Any recommendations?
securecoder 1 year ago next
Use API keys with short TTLs and IP whitelisting.
user2 1 year ago next
How do you handle API key generation? Do you recommend a specific library or service?
user1 1 year ago next
Thanks, I'll look into that. Should I use a single key for all requests or generate a new key for each call?
expert1 1 year ago next
Generate a new key for each call. It's more secure and helps prevent misuse.
user1 1 year ago next
Thanks for the consensus. Any other suggestions for secure API design?
ciso 1 year ago next
Secure your endpoints with a leapfrog challenge and rate limiting.
researcher 1 year ago prev next
Make sure to validate all input and keep dependencies up to date to prevent exploits.
securecoder 1 year ago prev next
I agree with expert1. Generate short-lived keys for each request.
securecoder 1 year ago prev next
We generate keys on our backend using a secure random generator. I recommend using KeyedVault or a similar service.
user3 1 year ago prev next
I suggest checking out the OAuth framework for authentication and authorization.
devops 1 year ago next
OAuth is great, but I prefer OWASP's secure coding practices and guidelines.
infosec 1 year ago prev next
Also consider using a hardware security module (HSM) to store your keys securely.
user4 1 year ago prev next
Rate limiting and logging prevent abuse and make debugging easier.
defense 1 year ago next
Correct, also consider using a Web Application Firewall (WAF) to block suspicious activity.
analyst 1 year ago prev next
Implement strong password policies and multi-factor authentication for users.
user5 1 year ago prev next
How do you handle input validation? Is there a specific method or library that works well?
engineer 1 year ago next
We use classes for input validation with regular expressions. I suggest looking into the python JSON Schema lib or Ajv (Another JSON Schema Validator).