Prompt
Why is PII still leaking in API responses?
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
PII still leaks in API responses for a few common reasons:
-
It’s being returned by default
- The backend serializer or ORM entity includes sensitive fields unless they’re explicitly excluded.
- Example: returning a full user object instead of a safe DTO/view model.
-
Authorization is incomplete
- The endpoint may be correctly authenticated, but not properly authorized for the specific fields.
- A user can access a resource they should see, but still get extra personal data attached to it.
-
Nested/related objects are overlooked
- Even if the top-level response is sanitized, embedded objects, expansions, or joins can contain PII.
- Common in GraphQL, “include” flags, and overfetching ORM queries.
-
Legacy code paths
- Old endpoints, admin endpoints, exports, and debug routes often bypass newer redaction rules.
- Some services also have inconsistent filtering between versions.
-
Logging/error handling accidentally exposes it
- Error responses, validation messages, stack traces, or “debug” fields can echo PII.
- Sometimes the leak is in response metadata rather than the main payload.
-
Caching and proxies serve stale sensitive data
- CDN, reverse proxy, or application cache may store a response that includes PII and replay it to other requests.
- Misconfigured cache keys or missing
Cache-Control: no-storecan cause this.
-
Front-end requests ask for too much
- The client may request broad fields “for convenience,” and the API honors it.
- This is especially common with generic list/detail endpoints.
-
Testing and observability gaps
- Teams often don’t have automated checks to detect PII in responses.
- Without schema-based allowlists or data loss prevention checks, regressions slip through.
What to do
- Use response DTOs / allowlists, not raw database models.
- Redact sensitive fields centrally in middleware or serializers.
- Enforce field-level authorization for sensitive attributes.
- Add tests that assert PII is absent from responses.
- Review nested objects, errors, logs, and cached responses.
- Mark sensitive endpoints with proper cache headers.
If you want, I can help you build a PII leak checklist or show how to fix this in a specific stack like Express, Django, Spring, or GraphQL.