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-073 --project .About This Rule
Understanding the vulnerability and how it is detected
Python's multiprocessing.Connection.recv() method receives and deserializes data using pickle. When data arrives on the Connection object, recv() calls pickle.loads() internally to reconstruct the Python object from the received bytes. This means that any data received via recv() executes arbitrary Python code if the sender can craft a malicious pickle payload.
multiprocessing Connections are designed for inter-process communication between trusted Python processes in the same application. They become dangerous when exposed over a network socket (via multiprocessing.connection.Client()/Listener()) to untrusted parties.
Use recv_bytes() to receive raw bytes without pickle deserialization, then parse the bytes with a safe format like JSON.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Pickle Deserialization via IPC Channel
recv() calls pickle.loads() on the received bytes. An attacker who can write to the connection (either as a MITM attacker or a malicious process connecting to an exposed Listener) can send a malicious pickle payload that executes arbitrary code in the receiving process.
Listener Exposed to Network
multiprocessing.connection.Listener() can bind to a TCP address. If exposed to a network-accessible address (not localhost), any client can send arbitrary pickle payloads to the Listener, achieving remote code execution.
Authentication Bypass
multiprocessing connections support HMAC-based authentication via the authkey parameter. Without authkey, there is no authentication and any connecting client can send pickle payloads. Even with authkey, compromised keys allow exploitation.
Forked Process Trust Assumption
Code that assumes recv() is safe because "it's only used with forked processes" may be vulnerable if the connection is also exposed to a network or if the expected trusted sender can be replaced by an attacker-controlled process.
How to Fix
Recommended remediation steps
- 1Replace Connection.recv() with Connection.recv_bytes() and parse the received bytes with json.loads() to avoid pickle deserialization.
- 2Always bind multiprocessing Listener() to localhost (127.0.0.1) and not to 0.0.0.0 or a network-accessible address.
- 3Use the authkey parameter for all multiprocessing connections to require HMAC authentication, even between trusted processes.
- 4For inter-process communication that must cross network boundaries, use a proper message queue (Redis, RabbitMQ) with authenticated, schema-validated payloads.
- 5Audit all multiprocessing.connection.Listener() configurations to ensure they are not exposed to untrusted network connections.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to .recv() on multiprocessing Connection objects and related objects that use pickle for deserialization. The rule flags all recv() call sites to prompt review of the connection's trust boundary.
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
Pickle Deserialization of Untrusted Data
pickle.loads() and pickle.load() execute arbitrary Python code during deserialization. Never unpickle data from untrusted sources.
Socket Bound to All Interfaces (0.0.0.0)
Binding a socket to 0.0.0.0 exposes the service on all network interfaces, including public-facing ones. Bind to specific interfaces in production.
Paramiko exec_command() Usage
paramiko exec_command() runs commands on a remote host. Audit that command arguments are not derived from untrusted input to prevent command injection.
Frequently Asked Questions
Common questions about multiprocessing Connection.recv() Usage
New feature
Get these findings posted directly on your GitHub pull requests
The multiprocessing Connection.recv() Usage rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.