Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-LANG-SEC-104 --project .About This Rule
Understanding the vulnerability and how it is detected
This rule detects calls to logging.config.listen(), which starts a socket server that accepts logging configuration over the network. By default, the received configuration is processed using logging.config.dictConfig() or logging.config.fileConfig(), which can execute arbitrary Python code through handler class references and filter callables.
An attacker who can connect to the listening port can send a configuration dict that specifies a handler class like os.system, effectively achieving remote code execution. Python's own documentation warns that "this function is useful for updating logging configuration from a remote machine, but it is not secure."
The rule matches LoggingConfig.method("listen") and fires on any invocation.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Remote Code Execution via Configuration
The listener accepts dictConfig-format payloads over TCP. A crafted config can specify arbitrary Python callables as handler classes, filter functions, or formatter factories. This executes code in the context of the application process with its full permissions.
No Authentication by Default
logging.config.listen() binds to a port with no authentication, encryption, or access control. Any process that can connect to the port can send config. On a server with a public IP, this is directly exploitable from the internet.
Privilege Escalation
If the application runs as root or with elevated permissions, an attacker who sends a malicious config gains those same permissions. In containerized environments, this can lead to container escape.
How to Fix
Recommended remediation steps
- 1Remove logging.config.listen() from production code entirely
- 2Use static logging configuration via dictConfig() or fileConfig() loaded at startup
- 3If remote logging reconfiguration is needed, implement it through your application's authenticated API, not through logging.config.listen()
- 4Bind logging listeners to localhost only if they must exist, and restrict access via firewall rules
- 5Use Python 3.2+ verify parameter to provide a verification function that validates configs before applying
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule matches calls to logging.config.listen() via the QueryType pattern LoggingConfig.method("listen"). It fires on any invocation regardless of arguments, since the function opens a network socket that accepts executable configuration by default.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
Dangerous eval() Usage Detected
eval() executes arbitrary Python expressions from strings, enabling remote code execution when called with untrusted input.
Dangerous exec() Usage Detected
exec() executes arbitrary Python statements from strings or code objects, enabling remote code execution when called with untrusted input.
Logger Credential Leak Risk
Detects logging calls (info, debug, warning, error, critical) that should be audited for accidental credential or secret leakage in log output.
Frequently Asked Questions
Common questions about logging.config.listen() Eval Risk
New feature
Get these findings posted directly on your GitHub pull requests
The logging.config.listen() Eval Risk rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.