chapter eleven

11 Designing a secure API

 

This chapter covers

  • Exposing only the necessary data and operations
  • Ensuring operations behave according to context
  • Preventing protocol or infrastructure-based data leaks
  • Limiting access with security scopes
  • Erroring securely

An API that does the job and is user-friendly is nice but worth nothing if not secure. As APIs grew in popularity, the number of API attacks has increased exponentially over the years, making APIs the primary hacking attack vector in 2022. In 2023, 95% of organizations faced API security problems, such as DDoS attacks (Distributed Denial of Services), lack of authentication, API key leaks, shadow or zombie APIs no one knows of, sensitive data overexposure, or business logic abuse. API security issues can cause reputational damage, financial losses, business operations, and data privacy threats.

API designers can’t solve all API security issues, but they have a crucial role to play. API security must not be overlooked during the API design process, assuming security experts will handle it later. How we design and document an API can significantly influence its security. For example, if we’re not careful, a user buying products on our Shopping website via our Shopping API could discover the secret buying price of products by inspecting network traffic through developer tools, access other users' orders, or change the price of a product.

11.1 Overviewing API security

11.1.1 What happens during an API call

11.1.3 How API design contributes to API security

11.2 Exposing only the necessary data and operations

11.2.1 What is sensitive data or operation?

11.2.2 When and how to identify sensitive data or operations?

11.2.3 Challenging sensitive and non-sensitive data and operations

11.2.4 Modifying data to make it less- or non-sensitive

11.2.5 Splitting an operation to separate concerns

11.2.6 Separating sensitive operations in dedicated APIs

11.3 Ensuring operations behave according to context

11.3.1 Describing who sees or does what

11.3.2 Adapting design to narrow data for a specific task

11.4 Ensuring data integrity with conditional updates

11.5 Avoiding protocol- or architecture-based security issues

11.5.1 What may not be secured on an API call over HTTPS