Cybersecurity

API Security: The Attack Surface Developers Keep Underestimating

APIs now carry most application traffic, and they expose business logic directly to anyone who can read the documentation or a mobile app's traffic. The OWASP API Security Top 10 was just updated for 2023. Here is what changed, and the authorisation bugs we keep finding.

By EthicalHat Research · · 4 min read
Infographic: The 2023 OWASP API Security Top 10, at a glance

Web applications used to hide their data model behind server-rendered pages. Today, most applications are a thin client (a single-page app or a mobile app) talking to a set of APIs that return raw JSON objects. That is great for developers. It also means the business logic, and every object ID, is exposed directly to anyone who opens the browser's developer tools or proxies a mobile app.

Attackers have noticed. Two of the most discussed breaches of the past year were API failures:

  • Optus (September 2022): data on up to 9.8 million customers was reportedly retrieved through an internet-facing API endpoint that did not require authentication, by iterating through customer identifiers.
  • T-Mobile (disclosed January 2023): an attacker abused an API to obtain data on around 37 million current customer accounts.

In June, OWASP published the 2023 edition of the API Security Top 10, the first update since 2019.

The 2023 list

#RiskIn one sentence
API1Broken Object Level AuthorizationThe API returns any object whose ID you ask for
API2Broken AuthenticationWeak tokens, missing checks or credential stuffing
API3Broken Object Property Level AuthorizationReading or writing fields you should not (merges 2019's excessive data exposure and mass assignment)
API4Unrestricted Resource ConsumptionNo limits on requests, payload size or costly operations
API5Broken Function Level AuthorizationRegular users can call admin endpoints
API6Unrestricted Access to Sensitive Business FlowsAutomating purchases, sign-ups or referrals at scale (new)
API7Server Side Request ForgeryThe API fetches URLs you supply (new)
API8Security MisconfigurationCORS, verbose errors, missing hardening
API9Improper Inventory ManagementOld versions and undocumented hosts still live
API10Unsafe Consumption of APIsTrusting data from third-party APIs too much (new)

BOLA: the bug we find in almost every API test

Broken object-level authorisation stays at number one because it is easy to introduce and easy to exploit. The pattern looks like this:

javascript
// Vulnerable: authenticates the user, but never checks they own the invoice
app.get("/api/invoices/:id", requireLogin, async (req, res) => {
  const invoice = await db.invoices.findById(req.params.id);
  if (!invoice) return res.sendStatus(404);
  res.json(invoice);
});

Any logged-in user can change /api/invoices/1001 to /api/invoices/1002 and read someone else's invoice. Switching to UUIDs makes guessing harder but does not fix the bug, because IDs leak through URLs, logs and other endpoints.

The fix is to scope every query to the caller, and to make that the default rather than something each endpoint remembers:

javascript
// Fixed: the query itself is scoped to the caller's tenant and user
app.get("/api/invoices/:id", requireLogin, async (req, res) => {
  const invoice = await db.invoices.findOne({
    id: req.params.id,
    tenantId: req.user.tenantId,
    ownerId: req.user.id,
  });
  if (!invoice) return res.sendStatus(404); // same response whether it exists or not
  res.json(invoice);
});

In larger codebases, centralise this in a data-access layer or policy engine so an endpoint cannot fetch an object without an authorisation context.

Property-level authorisation and mass assignment

APIs often return the whole database object and let clients pick the fields they display. That leaks internal fields such as isAdmin, passwordHash and internalNotes. On writes, frameworks that bind request JSON straight onto a model let attackers set fields they should not:

http
PATCH /api/users/me
Content-Type: application/json

{ "displayName": "Sam", "role": "admin", "creditLimit": 100000 }

Use explicit response schemas (serialise only allowed fields) and explicit allow-lists for writable properties.

Business flows and inventory: the new emphasis

Two themes in the 2023 list are worth highlighting:

  • Sensitive business flows (API6). An endpoint can be perfectly "secure" and still be abused, for example by scripts that buy every concert ticket, create thousands of accounts for referral bonuses or scrape a catalogue. Protecting these needs rate limits per user and device, bot detection and business-level monitoring, not just input validation.
  • Inventory (API9). The API you are testing is rarely the one that gets breached. It is /v1/, which the mobile app stopped using two years ago but nobody switched off, or the staging host with production data. You cannot protect APIs you do not know about.

A checklist for API owners

  1. Keep an inventory of every API host, version and environment, generated from gateways and traffic rather than documentation.
  2. Require authentication by default; make anonymous endpoints an explicit, reviewed exception.
  3. Enforce object- and function-level authorisation centrally, with tests that try cross-tenant and cross-user access.
  4. Return explicit schemas; never serialise whole database objects.
  5. Rate-limit and quota per user, token and IP, including on expensive operations like search and exports.
  6. Validate outbound fetches to stop SSRF: allow-list destinations and block internal ranges and metadata endpoints.
  7. Log with context (user, object ID, result) so abuse such as ID enumeration is detectable.

Why scanners miss this

Automated scanners are good at injection and misconfiguration. They are poor at authorisation, because they do not know that user A should not see user B's invoice. Finding BOLA and business-flow abuse needs a tester who understands the application's roles and data model, working with at least two accounts per role.

That is exactly how our application penetration testing and application security testing engagements approach APIs.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.