API Route Exposing Sensitive Data in Response
Your v0-generated Next.js API route is returning sensitive data in its JSON response that should never reach the client. Internal database IDs, user emails, hashed passwords, API keys, or internal configuration values are being serialized and sent to the browser because the route handler returns the full database record without filtering fields.
This is especially dangerous when v0 scaffolds CRUD endpoints that use Prisma's findMany or findUnique without a select clause, causing every column in the table to be included in the response payload.
Attackers can inspect network responses in DevTools or call your API directly to harvest sensitive information, leading to data breaches and compliance violations.
Error Messages You Might See
Common Causes
- No field filtering on queries — Prisma findMany/findUnique returns all columns by default, including password hashes and internal flags
- Spreading full user objects — v0 generated
return NextResponse.json(user)without picking safe fields - Environment variables in responses — process.env values accidentally included in API response during debugging
- Nested relations exposing data — Prisma include statements pulling related records with sensitive fields
- No response serialization layer — missing DTO or transform step between database and response
How to Fix It
- Add Prisma select clauses — replace findMany() with findMany({ select: { id: true, name: true, avatar: true } }) to whitelist safe fields
- Create response DTOs — build a toPublicUser() function that strips sensitive fields before returning
- Audit all API routes — search your codebase for NextResponse.json and verify every response payload is sanitized
- Add middleware validation — create a response sanitizer middleware that strips known sensitive field names
- Use Zod output schemas — define Zod schemas for API responses and parse through them before returning
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How do I find all exposed API routes?
Search your app/api directory for NextResponse.json calls. Check each one to ensure it uses Prisma select or maps through a DTO before returning data.
Should I use select or omit in Prisma?
Use select for whitelisting safe fields. Prisma omit is available in newer versions but select is more explicit and safer by default.
How do I prevent this in future v0 generations?
Add a project rule in v0 that instructs it to always use select clauses in Prisma queries and never return raw database objects.