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-003 --project .About This Rule
Understanding the vulnerability and how it is detected
Python's code module provides the InteractiveConsole, InteractiveInterpreter, and interact() classes and functions which implement a Python read-eval-print loop (REPL). These are intended for debugging and development tooling; when exposed to or called with untrusted input in production code, they grant the caller full Python code execution capability.
code.InteractiveConsole().interact() drops into a full Python REPL. code.compile_command() partially compiles Python source and is used as a building block for interactive interpreters. Any application that pipes untrusted network or user input into these components effectively gives the attacker a remote Python shell on the server.
These functions are legitimate for local development tools, administrative debug consoles that are properly authenticated, and embedded REPL features. They become dangerous when exposed unauthenticated over a network or when the input source is not strictly controlled.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Remote Python Shell
An unauthenticated or improperly authenticated code.interact() endpoint gives the attacker a full interactive Python interpreter with the privileges of the web server process, equivalent to SSH access to the host.
Unrestricted File System Access
Through the interactive console, an attacker can read, write, and delete any file accessible to the process, including application secrets, SSL private keys, database credentials, and user data.
Process and System Control
The interactive console can spawn subprocesses, open network connections, modify environment variables, send signals to other processes, and call any system call available to Python, giving the attacker complete control of the host environment.
Debug Endpoint Exposure
Development debug panels (such as Werkzeug's debug console) that use code module internals are commonly left enabled in production deployments. This is a well-known and frequently exploited attack vector in Python web applications.
How to Fix
Recommended remediation steps
- 1Never expose code.InteractiveConsole or code.interact() over an unauthenticated network endpoint.
- 2In production deployments, disable any debug console or REPL endpoint; ensure DEBUG=False in all production configuration.
- 3If an admin REPL is required, gate it behind strong multi-factor authentication, restrict to localhost or a VPN-only interface, and log all commands executed.
- 4Replace interactive consoles with purpose-built admin CLIs that accept an explicit allowlist of commands without arbitrary code execution.
- 5Use a process supervisor or container runtime that provides exec access only to authorized operations teams rather than exposing a Python REPL.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to code.InteractiveConsole(), code.interact(), code.compile_command(), and code.InteractiveInterpreter() from the Python standard library code module. All call sites are flagged as these functions are designed for interactive interpreter use and are inappropriate in production application code that processes external input.
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.
Non-literal Dynamic Import Detected
__import__() or importlib.import_module() with a non-literal argument can import arbitrary modules when called with untrusted input.
Frequently Asked Questions
Common questions about Dangerous code.InteractiveConsole Usage
New feature
Get these findings posted directly on your GitHub pull requests
The Dangerous code.InteractiveConsole Usage rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.