Passwords, tokens and personal data written to your logs

Last updated November 12, 2026
Steps
- 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.
- 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.
- Replace whole-object logging with a short list of safe fields, such as user ID, route, status code and duration.
- Use a logger with redaction (structured JSON logs) and add redact paths for authorization headers, cookies, passwords, tokens, card data and personal fields.
- Turn off debug logging in production with a log-level setting, and remove leftover debug log files before deploying.
- If secrets did reach your logs, rotate those keys and tokens, then delete or expire the affected logs where your provider allows it.
- 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
- Error messages that leak stack traces, queries or keys
- API secret keys shipped in your frontend bundle
- Exposed .env or .git on a deployed site
- Production source maps that publish your app's original source code
- Debug or preview mode left on in production
- API responses that return whole database records (excessive data exposure)
- CSV exports that run formulas when opened in a spreadsheet (CSV injection)
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 StorenTechVibe 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.