Skip to content

API security: the most common mistakes

B2Bnetwork team · · 6 min

Security

In brief

The most common API security mistake is failing to check whether a user has the right to the specific object they point to in a request. The OWASP API Security Top 10 2023 puts it first, followed by authentication flaws, property and function authorization, missing resource limits, and a weak version inventory. The common denominator: the API trusts the client more than it should. Most of these flaws can be caught with ordinary automated tests using a few accounts.

Why APIs get their own list

An API has no interface that constrains the user. A mobile app shows only your policies, but the API it uses will accept any request anyone sends. That is why OWASP maintains a separate list of API risks. The 2023 edition looks like this:

CodeRiskIn short
API1Broken Object Level Authorizationno check of the right to a specific object
API2Broken Authenticationweak authentication, tokens, password reset
API3Broken Object Property Level Authorizationaccess to properties the user should not see or change
API4Unrestricted Resource Consumptionno limits on requests, size, and cost of operations
API5Broken Function Level Authorizationaccess to administrative functions from a user role
API6Unrestricted Access to Sensitive Business Flowsno protection for processes that can be abused at scale
API7Server Side Request Forgerythe server fetches an address supplied by the client
API8Security Misconfigurationconfiguration, CORS, error messages, no TLS
API9Improper Inventory Managementold versions and undocumented endpoints
API10Unsafe Consumption of APIsuncritical trust in responses from other APIs

The list partly overlaps with the general OWASP Top 10, but the emphasis is distributed differently. In a web application, some flaws are stopped by the interface and the browser session. In an API, the client is a program that can send thousands of requests per minute, with arbitrary identifiers and properties. That is why as many as three items concern authorization, and two concern limits and process abuse.

Authorization of objects, properties, and functions

The three authorization items (API1, API3, API5) account for most serious findings in tests.

Object

A request `GET /policies/48213` must return the policy only if it belongs to the customer in the token or if the agent has permission for it. The check happens on the server side, on every request, ideally in one place in the code, for example in a data access layer that always filters by owner. Unpredictable identifiers, such as UUIDs, make guessing harder but do not replace permission checks.

Property

The API returns the whole object from the database, while the application displays only three properties. The rest, for example the customer's internal risk score, still ends up in the response. In the other direction: the API accepts a whole object on update, so a client can add a `role` or `limit` property. The defense is explicit input and output schemas for every endpoint, rather than mapping a database object one to one.

Function

Administrative endpoints are sometimes hidden only because the application does not call them. Every function has roles assigned, and the default response for a role without permission is a denial.

Limits and business processes

Missing limits (API4) are not only an overload risk. An endpoint that sends an SMS with a code incurs a cost on every call. An export endpoint without pagination lets a single request download the entire database. Basic safeguards are request limits per client and per user, a maximum page and payload size, operation timeouts, and separate, lower limits for expensive operations.

Business processes (API6) require thinking about abuse, not a technical error. Examples: bulk checking whether a phone number has an account with an operator, bulk reservation of goods in a promotion, automated account creation for a bonus. The defense depends on the process: limits per identity, bot detection, extra confirmation for an unusual pattern.

Inventory, versions, and other people's APIs

An old API version (API9) often keeps running because “one partner still uses it”, and it lacks the fixes made in the new one. The basis is an inventory: every endpoint has an owner, an OpenAPI specification, an environment, and a retirement date. An API gateway that lets through only documented paths makes an endpoint outside the inventory unavailable altogether.

Treat other people's APIs (API10) like user input. A response from a partner system, a credit bureau, or a currency rate service is validated against a schema, has a size and time limit, and redirects are disabled or restricted to known hosts.

How to test APIs in a team

Most flaws on the list can be detected automatically if the tests have several accounts and know the specification:

  1. A permission matrix. For each endpoint, a table: role, own resource, someone else's resource, expected result. The tests go through the whole matrix on every release.
  2. Response schema tests. The response contains no properties outside the specification. API contract tests help here.
  3. Limit tests. A series of requests above the limit ends with a 429 response, and a page above the maximum is truncated.
  4. Comparing the inventory with traffic. Endpoints visible in gateway logs that are not in the specification go to be explained.
  5. A DAST scan with an OpenAPI file and a penetration test once a year, described in the articles SAST, DAST, and SCA and Penetration testing vs. vulnerability scanning.

API authentication is usually based on OAuth 2.0, whose typical mistakes we describe in the article OAuth 2.0 and OpenID Connect demystified. How to test APIs for external partners is shown in the scenario an API platform for comparison sites and multi-agencies.

Questions and answers

Does an API gateway solve security problems?

A gateway helps with authentication, limits, inventory, and blocking unknown paths, but it does not know whether a client has the right to a specific policy or account. Object-level authorization must be in the service code, because only the service knows the relationship between the user and the data.

Does GraphQL have the same problems as REST?

Yes, and some are harder. A single GraphQL query can reach many objects and properties, so authorization must be checked at the level of every property and object. Query depth and complexity limits come on top. We describe the differences between API styles in the article REST, GraphQL, or gRPC.

Do internal APIs need securing too?

Yes, because an attacker who takes over one service on the internal network will use internal APIs without restrictions. Services should authenticate each other, for example with a client credentials token or through mTLS, and object authorization applies to internal calls as well. This is one of the principles of the zero trust approach.

How do you start if you have hundreds of endpoints?

With inventory and risk: list endpoints from gateway logs, mark those that return personal or financial data, and write permission matrix tests for them. Cover the rest with a DAST scan using an OpenAPI file. That way you protect the most valuable data first, and coverage grows with every sprint.

What it looks like in a project

Want to check your application's security? Talk to an engineer.

Let's talk

Read more: Security