Logging Vulnerabilities

CWE-117, CWE-221, CWE-223, CWE-532, CWE-778

Logging is a concept that most developers already use for debugging and diagnostic purposes. Security logging is an equally basic concept: to log security information during the runtime operation of an application.

Monitoring is the live review of application and security logs using various forms of automation. The same tools and patterns can be used for operations, debugging and security purposes.

The goal of security logging is to detect and respond to potential security incidents.


Real-World Attack Scenarios

Scenario 1: Log Injection via Unvalidated Input (CWE-117)

An application logs user login attempts without sanitization:

import logging

def log_login_attempt(username, success):
    # VULNERABLE - User input not sanitized
    if success:
        logging.info(f"User {username} logged in successfully")
    else:
        logging.info(f"Failed login attempt for user {username}")

The vulnerability:

User-controlled input written directly to logs:

  • Newline characters (\n) not filtered

  • Attacker can inject fake log entries

  • Can hide malicious activity

  • Can frame other users

  • Can corrupt log files

The attack:

Attacker enters username with embedded newlines:

Resulting log entry:

Looks like admin logged in successfully, hiding the failed attempt.

Or inject malicious entries:

Resulting log:

Attacker hides real attack by injecting fake "all clear" message.

Advanced attack - Log forging:

Attacker frames another user for malicious activity.

Result:

  • Forged audit trail

  • Hidden attack evidence

  • Framing innocent users

  • Corrupted forensic data

  • Investigation misdirection

Finding it: Test login forms and any logged input. Try \n, \r\n, null bytes. Check if log entries can be injected.

Exploit:

The fix:

Sanitize all user input before logging:

Or use structured logging (JSON):


Scenario 2: Passwords in Log Files (CWE-532)

Application logs all HTTP requests including authentication:

The vulnerability:

Sensitive data written to logs:

  • Passwords in POST bodies

  • API keys in headers

  • Session tokens in cookies

  • Credit cards in request data

  • PII (SSN, email, phone) in parameters

The attack:

User logs in with credentials:

Log file contains:

Attacker gains access to log files (misconfiguration, backup exposure, insider threat):

Or API keys:

Result:

  • Mass credential theft

  • Complete account compromise

  • API key leakage

  • PCI DSS violation (logging credit cards)

  • GDPR violation (logging PII)

Finding it: Access log files. Search for passwords, tokens, API keys, credit cards. Check if sensitive data logged.

Exploit:

The fix:

Never log sensitive data:

Or use allowlist approach:


Scenario 3: No Logging of Security Events (CWE-778, CWE-221)

Application doesn't log critical security events:

The vulnerability:

No audit trail for:

  • Failed login attempts

  • Privilege escalation

  • Access to sensitive data

  • Configuration changes

  • User deletions

  • Password changes

  • Admin actions

The attack:

Attacker gains admin access and deletes users:

Investigation reveals nothing:

Result:

  • No incident detection

  • No forensic evidence

  • Cannot identify attacker

  • Cannot determine scope of breach

  • Compliance failure (PCI DSS requires logging)

Finding it: Review code for sensitive operations. Check if logging present. Test security events and verify they appear in logs.

The fix:

Log all security-relevant events:

Or use structured logging:


Scenario 4: Missing Context in Logs (CWE-223)

Application logs events but omits critical information:

The vulnerability:

Logs missing:

  • Username (who logged in?)

  • IP address (from where?)

  • Timestamp (exact time?)

  • User agent (what client?)

  • Session ID (which session?)

The attack:

Attacker performs brute-force attack:

Logs show:

But administrators cannot determine:

  • Which account was attacked

  • Source IP of attack

  • If attack is ongoing

  • If attack targeted multiple accounts

Result:

  • Cannot detect brute-force attacks

  • Cannot block attacker IP

  • Cannot identify compromised accounts

  • Incomplete forensic evidence

Finding it: Review log entries. Check if they contain sufficient context (who, what, when, where, how).

The fix:

Include comprehensive context:

Or structured format:


Scenario 5: Log Files Publicly Accessible

Application stores logs in web-accessible directory:

The vulnerability:

Log files accessible via web browser:

  • No authentication required

  • Directory listing enabled

  • Logs contain sensitive data

  • Anyone can download them

The attack:

Or automated scanning:

Result:

  • Complete log exposure

  • Credential theft

  • Attack pattern visibility

  • Business logic disclosure

  • User behavior tracking

Finding it: Check if /logs/, /log/, /debug/ accessible. Try common log filenames. Look for directory listing.

Exploit:

The fix:

Store logs outside web root:

Restrict permissions:

Disable directory listing:

Block log access:


Scenario 6: Insufficient Failed Login Logging

Application only logs successful logins:

The vulnerability:

No logging of:

  • Failed login attempts

  • Password guessing attacks

  • Brute-force attempts

  • Account enumeration

The attack:

Attacker performs credential stuffing:

After 10,000 attempts, password found. But logs show:

No trace of:

  • 10,000 failed attempts

  • Source IP

  • Attack duration

  • Attack pattern

Result:

  • Brute-force attacks undetected

  • No alerting or blocking

  • Successful compromise invisible until damage done

Finding it: Review authentication code. Check if failed attempts logged. Test with wrong passwords.

The fix:

Log all authentication attempts:

With rate limiting:


Scenario 7: Log Tampering (Inadequate Protection)

Logs stored with weak permissions:

The vulnerability:

Anyone can modify logs:

  • Attacker removes evidence

  • Attacker injects false entries

  • Forensic evidence destroyed

  • Incident investigation impossible

The attack:

Attacker compromises system, deletes traces:

Investigation finds nothing:

Result:

  • Evidence destruction

  • Cannot prove breach occurred

  • Cannot identify attacker

  • Legal proceedings impossible

Finding it: Check file permissions on logs. Test if logs can be modified or deleted.

The fix:

Restrict log permissions:

Use append-only flag:

Send logs to central server:

Use write-once storage:


Mitigation Strategies

Sanitize all logged input

Never log sensitive data

Log all security events

Include comprehensive context

Protect log files

Use structured logging

Centralize logs

Monitor and alert


https://cwe.mitre.org/data/definitions/117.html

Last updated