Security Playbook
19 · APIs & mobileOWASP API3:20236 min read

API security: the UI hides it, the API sends it

APIs often return whole database objects and let the frontend pick what to show. Anyone with DevTools sees the rest. The OWASP API Top 10 risks that matter most for product teams and how to design responses that leak nothing.

In one sentence

Decide on the server which fields each audience may see and change, return only those, and authorize every object and every property.

Three fields on screen, eleven on the wire

The profile page shows a name, an avatar and a bio. The endpoint behind it returns the full user row: email, phone, password hash, internal flags. The frontend just doesn't render them.

Excessive data exposure: the UI shows 3 fields, the API sends 11
Who's calling
What the profile page shows
🦊
Ana LópezClimber, coffee nerd
GET /api/users/7 · What the API actually returns
{
"id": 7,"name": "Ana López","avatar": "🦊","bio": "Climber, coffee nerd","email": "ana@mail.test","phone": "+34 600 000 111","passwordHash": "$argon2id$v=19$m=19456…","role": "customer","lastLoginIp": "88.12.4.201","stripeCustomerId": "cus_FAKE91","isAdmin": false,}

⚠ 7 fields the UI hides but anyone can read in DevTools

Filtering in the frontend is not filtering. Define a response schema per audience on the server (DTOs / serializers) and never return objects straight from the database.
Change who's calling and turn on a per-role response schema.

The API risks to know

OWASP API (2023)What it looks like
API1 Broken object level authorizationGET /orders/1042 works for someone who doesn't own it (IDOR)
API2 Broken authenticationTokens that never expire, unprotected password reset, API keys in URLs
API3 Broken object property level authorizationResponses with extra fields; mass assignment on writes
API4 Unrestricted resource consumptionNo pagination limits, no rate limits, expensive queries on demand
API5 Broken function level authorizationA normal user calls /admin/refunds
API9 Improper inventoryAn old /v1 endpoint, still live, without the new checks
// Serialize per audience instead of returning the DB row
const PublicUser = UserSchema.pick({ id: true, name: true, avatar: true, bio: true });
const SelfUser = PublicUser.extend({ email: z.string(), phone: z.string() });

return Response.json(isSelf ? SelfUser.parse(user) : PublicUser.parse(user));

Key takeaways

  • 01Never return raw database objects from an API.
  • 02Define response schemas per audience on the server.
  • 03Authorize objects, properties and functions on every request.
  • 04Keep an inventory of endpoints and retire old versions.

Check your understanding

1 of 3

Why shouldn't an API return raw database objects?

Related concepts