Home / patterns

Passwords, tokens and personal data written to your logs

A developer at night watching a large monitor full of scrolling server log lines, with a laptop and a coffee mug on the desk and city lights through the window
Quick answer: AI-written code loves to debug with console.log(req.body), print the whole user object, or log the full request headers. In production that sends passwords, session cookies, API keys, Stripe events and customers' personal data into your hosting provider's logs, your error tracker and anyone with dashboard access. Logs are kept for a long time and shared widely, so a leak there is quiet and lasting.

Last updated November 12, 2026

Steps

  1. Search your code for console.log, console.error, print and logger calls that output whole objects: req.body, req.headers, user, session, process.env, payment or webhook events.
  2. Open your host's log viewer (and any error tracker) and search recent logs for words like password, token, authorization, cookie, secret, apikey and sk_. Anything you find has already leaked.
  3. Replace whole-object logging with a short list of safe fields, such as user ID, route, status code and duration.
  4. Use a logger with redaction (structured JSON logs) and add redact paths for authorization headers, cookies, passwords, tokens, card data and personal fields.
  5. Turn off debug logging in production with a log-level setting, and remove leftover debug log files before deploying.
  6. If secrets did reach your logs, rotate those keys and tokens, then delete or expire the affected logs where your provider allows it.
  7. Limit who can read production logs and error reports, and never store log files in a web-accessible folder.

Why it matters

MITRE tracks this as CWE-532 (Insertion of Sensitive Information into Log File) and its first mitigation is simple: don't write secrets into log files. It also recommends removing debug log files before deploying to production, protecting log files from unauthorized access and switching configuration from debug to production settings. OWASP's Logging Cheat Sheet lists data that usually shouldn't be logged directly, including session IDs, access tokens, passwords, database connection strings, encryption keys, payment card data and sensitive personal information, and says it should be removed, masked, hashed or encrypted. It also warns against exposing logs in web-accessible locations and recommends restricting who can access them.

Sources

MITRE CWE-532: Insertion of Sensitive Information into Log File — https://cwe.mitre.org/data/definitions/532.html

OWASP Cheat Sheet Series: Logging Cheat Sheet — https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html

Related patterns

Found a problem you'd rather not fix yourself?

Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.

Get it fixed by StorenTech

Vibe Security Weekly

One email a week with new failure patterns and how to fix them.

By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.