Skip to main content
Logs
Published 9 min read

What Sensitive Data Should Never Be Stored in Logs?

A checklist of exactly what shouldn't appear in your logs, and why each item on it is riskier than it looks.

Most sensitive data in logs isn't there because someone decided to log it - it's there because a broad logging statement captured more than intended. This is a working checklist of what to specifically watch for, and why each category is worth treating differently from ordinary debug output.

Credentials and authentication material

  • Passwords, in any form - plaintext or hashed. A hash is still one offline attack away from being useful, and there's simply no reason to log it.
  • API keys and access tokens - a leaked key found in a log is functionally identical to a stolen key.
  • JWTs - the signature portion can be used to impersonate the token's owner until it expires.
  • Session cookies and session IDs - these can often be replayed to hijack an active session.
  • Database connection strings - these frequently embed a username and password directly in the URL.
  • Cloud provider credentials (access keys, secret keys) - these can grant broad infrastructure access if found.
  • Private keys - anything resembling a PEM block (-----BEGIN PRIVATE KEY-----) should never appear in a log.

Personal and identifying information

  • Full names combined with other identifying context
  • Email addresses
  • Phone numbers
  • Physical addresses
  • Government-issued ID numbers
  • Dates of birth

None of these are automatically catastrophic on their own, but they add up - and depending on your industry, several data-protection regulations place specific restrictions on how personal data can be stored and retained, which extends to logs whether or not that was the intent.

Financial information

  • Full credit card numbers
  • CVV codes
  • Bank account and routing numbers

Payment data has its own compliance framework (PCI DSS) that treats logging full card numbers as a direct violation, regardless of whether the log is ever shared externally.

Request internals that hide credentials

  • Authorization headers - these often contain a Bearer token or Basic auth credentials directly
  • Full cookie headers
  • Query strings with embedded tokens (?api_key=...) - these are easy to miss because they don't look like a credential field
  • Webhook signing secrets

A quick reference table

Data typeExampleShould it be logged?Recommended handling
Passwordhunter2NeverLog the outcome ("login failed") instead
API keysk-live-...NeverLog a key ID or last 4 characters if identification is needed
Session cookieconnect.sid=s%3A...NeverMask entirely if the header must be logged
Email address[email protected]Avoid where possibleMask (j***@example.com) if needed for correlation
IP address203.0.113.5Context-dependentConsider truncating or masking for externally-shared logs
Request IDreq_8f2a91YesNot sensitive - useful for tracing

A practical checklist before sharing a log

  • No Authorization or Cookie header values are visible in plaintext
  • No API keys, tokens, or connection strings are present
  • No full card numbers or CVVs are present
  • Email addresses and phone numbers are masked or removed if the log is leaving internal systems
  • Field names in structured (JSON) logs have been checked, not just the values

Log Sanitizer runs this exact checklist automatically - paste a log and it flags and masks each of these categories, entirely in your browser.

For the step-by-step process of actually cleaning a log once you've identified what needs to go, see How to Remove Sensitive Data from Logs: A Step-by-Step Guide.

Summary

The categories worth watching for are consistent across almost every codebase: credentials, personal data, financial data, and the request internals (headers, cookies, query strings) that quietly carry all three. Treating this as a fixed checklist - rather than relying on catching it by eye each time - is what keeps sanitization consistent under time pressure.

Frequently asked questions

Is it ever acceptable to log a password?
No - not even a hashed one, and not even temporarily. There's no debugging scenario where the actual password value is necessary; logging that a login attempt failed is enough.
Should API keys ever appear in logs?
No. If you need to confirm which key was used, log a stable identifier for it (a key ID or the last few characters) rather than the full key value.
What should I do if I find sensitive data already sitting in historical logs?
Treat any real credential found there as compromised and rotate it, then fix the logging statement that caused it and consider purging or re-processing the affected historical logs if your retention policy allows it.

The tool that pairs with this guide.

Did this help you clean up sensitive logs?

If these free developer tools save you time, consider buying me a byte. Your support helps keep DevCraftKit free and growing.

Buy me a byte 💾