Don't Log That! Avoiding Sensitive Info Leaks with VibeSafe

By Justin Mendez on 5/7/2025

Scanners

Logging: Your Debugging Superpower (and Security Risk)

Application logs are invaluable. They provide a trail of events, errors, and state changes that are essential for debugging issues, monitoring application health, and understanding user behavior. When something goes wrong, logs are often the first place we look.

But this indispensable tool can quickly become a security liability if not handled carefully. The risk? Accidentally logging sensitive information.

What kind of sensitive information?

  • Passwords (even masked ones, sometimes the masking fails)
  • API Keys or other credentials
  • Session Tokens
  • Personally Identifiable Information (PII) like names, addresses, email addresses, phone numbers, credit card details (partially or fully)
  • Detailed internal error messages or stack traces that reveal system architecture.

Logging this data creates a new attack surface. If log files are compromised (through server misconfiguration, unauthorized access, or vulnerabilities in log aggregation systems), attackers gain direct access to potentially valuable secrets or user data.

How Sensitive Data Ends Up in Logs

Similar to hardcoded secrets, sensitive data usually gets logged accidentally:

  1. Logging Entire Objects: Developers might log entire request objects, user objects, or configuration objects for debugging, inadvertently including sensitive fields within those objects.
    • Example: console.log("User object:", user); where user contains password or apiKey fields.
  2. Verbose Error Logging: Catching an exception and logging the entire exception object, which might include sensitive parameters or overly detailed stack traces.
    • Example: catch (error) { console.error("API call failed:", error); } where error might contain request headers with tokens.
  3. Debugging Statements Left In: console.log or similar statements used during development to inspect sensitive variables might be forgotten and committed.
  4. Third-Party Libraries: Some libraries might have verbose logging enabled by default that includes sensitive data.

In the heat of debugging or rapid feature development ("vibe coding"), it's easy to add a quick log statement without fully considering the security implications of what is being logged.

How VibeSafe Helps: Spotting Risky Logging Patterns

Manually reviewing every single log statement in a growing codebase is impractical. VibeSafe provides automated assistance with its 🪵 Improper Logging Patterns check:

  • Identifies Logging Functions: Recognizes common logging functions (console.log, console.error, logger.info, etc.) across various languages and frameworks.
  • Looks for Sensitive Keywords: Scans the data being passed to these logging functions for keywords commonly associated with sensitive information (e.g., password, apiKey, secret, token, creditCard, ssn, etc.).
  • Flags Suspicious Object Logging: Warns when entire complex objects (like req, user, error) are logged, as these often contain nested sensitive data.
  • Detects Full Stack Trace Logging: Flags patterns that might log full, detailed stack traces, which could leak internal path or library information.

Example VibeSafe Alert:

WARN: Potential logging of sensitive keyword 'password' detected.
  File: src/controllers/authController.js
  Line: 45
  Detail: `console.log('Login attempt for user:', username, 'with password:', password);`

WARN: Logging entire request object 'req' might leak sensitive headers or body data.
  File: src/middleware/requestLogger.js
  Line: 10
  Detail: `logger.debug('Incoming request:', req);`

INFO: Logging full error object. Consider logging only relevant error messages/codes in production.
  File: src/utils/errorHandler.js
  Line: 22
  Detail: `console.error('Unhandled exception:', error);`

VibeSafe acts as a helpful reminder to critically evaluate what information your application is recording.

Best Practices for Secure Logging

  • Log What You Need, Not Everything: Be intentional about the data you log. Avoid logging entire objects if you only need specific fields.
  • Never Log Raw Secrets: Passwords, API keys, tokens should never appear in logs.
  • Sanitize PII: If you need to log user-related information, filter or mask sensitive PII before logging.
  • Structured Logging: Use libraries that support structured logging (e.g., JSON format). This makes logs easier to parse and often encourages more deliberate field selection.
  • Control Log Levels: Use different log levels (DEBUG, INFO, WARN, ERROR) appropriately. Configure production environments to log only INFO level and above, while development might use DEBUG.
  • Secure Log Storage & Access: Ensure your log files or log aggregation systems have appropriate access controls and retention policies.
  • Code Reviews: Make reviewing log statements part of your code review process.
  • Regular Scanning: Use VibeSafe to continuously catch potentially risky logging patterns introduced during development.

Conclusion: Log Wisely!

Logging is essential, but insecure logging practices can turn this valuable tool into a significant security risk. Accidentally leaking passwords, API keys, or user PII into logs can have severe consequences.

Develop a habit of mindful logging. Be deliberate about what you record, especially when dealing with user data or credentials. Leverage automated tools like VibeSafe to act as a safety net, flagging potentially dangerous logging patterns before they expose sensitive information. Keep your logs useful for debugging, but safe from prying eyes.

Quick Start

npm i -g vibesafe
vibesafe scan