CWE-213OWASP API3:2023OWASP A01:2021CWE-200

CWE-213: Excessive Data Exposure

An API or response returns more data than the user should see, exposing sensitive fields because the output was not filtered to the intended policy.

Also known as: Excessive data exposure, Over-fetching fields, Unfiltered API response

Risk

Usually medium to high. The endpoint may be correctly authorized, yet it hands back internal or private fields the client hides but the raw response still contains, leaking data to anyone who reads it.

Definition

What it is

CWE-213 is the exposure of sensitive information because the data a component returns does not match the policy for who should see it. A common form is an API that serializes a whole database object, so the response includes password hashes, internal flags, or other users' details that the UI never shows but the JSON does. The client filtering the display does nothing, because the raw response is already on the wire. The fix is to return only the fields the caller is entitled to, decided on the server.

Use-cases

How it shows up in real code

Whole object serialized

A user endpoint returns the full record including passwordHash and isAdmin because the handler serializes the model directly. The UI shows only a name, but the JSON carries everything.

Hidden in the UI, present in JSON

A profile page hides internal fields with CSS or front-end logic. Opening the network tab reveals the full response with the sensitive fields intact.

List endpoint leaks neighbors

A list of orders includes each customer's email and address for the whole page. A user viewing their own orders receives other people's data in the same payload.

Debug fields in production

An endpoint returns internal timing, stack, or config fields meant for development. In production those fields expose implementation details to any caller.

AI risk

Why AI-generated code has increased the exposure

  • Assistants optimize for an endpoint that returns the data the UI needs, and returning the whole object is the shortest way to guarantee the needed field is present.
  • Training data is full of handlers that serialize a model directly or spread an entire record, so the model emits return user rather than a curated projection.
  • The model cannot see which fields are sensitive in a given schema, so it exposes password hashes or internal flags alongside the harmless ones.
  • When scaffolding CRUD endpoints, the assistant generates read handlers that echo the full stored object for every resource it creates.
  • Because generated code relies on the client to show only some fields, the volume of endpoints multiplies responses that over-return on the wire.

Vibe coding

How vibe coding amplifies the risk

  • Vibe coding ships an endpoint that returns the whole record because the page renders correctly, hiding that the JSON carries far more.
  • The skipped review is where someone would open the network tab and notice the response includes fields the UI never shows.
  • A prototype that returned everything for convenience is promoted to production, still leaking internal fields to every caller.
  • The exposure is invisible in local and demo testing because the rendered page looks right and nobody inspects the raw response.
  • As a vibe-coded API grows more endpoints and clients, each unfiltered response adds another place private fields leak, with no review catching it.

Detection

How to find it

  • Inspect raw API responses, not the rendered UI, and look for fields the caller should not receive such as hashes, tokens, or internal flags.
  • Compare what each endpoint returns against the fields the client actually uses; a large gap signals over-exposure.
  • Check list endpoints for other users' data bundled into a single page payload.
  • Review serializers and handlers for places that return a whole model or spread an entire record.

Remediation

How to fix it

  • Return an explicit allowlist of fields per endpoint, serialized through a response schema, rather than the raw stored object.
  • Define separate output shapes for different audiences so internal fields are never serialized to external callers.
  • Decide exposure on the server; never rely on the client to hide fields that the response still contains.
  • Strip debug, internal, and other-user fields from production responses, and keep sensitive columns out of default queries.
  • Add tests that assert each endpoint's response contains only the intended fields so a regression over-returns loudly.

Frequently asked questions

What is CWE-213 (exposure of sensitive information due to incompatible policies)?
CWE-213 is when a response returns more data than the viewer should see, often because an API serializes a whole object and includes fields like password hashes or internal flags that the UI hides but the JSON still carries. Since the raw response is already sent, client-side filtering does not protect it.
How have AI assistants and vibe coding increased the risk?
Assistants optimize for an endpoint that returns the data the UI needs, and emitting the whole object is the shortest route, so generated handlers echo full records including sensitive fields the model cannot tell apart. Vibe coding ships those endpoints because the page renders correctly, so nobody inspects the over-returning raw response before production.
How do I fix excessive data exposure?
Return an explicit allowlist of fields through a response schema instead of the raw object, define separate output shapes per audience, decide exposure on the server rather than the client, and test that each endpoint returns only the intended fields.

Related weaknesses

Catch CWE-213 before you ship

Tethlyn Audit scans your codebase and its git history for CWE-213 and the rest of the sensitive data exposure & privacy class, then ranks each finding by real exploitability and data sensitivity.

See Tethlyn Audit