Python Core

Python Core rules for Python

54
Security Rules

Run All Python Core Rules

pathfinder scan --ruleset python/lang --project .

Rules

Dangerous eval() Usage Detected

HIGH

eval() executes arbitrary Python expressions from strings, enabling remote code execution when called with untrusted input.

pythonevalcode-injectiondynamic-executionbuiltinsCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Dangerous exec() Usage Detected

HIGH

exec() executes arbitrary Python statements from strings or code objects, enabling remote code execution when called with untrusted input.

pythonexeccode-injectiondynamic-executionbuiltinsCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Dangerous code.InteractiveConsole Usage

HIGH

code.InteractiveConsole and code.interact() enable arbitrary Python code execution and should not be exposed to untrusted users.

pythoncode-moduleinteractive-consolecode-executionreplCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Dangerous globals() Usage Detected

MEDIUM

globals() exposes the module's global namespace as a mutable dictionary, allowing arbitrary attribute injection when passed to untrusted code.

pythonglobalsnamespace-injectiondynamic-executionCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Non-literal Dynamic Import Detected

MEDIUM

__import__() or importlib.import_module() with a non-literal argument can import arbitrary modules when called with untrusted input.

pythondynamic-importimport-injection__import__importlibCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Dangerous typing.get_type_hints() Usage

MEDIUM

typing.get_type_hints() evaluates string annotations as Python expressions, enabling code execution when annotation strings contain untrusted content.

pythonannotationsget-type-hintspep-563type-evaluationCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Dangerous os.system() or os.popen() Call

HIGH

os.system() and os.popen() execute shell commands via /bin/sh, enabling command injection when arguments contain untrusted input.

pythonos-systemos-popencommand-injectionshell-injectionCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

Dangerous os.exec*() Call

HIGH

os.exec*() replaces the current process image with a new program, enabling arbitrary program execution when arguments are untrusted.

pythonos-execcommand-injectionprocess-replacementCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

Dangerous os.spawn*() Call

HIGH

os.spawn*() spawns a new process and can execute arbitrary programs when the executable path or arguments are derived from untrusted input.

pythonos-spawnprocess-spawncommand-injectionCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

Shell Command with Wildcard Character

MEDIUM

os.system() calls containing wildcard characters (*) may lead to unintended file inclusion or command injection through wildcard expansion.

pythonwildcardglob-expansioncommand-injectionos-systemCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

Python Reverse Shell Pattern Detected

CRITICAL

Reverse shell pattern detected using socket connections with subprocess or exec(). This is a strong indicator of malicious code or a backdoor.

pythonreverse-shellbackdoormalicious-codesocketCWE-506OWASP-A03
CWE-506
Updated 2026-03-22

Dangerous subprocess Usage

HIGH

subprocess calls detected. Ensure command arguments are not user-controlled to prevent OS command injection.

pythonsubprocesscommand-injectionprocess-executionCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

subprocess Called with shell=True

HIGH

subprocess called with shell=True passes the command through the system shell, enabling command injection when any part of the command contains untrusted input.

pythonsubprocessshell-truecommand-injectionshell-injectionCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

Dangerous asyncio Shell Execution

HIGH

asyncio.create_subprocess_shell() passes the command through the system shell, enabling command injection when arguments contain untrusted input.

pythonasyncioshellcommand-injectionasyncCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

Dangerous subinterpreters run_string() Usage

HIGH

subinterpreters.run_string() executes arbitrary Python code strings in sub-interpreters, enabling code injection when called with untrusted input.

pythonsubinterpreterscode-executionsub-interpreterCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Insecure MD5 Hash Usage

MEDIUM

MD5 is cryptographically broken and unsuitable for security-sensitive purposes. Use SHA-256 or SHA-3 instead.

pythonmd5weak-hashcryptographyhashlibCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

Insecure SHA-1 Hash Usage

MEDIUM

SHA-1 is cryptographically weak due to practical collision attacks. Use SHA-256 or SHA-3 for security-sensitive hashing.

pythonsha1weak-hashcryptographyhashlibCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

Insecure Hash via hashlib.new()

MEDIUM

hashlib.new() with an insecure algorithm name (MD5, SHA1, SHA-224) creates a cryptographically weak hash. Use SHA-256 or SHA-3.

pythonhashlib-newweak-hashalgorithm-selectioncryptographyCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

SHA-224 or SHA3-224 Weak Hash Usage

LOW

SHA-224 and SHA3-224 provide only 112-bit collision resistance, which is below the 128-bit minimum recommended by NIST for new applications.

pythonsha224sha3-224insufficient-bit-lengthcryptographyhashlibCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

MD5 Used for Password Hashing

HIGH

MD5 is being used to hash passwords. MD5 is cryptographically broken and orders of magnitude too fast for password hashing. Use bcrypt, scrypt, or argon2.

pythonmd5password-hashingweak-password-storagecredentialsCWE-916OWASP-A02
CWE-916
Updated 2026-03-22

