logo

Database

Python Log Injection Unescaped Input

Description

Detects log injection vulnerabilities where unsanitized user input is passed directly to Python logging functions (info, debug, warning, error, critical). This could allow attackers to inject malicious payloads into log files, potentially leading to log forging or log file manipulation.

Weakness:

091 - Log injection

Category: System Manipulation

Detection Strategy

    Check if the Python 'logging' library is imported in the code

    Look for calls to logging functions: info(), debug(), warning(), error(), critical()

    Verify if any arguments passed to these logging functions contain unsanitized user input

    Report a vulnerability if user-controlled data flows into logging function calls without proper sanitization

Vulnerable code example

from flask import Flask, request
import logging

app = Flask(__name__)
logging.basicConfig(level=logging.INFO)

@app.route("/redirect")
def redirect_page():...

✅ Secure code example

from flask import Flask, request, redirect, escape
import logging
from urllib.parse import urlparse, urljoin

app = Flask(__name__)
logging.basicConfig(level=logging.INFO)

# Whitelist of allowed redirect paths...