Prompt
How do I inspect API requests and responses for sensitive data leaks?
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
To inspect API requests and responses for sensitive data leaks, use a mix of manual review, automated scanning, and runtime monitoring.
1) Define what “sensitive” means
Look for:
- Passwords, API keys, tokens, session cookies
- Personal data: names, emails, phone numbers, addresses, DOB
- Financial data: card numbers, bank details
- Government IDs: SSN, passport, driver’s license
- Internal-only data: user IDs, database IDs, feature flags, stack traces
- Secrets in headers, query strings, bodies, error messages, or logs
2) Inspect traffic directly
Use tools like:
- Browser DevTools → Network tab for frontend APIs
- curl -v or Postman/Insomnia for manual calls
- Charles Proxy / Burp Suite / mitmproxy to capture and review traffic
- Server-side logs (carefully—avoid logging secrets in the first place)
What to check:
- Headers:
Authorization,Cookie, custom auth headers, tracing headers - Query params: avoid secrets in URLs since they get logged/cached
- Request body: passwords, tokens, PII, debugging info
- Response body: secrets, full user objects, internal identifiers, stack traces
- Status/error messages: avoid exposing internals or validation details
3) Automate detection with scanning rules
Use pattern-based checks in logs, captured traffic, or test environments:
- Regex for tokens/secrets:
- JWT-like strings
- AWS keys, GitHub tokens, Stripe keys
- Credit card formats
- Email/phone/SSN patterns
- DLP-style scanners:
- gitleaks, trufflehog for secrets in repos/configs
- Semgrep for insecure logging patterns
- Detect-secrets for secret-like strings
- Commercial DLP tools for broader coverage
Examples of things to flag:
Authorization: Bearer ...Set-Cookievalues in logspassword,secret,token,apiKeyin responses- Large unredacted JSON objects from user/profile endpoints
4) Test common leakage paths
Run tests that intentionally trigger errors and edge cases:
- Invalid auth
- Missing fields
- Oversized payloads
- 4xx/5xx responses
- Debug mode on/off
- GraphQL introspection / verbose error messages
- Pagination and export endpoints
- Admin/internal endpoints accidentally exposed
Check whether responses reveal:
- Stack traces
- SQL queries
- File paths
- Environment variables
- Internal service names
- Raw upstream error payloads
5) Redact and minimize by design
Prevent leaks rather than finding them later:
- Never log secrets
- Redact values of known sensitive fields
- Use allowlists for response fields, not blocklists
- Avoid putting secrets in URLs
- Return only necessary fields from APIs
- Split public and private DTOs/models
- Mask sensitive values in telemetry and APM tools
Example redaction policy:
Authorization→[REDACTED]Cookie→[REDACTED]password,token,apiKey→[REDACTED]- card number → keep last 4 digits only
6) Add CI/CD and runtime checks
- Scan test traffic in CI
- Add unit/integration tests asserting sensitive fields are absent
- Use middleware to redact logs before they are emitted
- Add WAF/API gateway rules for obvious secret patterns
- Monitor production logs for accidental leakage
- Alert on high-risk patterns in responses and traces
7) Good practice checklist
- No secrets in URL/query params
- Request/response logging is redacted
- Error responses don’t include stack traces in production
- APIs use least-privilege field exposure
- PII is masked where not required
- Tokens/cookies never appear in analytics or APM
- Automated scans run on code, logs, and captured traffic
If you want, I can give you:
- a practical inspection workflow using DevTools/Burp/mitmproxy, or
- a sample Python/Node script to scan API logs and JSON responses for leaks.