Skip to content

API penetration testing: critical points in authentication, authorization and exposure

APIs concentrate logic and data, and they fail more often on authorization than on injection. See where the risk really is.

Reading time
10 min
Published

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.

Response headers for sensitive API responses
Content-Type: application/jsonX-Content-Type-Options: nosniffCache-Control: no-store

Server-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.

Frequently asked questions

What is BOLA and why is it so common in APIs?
BOLA is broken object level authorization. The API authenticates the user but does not check whether that user has the right to the requested object. It is common because authentication is almost always in place and gives the impression that the matter is settled, while the check of who owns the resource gets forgotten. The fix is to validate that ownership on the server, on every request.
Is decoding a JWT the same as validating it?
No. Decoding only reveals the token's content, which anyone can read. Validating means verifying the signature with the correct key and checking the issuer, audience and expiration. The fact that the content is readable does not prove the token is authentic, so the API must validate it on every request instead of simply reading what is written in it.
Does GraphQL change how the API is tested?
Partly, yes. GraphQL concentrates everything in a single endpoint and accepts flexible queries, which brings its own concerns: queries nested too deep, more fields exposed than needed and the need to authorize field by field. The principles stay the same (server-side authorization and data minimization), but the surface and the controls have their own particularities.
Is rate limiting enough to protect an API?
Not on its own. Rate limiting reduces abuse, brute force and scraping, but it does not fix authorization flaws or data exposure. It is an important layer that has to come with strong authentication, server-side authorization, input validation and minimization of what the API returns.
What are shadow APIs and why are they dangerous?
Shadow APIs are endpoints that exist but sit outside governance: old versions that stayed online, exposed test hosts or APIs published without going through the inventory. The danger is that they usually have weaker authentication and validation and nobody looks at them. To defend against them, keep an up-to-date inventory of APIs, versions and environments, take offline whatever was discontinued and use the specification as the source of truth.
What is mass assignment and how do I prevent it?
Mass assignment happens when the API automatically copies every field the client sends into the internal object. That lets the user set a field they should not control, such as a privilege flag. To prevent it, validate the body against an explicit schema, accept only the expected fields and check authorization at the property level as well as at the object level.
How do I protect an API against SSRF?
If the API fetches a URL provided by the client, validate the destination against an allowlist, reject internal addresses and the cloud metadata endpoint, and resolve the name before connecting so the check cannot be bypassed. Giving outbound requests the same care as inbound ones closes the path for server-side request forgery, which often goes unnoticed.

When to bring in specialist help

Testing an API calls for specific attention to authorization and exposed data. GUARDIASEC's penetration testing service assesses REST and GraphQL APIs and checks authentication, authorization and data exposure, with evidence for each finding and priority set by risk.

If you are evaluating a provider, describe the environment and the timeline, and we will send you a written proposal. Request a proposal for penetration testing