Almost every modern application depends on APIs to talk to the backend, and the data and business logic pass through them. That is why they are such a popular target. Contrary to what many people assume, the most common API problems are authorization flaws, not classic injection: a user who can read another user's data, or run a function that should be out of reach. The OWASP API Security Top 10 makes this clear: broken object level authorization is first on the list, and broken function level authorization is in the top five.
Everything that follows is seen from the defender's side. For each point an API pentest examines, the question is where the risk concentrates and what your team can do to reduce it, with no exploitation instructions.
Authentication and tokens
API authentication usually relies on JWT tokens or OAuth flows, and the problems are in the details: weak signature validation, expiration that is too long, no way to revoke the token and poorly stored secrets. Note that decoding a JWT is different from validating it. Anyone can decode the token and read the claims, the issuer and the expiration. The API, on the other hand, must check the signature, issuer, audience and validity on every request.
A long-lived token that cannot be revoked is dangerous, because if it leaks it stays valid for a long time in someone else's hands. Prefer short expiration with controlled renewal, and have a ready path to revoke compromised credentials.
Authorization: BOLA and BFLA
The most common API flaw, and the most costly, is broken object level authorization, known as BOLA. The API checks who the user is but does not verify whether that user has the right to the object requested. In practice, changing an identifier in the request (an order number, for example) is enough to receive someone else's data. The fix is to validate ownership of the resource on the server, on every request, without trusting the identifier that came from the client.
Broken function level authorization, or BFLA, is similar, except it involves administrative or privileged actions within reach of people who shouldn't use them. Hiding the button in the interface doesn't solve it, because the API still accepts the call. Every sensitive endpoint must check the caller's role on the server.
- Validate on the server, on every request, that the object belongs to the requester
- Check the role and permission in the backend before running sensitive functions
- Do not trust identifiers or flags sent by the client
- Apply the same access control to every method and version
Inventory, versioning and exposed surface
One cause of API incidents that almost nobody notices is losing track of which endpoints exist. An old version that was left running, a test endpoint published by mistake, a staging host open to the internet: these are the so-called shadow APIs and zombie APIs, which nobody monitors and which almost always have weaker controls. The problem is so frequent that the OWASP API Security Top 10 gives it its own entry, improper inventory management.
Defense starts with knowing what is exposed. Keep an up-to-date inventory of your APIs, with versions and environments, and use the specification (OpenAPI, for example) as the source of truth, so no endpoint falls outside governance. Test and production must stay separate, with no real data in the test environment. And a discontinued version has to actually be taken offline, because marking it as deprecated and leaving it running does not reduce the exposed surface.
- Keep an up-to-date inventory of APIs, versions and environments
- Take discontinued versions offline instead of just marking them as deprecated
- Separate test and production environments, with no real data in test
- Treat the specification as the source of truth and detect drift
Exposure, validation and abuse
APIs often return more data than the screen uses and leave the filtering to the client. The problem is that anyone inspecting the traffic sees everything in the response, including what the interface hides. Return only the fields each context needs. Validate input strictly on the server and respond to errors without revealing internal details that would help an attacker.
Without rate limiting, the API is exposed to abuse, brute force and mass scraping. Limit requests per identity and per source and watch for unusual patterns. API logs support detection and investigation: with them you notice abuse while it happens and can investigate it afterward.
API defense layers
No single control protects an API on its own. A design that tolerates failures combines a gateway in front, strong authentication, authorization checked inside the service itself and strict validation of what comes in and what goes out. Each layer assumes the previous one may fail, so a single mistake does less damage.
Schema validation and property assignment
Validating the body and parameters against an explicit schema, and rejecting unknown fields, eliminates a whole class of problems at once. When the API blindly accepts the object the client sent, it opens the door to mass assignment: the user adds to the request a sensitive field the interface would never show (an administrative role flag, for example). The rule is to bind only the expected fields and to check authorization at the property level as well as at the object level.
Content-Type: application/jsonX-Content-Type-Options: nosniffCache-Control: no-storeServer-to-server requests and SSRF
When the API fetches a URL supplied by the client (a webhook or a remote image, for example), it can be tricked into reaching internal destinations. This is called server-side request forgery, or SSRF. To defend against it, validate the destination against an allowlist, reject internal addresses and the cloud metadata endpoint, and resolve the name before connecting, so nobody can bypass the check. The outbound requests the API makes deserve the same rigor as the ones it receives, and this point often goes unnoticed.
Practical checklist
- Validate token signature, issuer, audience and expiration on the server
- Use short expiration, with renewal and a revocation path
- Validate object ownership on every request (against BOLA)
- Check role and permission on sensitive functions (against BFLA)
- Do not trust identifiers or flags coming from the client
- Return only the necessary fields in each response
- Validate input strictly on the server
- Apply rate limiting per identity and per source
- Respond to errors without leaking internal details
- Keep API logs for detection and investigation
- Keep the inventory of APIs, versions and environments up to date
- Take discontinued versions and test endpoints offline
- Validate body and parameters against the schema and reject unknown fields
- Restrict outbound API requests to contain SSRF
Best practices
- Centralize authorization in the backend and apply the same rule everywhere
- Hold every endpoint and every version to the same access rigor
- Return only the data the client really needs
- Use short expiration and revocation to limit the damage of a leaked token
- Monitor abuse with rate limiting and anomaly detection
- Version and document the API so no endpoint is forgotten
- Combine a gateway, authentication, in-service authorization and schema validation
- Check authorization per property as well as per object
Common mistakes
- Trusting the identifier sent by the client
- It opens the door to broken object level authorization (BOLA), and other users' data leaks.
- Sensitive functions with no server-side role check
- A regular user can perform administrative actions (BFLA).
- Long-lived tokens with no revocation
- A leaked token stays valid for a long time.
- Responses with more data than needed
- Anyone inspecting the traffic sees sensitive information the screen doesn't even display.
- No rate limiting
- Nothing holds back abuse, brute force and mass scraping.
- Old versions and test endpoints left running
- They become shadow APIs with weak controls that grow the attack surface while nobody monitors them.
- Accepting the client's object without schema validation
- It opens the way to mass assignment, and the user gets to set sensitive fields they should not control.
Authorship and review
Cesar Gargiulo
CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.
Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.