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).
Low severity in aggregate because exploitation requires accessing the endpoint first, but any single sensitive-field leak (passwordHash, internalToken) is independently critical.
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 } })
saas-api-design.request-response.no-over-fetchinglowselect *-equivalent patterns, and check response serialization for field allowlisting.User endpoint returns passwordHash. Identify the specific over-fetching issue (e.g., "User endpoint returns passwordHash and internalFlags fields; /api/orders includes full customer object on every item"). Max 500 chars.src/lib/serializers.ts and explicitly exclude sensitive fields in responses. In Prisma: use select: { id: true, name: true, email: true } rather than returning the whole record. In raw SQL: name columns explicitly. Create a serializer or DTO (Data Transfer Object) function that converts database records to API-safe response shapes — this is a single place to audit what you're exposing. Never return a database row directly without going through a field allowlist.