No unnecessary data in responses (over-fetching)
Why it matters
Returning passwordHash, internal tokens, or entire database rows in API responses is a direct CWE-200 (exposure of sensitive information) finding and maps to OWASP A01:2021 (broken access control) when those fields reveal authorization state. A single mistakenly-included passwordHash field in a user endpoint hands an attacker every credential they need to mount offline dictionary attacks. Over-fetching also inflates response payloads and tightly couples clients to database schema, making schema changes more expensive (ISO-25010:2011 functional-suitability.functional-correctness).
Severity rationale
Low severity in aggregate because exploitation requires accessing the endpoint first, but any single sensitive-field leak (passwordHash, internalToken) is independently critical.
Remediation
Create a serializer at src/lib/serializers.ts that explicitly allowlists fields before returning database records. Never spread a database row directly into a response:
// src/lib/serializers.ts
export function serializeUser(user: User) {
const { id, name, email, createdAt, role } = user
return { id, name, email, createdAt, role }
// passwordHash, internalFlags, stripeCustomerId are never included
}
In Prisma, add explicit select clauses to queries rather than fetching and stripping fields after the fact — this prevents the data from ever crossing the DB boundary:
db.user.findUnique({ where: { id }, select: { id: true, name: true, email: true } })
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the API Design Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-200 — Exposure of Sensitive Information to an Unauthorized Actor
- owasp:2021 · A01 — Broken Access Control
- iso-25010:2011 · functional-suitability.functional-correctness — Functional Correctness
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-api-design·automated