No console.log or console.debug in production code paths
Why it matters
Unguarded console.log calls in production code expose internal data structures — user objects, API responses, internal state — to browser consoles and server logs. CWE-532 (Insertion of Sensitive Information into Log File) applies when logged objects include user data, tokens, or application secrets. Beyond the data exposure risk, console.log in server-side code that runs on every request floods logs with noise, making real errors and security incidents harder to detect. AI-generated codebases accumulate debug logs that were never removed before shipping.
Severity rationale
Low because `console.log` in production primarily causes data leakage and log noise rather than direct security exploitation, though CWE-532 applies when logged objects contain sensitive data.
Remediation
Add an ESLint rule to flag production console calls:
"no-console": ["warn", { "allow": ["warn", "error"] }]
Replace debug logging with a structured logger that is environment-aware:
// lib/logger.ts
export const logger = {
info: (msg: string, data?: object) => {
if (process.env.NODE_ENV !== 'production') console.log(msg, data)
// In production: send to your logging service
},
error: (msg: string, error?: unknown) => console.error(msg, error)
}
Server-side route handlers should never call console.log on every request — use structured logging with sampling instead.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Code Maintainability Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · maintainability.analysability — Analysability
- cwe · CWE-532 — Insertion of Sensitive Information into Log File
Taxons
History
- 2026-04-18·v1.0.0·Initial import from code-maintainability·automated