API Security Checklist

2 min read

A security checklist to make sure of your API safety

API security is probably one of the most important aspects that you, as a developer, can think of before releasing your API.

Well, our team came up with an API security checklist that can help you tremendously in your process.

This checklist focuses mainly in API security. It can help you track and adopt the most important security countermeasures when designing, testing and releasing your API.


8 steps to secure your API

  1. Authentication
  2. JWT (JSON Web Token)
  3. OAuth
  4. Access
  5. Input
  6. Processing
  7. Output
  8. CI & CD

1. Authentication

  • Don’t useBasic Auth. Use standard authentication (e.g. JWTOAuth).
  • Don’t reinvent the wheel inAuthentication,token generation,password storage. Use the standards.
  • UseMax Retryand jail features in Login.
  •  Use encryption on all sensitive data.

2. JWT (JSON Web Token)

  •  Use a random complicated key (JWT Secret) to make brute forcing the token very hard.
  •  Don’t extract the algorithm from the payload. Force the algorithm in the backend (HS256 or RS256).
  •  Make token expiration (TTLRTTL) as short as possible.
  •  Don’t store sensitive data in the JWT payload, it can be decoded easily.

3. OAuth

  •  Always validate redirect_uri server-side to allow only whitelisted URLs.
  •  Always try to exchange for code and not tokens (don’t allow response_type=token).
  •  Use state parameter with a random hash to prevent CSRF on the OAuth authentication process.
  •  Define the default scope, and validate scope parameters for each application.

4. Access

  •  Limit requests (Throttling) to avoid DDoS / brute-force attacks.
  •  Use HTTPS on server side to avoid MITM (Man in the Middle Attack).
  •  Use HSTS header with SSL to avoid SSL Strip attack.
5. Input
  •  Use the proper HTTP method according to the operation: GET (read)POST (create)PUT/PATCH (replace/update), and DELETE (to delete a record), and respond with 405 Method Not Allowed if the requested method isn’t appropriate for the requested resource.
  •  Validate content-type on request Accept header (Content Negotiation) to allow only your supported format (e.g. application/xmlapplication/json, etc.) and respond with 406 Not Acceptable response if not matched.
  •  Validate content-type of posted data as you accept (e.g. application/x-www-form-urlencodedmultipart/form-dataapplication/json, etc.).
  •  Validate user input to avoid common vulnerabilities (e.g. XSSSQL-InjectionRemote Code Execution, etc.).
  •  Don’t use any sensitive data (credentialsPasswordssecurity tokens, or API keys) in the URL, but use standard Authorization header.
  •  Use an API Gateway service to enable caching, Rate Limit policies (e.g. QuotaSpike Arrest, or Concurrent Rate Limit) and deploy APIs resources dynamically.
6. Processing
  •  Check if all the endpoints are protected behind authentication to avoid broken authentication process.
  •  User own resource ID should be avoided. Use /me/orders instead of /user/654321/orders.
  •  Don’t auto-increment IDs. Use UUID instead.
  •  If you are parsing XML files, make sure entity parsing is not enabled to avoid XXE (XML external entity attack).
  •  If you are parsing XML files, make sure entity expansion is not enabled to avoid Billion Laughs/XML bomb via exponential entity expansion attack.
  •  Use a CDN for file uploads.
  •  If you are dealing with huge amount of data, use Workers and Queues to process as much as possible in background and return response fast to avoid HTTP Blocking.
  •  Do not forget to turn the DEBUG mode OFF.

7. Output

  •  Send X-Content-Type-Options: nosniff header.
  •  Send X-Frame-Options: deny header.
  •  Send Content-Security-Policy: default-src 'none' header.
  •  Remove fingerprinting headers – X-Powered-ByServerX-AspNet-Version, etc.
  •  Force content-type for your response, if you return application/json then your response content-type is application/json.
  •  Don’t return sensitive data like credentialsPasswords, or security tokens.
  •  Return the proper status code according to the operation completed. (e.g. 200 OK400 Bad Request401 Unauthorized405 Method Not Allowed, etc.).

8. CI & CD

  •  Audit your design and implementation with unit/integration tests coverage.
  •  Use a code review process and disregard self-approval.
  •  Ensure that all components of your services are statically scanned by AV software before pushing to production, including vendor libraries and other dependencies.
  •  Design a rollback solution for deployments.

If you’re a GitHub fanatic, you can find our original repository here >  Api Security Checklist.

You can also join the discussion on HackerNewsReddit.


Follow us on facebook, twitter and linkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *