CWE-532OWASP A09:2021OWASP A02:2021CWE-200

CWE-532: Sensitive Information in Logs

Sensitive data such as passwords, tokens, or personal information is written into log files, where it is exposed to anyone who can read the logs.

Also known as: Secrets in logs, Sensitive data logging, Credential logging

Risk

Usually medium to high. Logs are widely read, forwarded, and retained, so a token or password written once can sit in many systems for a long time, often with weaker access controls than the database.

Definition

What it is

CWE-532 is the writing of sensitive information into logs. It happens when code logs a full request or object that contains a password, API key, token, or personal data, or when a debug statement prints a secret during development and is left in. Logs flow to files, aggregators, and third-party monitoring, and are kept far longer than the data's intended lifetime. A credential captured in a log is effectively leaked to every person and system with log access.

Use-cases

How it shows up in real code

Full request logged

A handler logs the entire incoming request to debug an issue, including the password in the login body. Every login now writes a plaintext password to the log.

Token in an error log

An error handler logs the request headers, which include the bearer token. Anyone reading the error log can replay the token and act as the user.

Debug print left in

A developer logs an object during development that contains an API key. The statement ships to production and records the key on every call.

PII in access logs

An endpoint puts personal data in the URL or logs the full payload, so names and emails land in access logs forwarded to a third-party service.

AI risk

Why AI-generated code has increased the exposure

  • Assistants optimize for helpful debugging output, so asked to log a request or error they print the whole object, secrets and all.
  • Training data contains countless log the request and console.log the object examples, so the model reproduces broad logging that sweeps in sensitive fields.
  • The model cannot tell which fields in a given payload are secret, so it logs the password or token alongside the harmless data.
  • When scaffolding error handling, the assistant logs full headers and bodies to aid diagnosis, which captures tokens and credentials.
  • Because generated code logs liberally across many handlers, the volume of logging statements multiplies the places a secret can be recorded.

Vibe coding

How vibe coding amplifies the risk

  • Vibe coding ships verbose logging the assistant added, and logs that help debugging feel helpful, not dangerous.
  • The skipped review is where someone would notice a log statement is printing a password or token.
  • Debug logging added in a prototype to see what is going on is promoted to production, where it quietly records secrets on every call.
  • The leak is invisible in local and demo testing because the logs look useful and nobody checks them for sensitive values.
  • As a vibe-coded app wires up log aggregation and monitoring, the secrets already in the logs are copied into more systems with broad access.

Detection

How to find it

  • Grep logging statements for request bodies, headers, and whole objects that could contain passwords, tokens, or personal data.
  • Search existing log output for secret-shaped strings and known key formats to find what is already being recorded.
  • Review error and debug handlers that log full requests or exceptions with their context.
  • Check that log sinks and third-party forwarders are not receiving fields that should never leave the app.

Remediation

How to fix it

  • Log identifiers and event descriptions, never raw credentials, tokens, or full request bodies.
  • Add redaction or allowlist-based serialization so known sensitive fields are masked before anything is written.
  • Remove debug logging of objects and headers before shipping, and gate verbose logging behind a safe non-production setting.
  • Scrub or rotate any secret already present in logs, since the recorded value must be treated as leaked.
  • Restrict and monitor access to log stores and forwarders, and set retention so sensitive records are not kept indefinitely.

Frequently asked questions

What is CWE-532 (insertion of sensitive information into log file)?
CWE-532 is when sensitive data such as passwords, tokens, or personal information is written into log files, exposing it to anyone who can read the logs. Because logs are forwarded to many systems and retained for a long time, a secret logged once is effectively leaked broadly.
How have AI assistants and vibe coding increased the risk?
Assistants optimize for helpful debugging output and reproduce log the whole request and object examples, so they print secrets they cannot distinguish from harmless fields. Vibe coding ships that verbose logging because it looks useful, and nobody inspects the logs for sensitive values before production.
How do I fix sensitive information in logs?
Log identifiers rather than raw credentials or full bodies, add redaction for known sensitive fields, remove debug logging before shipping, rotate any secret already recorded, and restrict and time-limit access to log stores.

Related weaknesses

Catch CWE-532 before you ship

Tethlyn Audit scans your codebase and its git history for CWE-532 and the rest of the sensitive data exposure & privacy class, then ranks each finding by real exploitability and data sensitivity.

See Tethlyn Audit