Course contentsShow
← Security
Lesson 994 of 3,05221. Web Security - API SecurityFree lesson

Excessive Data Exposure in API Responses

Identify when APIs return full objects trusting client-side filtering, exposing sensitive data that should be filtered server-side.

Excessive Data Exposure in API Responses

What you'll learn: You'll discover how APIs accidentally leak sensitive information by returning entire database objects and relying on the client to filter what's displayed.


The Core Problem

Many APIs take a shortcut: instead of carefully selecting which fields to return, they dump the entire user object, product record, or database row into the response—then expect the client-side code (JavaScript in the browser) to cherry-pick only the fields it needs for display.

The danger? Attackers don't use your UI. They intercept the raw API response and see everything the server sent—including fields you never intended to expose.


How It Happens

Imagine a social media API endpoint: GET /api/users/123

Vulnerable response:

{
  "id": 123,
  "username": "alice",
  "email": "alice@example.com",
  "phone": "555-1234",
  "password_hash": "$2b$10$...",
  "ssn": "123-45-6789",
  "balance": 5420.00,
  "role": "premium_user"
}

Your mobile app only displays username and email—but an attacker viewing the HTTP response sees password hashes, SSNs, internal roles, and account balances.


The Fix: Server-Side Filtering

Return only what's needed:

{
  "id": 123,
  "username": "alice",
  "email": "alice@example.com"
}

Never trust the client to hide sensitive data. The server must actively choose which fields to include in each response, based on context and authorization level.


Real-World Analogy

It's like a bank teller printing your entire account history, credit score, and Social Security number on every receipt—then asking you to ignore the extra information and only look at your balance. Any observer can read the rest.


Key Takeaway:
APIs must filter sensitive fields server-side before sending responses; relying on client-side code to hide data exposes everything to attackers inspecting HTTP traffic.