Sensitive and excessive data exposure in API responses
How APIs leak fields the screen never shows, why filtering in the client is not filtering, and how to review serializers, caches, and logs for personal data that should never leave the server.
Diagram
A response carrying more than the screen needs
Step 1 of 4
Request
The profile page asks for the signed-in user.
GET /api/v2/users/me
Whatever the table has today
Ships automatically
Requires reading the database
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Client-side filtering
- What fails
- The browser or app hides fields that the API still sends.
- Who is affected
- Every user in every response that carries the extra fields.
- What you would notice
- Responses in the proxy history with hashes, tokens, internal flags, or other users’ data.
- What you change
- Define response schemas per endpoint and test that unlisted fields are absent.
Data that outlives the response
- What fails
- Caches, logs, and analytics copy what the API returns.
- Who is affected
- Users whose data lands in systems with weaker access controls.
- What you would notice
- Full response bodies in application logs or a shared CDN cache.
- What you change
- Mark personal responses Cache-Control: private, no-store and log identifiers, not bodies.
Classify before you protect
- What fails
- Teams cannot protect fields they have not labeled.
- Who is affected
- Customers, when a field like date of birth is treated as harmless.
- What you would notice
- No data classification for the tables behind public endpoints.
- What you change
- Tag sensitive columns and fail a test when a tagged column appears in a public schema.
Reviewing one endpoint
Open the endpoint in a proxy you are authorized to use, compare the JSON to what the screen shows, and list every field the screen does not use. Then read the handler and find where the response is built. Returning an ORM object, a dict(row), or a to_json() of the whole model is the usual cause.
$ curl -s -H "Authorization: Bearer $LAB_TOKEN" https://api.lab.test/api/v2/users/me | jq 'keys' ["email","id","is_staff","last_login_ip","mfa_secret","name","password_hash"] # screen uses: name, email # finding: password_hash, mfa_secret, last_login_ip returned to the client
A test that keeps it fixed
A contract test asserts the exact key set of each public response. When someone adds a column, the test fails and forces a decision instead of a silent leak.
def test_me_fields(client, user_token):
body = client.get("/api/v2/users/me", headers=auth(user_token)).json()
assert set(body) == {"id", "name", "email"}Related classes
OWASP API Security Top 10 (2023) folds excessive data exposure into broken object property level authorization, alongside mass assignment. The same property-level review covers both: which fields may a caller read, and which may a caller write.
Check yourself
Recognition and the fix. Nothing here is a procedure.
The mobile app shows only a name, but the API returns password_hash. Where is the bug?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
This page stands on its own. The lab and the glossary card are the next reading.