Api Security
Api Security
@thisisnabi
4.61"
@moabukar
▪ Implement strong authentication mechanisms such as JWT (JSON Web Tokens), OAuth,
or OpenID Connect.
▪ Use secure password storage techniques, such as salted hashing or encrypt, to protect
user passwords.
▪ Consider implementing multi-factor authentication for sensitive operations or
privileged access.
▪ Protect against brute force attacks by enforcing account lockouts or rate limiting.
▪ Validate user roles or claims on the server-side before allowing access to sensitive
operations or data.
▪ Implement attribute-based authorization to enforce fine-grained access control at the
controller or action level.
▪ Validate and sanitize all input received from clients to prevent common attacks like
cross-site scripting (XSS), SQL injection, or command injection.
▪ Use parameter binding techniques that automatically validate input, such as model
binding or request validation.
▪ Avoid dynamic SQL queries or raw SQL concatenation and instead use parameterized
queries or an ORM (Object-Relational Mapping) tool.
▪ Enforce the use of HTTPS (TLS/SSL) to encrypt the communication between clients and
the API server.
▪ Disable or remove support for weak SSL/TLS protocols and ciphers to mitigate known
vulnerabilities (e.g., SSLv3, TLS 1.0/1.1, weak cipher suites).
▪ Implement HSTS (HTTP Strict Transport Security) to enforce HTTPS usage across all
requests.
▪ Validate and sanitize all input and output data, including query parameters, headers,
and request/response bodies.
▪ Apply output encoding or HTML encoding to prevent cross-site scripting (XSS) attacks.
▪ Implement structured error responses with appropriate HTTP status codes to indicate
the result of API requests.
▪ Monitor and analyze log data to detect anomalies or potential security breaches.
▪ Utilize intrusion detection and prevention systems (IDS/IPS) or security information
and event management (SIEM) tools for real-time threat detection and response.
▪ Apply rate limits based on client IP addresses, API keys, or user accounts to control the
number of requests per unit of time.
▪ Regularly update and patch all third-party libraries and dependencies used in your API
to mitigate known security vulnerabilities.
▪ Monitor security advisories and subscribe to notifications to stay informed about any
security patches or updates.
▪ Perform regular security testing, including vulnerability scanning, penetration testing,
and security code reviews, to identify and address potential security flaws.
▪ Conduct thorough security testing during the development lifecycle and before
deploying the API to a production environment.
▪ Use automated security testing tools, such as static analysis tools or dynamic
application security testing (DAST) tools, to identify common vulnerabilities and
security weaknesses.
▪ Regularly review and update security test cases and scenarios to account for emerging
threats and attack vectors.
While all the items in the checklist are important, these five items form
the core pillars of securing a Web API.