Pickle Deserialization of Untrusted Data

HIGH

pickle.loads() and pickle.load() execute arbitrary Python code during deserialization. Never unpickle data from untrusted sources.

pythonpickledeserializationarbitrary-code-executionCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

PyYAML Unsafe Load Function

HIGH

yaml.load() and yaml.unsafe_load() can execute arbitrary Python objects during YAML parsing. Use yaml.safe_load() instead.

pythonyamlpyyamlunsafe-loaddeserializationCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

jsonpickle Deserialization Detected

HIGH

jsonpickle.decode() can execute arbitrary Python code during deserialization. Use the standard json module for untrusted data.

pythonjsonpickledeserializationcode-executionCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

ruamel.yaml Unsafe Loader Configuration

HIGH

ruamel.yaml configured with typ='unsafe' can instantiate arbitrary Python objects during YAML parsing. Use typ='safe' or the default round-trip loader.

pythonruamel-yamlunsafe-yamldeserializationCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

marshal Deserialization Detected

MEDIUM

marshal.loads() and marshal.load() are not secure against erroneous or malicious data and should not be used to deserialize untrusted input.

pythonmarshaldeserializationbytecodeCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

shelve Module Usage Detected

MEDIUM

shelve.open() uses pickle internally for value serialization and is not safe for storing or retrieving data from untrusted sources.

pythonshelvepickledeserializationfile-storageCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

dill Deserialization Detected

HIGH

dill.loads() and dill.load() extend pickle with broader serialization capabilities and can execute arbitrary code when deserializing untrusted data.

pythondillpickle-extensiondeserializationcode-executionCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

Unverified SSL Context Created

HIGH

ssl._create_unverified_context() disables certificate verification entirely, making TLS connections vulnerable to man-in-the-middle attacks.

pythonssltlscertificate-validationmitmCWE-295OWASP-A02
CWE-295
Updated 2026-03-22

Weak SSL/TLS Protocol Version

HIGH

SSLContext configured with SSLv2, SSLv3, TLSv1.0, or TLSv1.1 uses deprecated protocols with known vulnerabilities. Use TLS 1.2 or TLS 1.3.

pythonssltlsweak-protocoldeprecated-tlsCWE-326OWASP-A02
CWE-326
Updated 2026-03-22

Deprecated ssl.wrap_socket() Usage

MEDIUM

ssl.wrap_socket() is deprecated since Python 3.7 and should be replaced with SSLContext.wrap_socket() for proper TLS configuration.

pythonsslwrap-socketdeprecated-apitls-configurationCWE-326OWASP-A02
CWE-326
Updated 2026-03-22

Certificate Validation Disabled (verify=False)

HIGH

TLS certificate validation is explicitly disabled via verify=False or CERT_NONE, making connections vulnerable to man-in-the-middle attacks.

pythonssltlsverify-falsecert-validationmitmCWE-295OWASP-A02
CWE-295
Updated 2026-03-22

Insecure HTTP Connection via http.client

MEDIUM

http.client.HTTPConnection transmits data in plaintext without encryption. Use HTTPSConnection for sensitive communications.

pythonhttp-clientplaintextcleartext-transmissionCWE-319OWASP-A02
CWE-319
Updated 2026-03-22

HTTP Request Without TLS (requests library)

MEDIUM

HTTP URLs in requests calls transmit data in plaintext without encryption. Use HTTPS URLs for sensitive data transmission.

pythonrequestshttpplaintextcleartext-transmissionCWE-319OWASP-A02
CWE-319
Updated 2026-03-22

Insecure urllib.request.urlopen() Usage

MEDIUM

urllib.request.urlopen() over HTTP transmits data in plaintext. Verify HTTPS URLs are used and SSL context is properly configured.

pythonurlliburlopenplaintexthttpCWE-319OWASP-A02
CWE-319
Updated 2026-03-22

Insecure urllib Request Object Usage

MEDIUM

urllib.request.Request() and OpenerDirector used with HTTP URLs transmit data in plaintext. Verify HTTPS URLs are used.

pythonurllibrequest-objectplaintexthttpCWE-319OWASP-A02
CWE-319
Updated 2026-03-22

FTP Without TLS (ftplib.FTP)

MEDIUM

ftplib.FTP() transmits data and credentials in plaintext. Use ftplib.FTP_TLS() or SFTP (via paramiko) for secure file transfer.

pythonftpftplibplaintextfile-transferCWE-319OWASP-A02
CWE-319
Updated 2026-03-22

telnetlib Usage Detected

HIGH

telnetlib.Telnet() transmits all data including credentials in plaintext. Replace with SSH (paramiko) for remote command execution.

pythontelnettelnetlibplaintextremote-accessCWE-319OWASP-A02
CWE-319
Updated 2026-03-22

Socket Bound to All Interfaces (0.0.0.0)

MEDIUM

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.

pythonsocketbindall-interfacesnetwork-exposureCWE-668OWASP-A05
CWE-668
Updated 2026-03-22

Paramiko Implicit Host Key Trust (AutoAddPolicy)

HIGH

paramiko.AutoAddPolicy() and WarningPolicy() automatically accept unknown SSH host keys, enabling man-in-the-middle attacks on SSH connections.

pythonparamikosshhost-keymitmCWE-322OWASP-A02
CWE-322
Updated 2026-03-22

Paramiko exec_command() Usage

MEDIUM

paramiko exec_command() runs commands on a remote host. Audit that command arguments are not derived from untrusted input to prevent command injection.

pythonparamikosshexec-commandcommand-injectionCWE-78OWASP-A03
CWE-78
Updated 2026-03-22

multiprocessing Connection.recv() Usage

MEDIUM

multiprocessing.Connection.recv() uses pickle internally and is not safe for receiving data from untrusted connections.

pythonmultiprocessingrecvpickledeserializationCWE-502OWASP-A08
CWE-502
Updated 2026-03-22

psycopg2 SQL Injection via String Formatting

CRITICAL

SQL query built with string formatting passed to psycopg2 cursor.execute() enables SQL injection. Use parameterized queries with %s placeholders.

pythonpsycopg2sql-injectionpostgresqldatabaseCWE-89OWASP-A03
CWE-89
Updated 2026-03-22

Formatted SQL Query Passed to cursor.execute()

HIGH

SQL query built with string formatting detected. String-formatted SQL strings are a common SQL injection vector. Use parameterized queries.

pythonsql-injectionstring-formattingcursor-executedatabaseCWE-89OWASP-A03
CWE-89
Updated 2026-03-22

Insecure XML Parsing (XXE Vulnerability)

MEDIUM

xml.etree.ElementTree is vulnerable to XML External Entity (XXE) attacks. Use defusedxml for safe XML parsing.

pythonxmlxxexml-external-entityelementtreeCWE-611OWASP-A05
CWE-611
Updated 2026-03-22

Insecure xml.dom.minidom Usage (XXE)

MEDIUM

xml.dom.minidom is vulnerable to XML External Entity (XXE) attacks. Use defusedxml.minidom for safe XML parsing.

pythonminidomxmlxxexml-external-entityCWE-611OWASP-A05
CWE-611
Updated 2026-03-22

Insecure xmlrpc Usage (XXE Risk)

MEDIUM

xmlrpc.client.ServerProxy and xmlrpc.server modules are vulnerable to XXE attacks via malicious XML-RPC payloads. Use defusedxml.xmlrpc for protection.

pythonxmlrpcxxexml-rpcremote-procedure-callCWE-611OWASP-A05
CWE-611
Updated 2026-03-22

Mako Template Usage Detected

MEDIUM

Mako templates execute Python expressions without sandboxing. Ensure templates are from trusted sources and user input is not rendered as template code.

pythonmakotemplate-injectionsstiserver-side-template-injectionCWE-94OWASP-A03
CWE-94
Updated 2026-03-22

csv.writer Audit (Formula Injection Risk)

LOW

csv.writer() detected. Audit CSV output for formula injection (CSV injection) if data is exported to spreadsheet applications.

pythoncsvformula-injectioncsv-injectionspreadsheetCWE-1236OWASP-A03
CWE-1236
Updated 2026-03-22

UUID Version 1 Leaks MAC Address

LOW

uuid.uuid1() embeds the host MAC address in the generated UUID, leaking hardware identity information.

pythonuuiduuid1information-disclosuremac-addressprivacyCWE-200OWASP-A05
CWE-200
Updated 2026-03-22

Insecure File Permissions via os.chmod

MEDIUM

os.chmod() or os.fchmod() sets overly permissive file permissions that allow unauthorized read, write, or execute access.

pythonfile-permissionsos-chmodos-fchmodworld-writableworld-readableCWE-732OWASP-A05
CWE-732
Updated 2026-03-22

Hardcoded Password in Default Function Argument

HIGH

A function defines a default argument whose name suggests a password or secret but whose value is a hardcoded string literal.

pythonhardcoded-passworddefault-argumentsecret-in-codecredentialsCWE-259OWASP-A07
CWE-259
Updated 2026-03-22

Regex DoS Risk

LOW

Detects re.compile(), re.match(), re.search(), and re.findall() calls that should be audited for catastrophic backtracking patterns.

pythonregexredosdenial-of-serviceauditCWE-1333OWASP-A06
CWE-1333
Updated 2026-03-22

logging.config.listen() Eval Risk

HIGH

Detects logging.config.listen() which opens a socket that accepts and executes arbitrary logging configuration, enabling remote code execution.

pythonloggingcode-executionnetworkCWE-95OWASP-A03
CWE-95
Updated 2026-03-22

Logger Credential Leak Risk

MEDIUM

Detects logging calls (info, debug, warning, error, critical) that should be audited for accidental credential or secret leakage in log output.

pythonloggingcredentialsinformation-disclosureauditCWE-532OWASP-A09
CWE-532
Updated 2026-03-22