Hub rules-python

rules-python

v4 public Verified

Python

Python is an interpreted, high-level, general-purpose programming language known for its readability. These rules govern idiomatic coding practices, environment management, and core library usage.

@sigmashakeinc 6 pulls 27 rules published Apr 8, 2026 synced Oct 11, 2026 sigmashakeinc/rules/rulesets/rules-python →
Severity
21 error 6 warn 0 info
demo.cast
Python is an interpreted, high-level, general-purpose programming language known for its readability. These rules govern idiomatic coding practices, environment management, and core library usage.

Rules index

27 governance rules

Indexed from the repository's .rules files, grouped by technology. Expand any rule to read the raw source.

python

no-assert-for-validation warning log

assert statements are stripped when Python runs with -O (optimize). Use explicit if/raise for input validation in production code.

Rule source requires an active Pro or Enterprise subscription.
no-bare-except error block

Bare 'except:' or 'except Exception:' swallows all errors including KeyboardInterrupt and SystemExit. Catch specific exception types.

Rule source requires an active Pro or Enterprise subscription.
no-django-secret-key-hardcoded error block

RISK: a hardcoded Django SECRET_KEY compromises session/CSRF signing if committed. FIX: SECRET_KEY = os.environ['DJANGO_SECRET_KEY'] and provision per-environment.

Rule source requires an active Pro or Enterprise subscription.
no-eval-exec error block

eval() and exec() allow arbitrary code execution and are banned. Refactor to use safe alternatives — if you need dynamic dispatch, use a dict of callables.

Rule source requires an active Pro or Enterprise subscription.
no-flask-debug-true error block

RISK: Flask/Werkzeug debug mode exposes an interactive PIN-protected console that allows RCE if the PIN is leaked (CVE-2024-34069 class). FIX: never ship debug=True; gate on an env var that is False in production.

Rule source requires an active Pro or Enterprise subscription.
no-hardcoded-secrets error block

RISK: hardcoded credentials leak when code is committed or shared. FIX: load secrets from environment variables (os.environ) or a secret manager; add the pattern to pre-commit gitleaks.

Rule source requires an active Pro or Enterprise subscription.
no-jinja2-autoescape-off error block

RISK: Jinja2 Environment() defaults to autoescape=False, enabling XSS in HTML templates. FIX: pass autoescape=select_autoescape(['html','xml']) or autoescape=True.

Rule source requires an active Pro or Enterprise subscription.
no-ldap-injection error block

RISK: string interpolation in LDAP search filters enables LDAP injection (CWE-90). FIX: escape all user-supplied values with ldap3.utils.conv.escape_filter_chars() or ldap.filter.escape_filter_chars() before inserting into a filter string.

Rule source requires an active Pro or Enterprise subscription.
no-marshal-loads error block

RISK: marshal.loads() on untrusted data can execute arbitrary code (CWE-502) — marshal is not a safe serialisation format. FIX: use json or a schema-validated format; marshal is intended only for Python bytecode internals.

Rule source requires an active Pro or Enterprise subscription.
no-md5-sha1-for-security warning log

RISK: MD5/SHA1 are broken for security use (collisions, length-extension). FIX: use hashlib.sha256() for integrity, or hashlib.blake2b()/SHA-3; add usedforsecurity=False only for non-security hashing.

Rule source requires an active Pro or Enterprise subscription.
no-mutable-default-arg warning log

Mutable default arguments (lists, dicts) are shared across all calls. Use None as default and initialize inside the function body.

Rule source requires an active Pro or Enterprise subscription.
no-open-path-traversal error log

RISK: open() with a user-supplied or interpolated path can escape the intended directory (path traversal, CWE-22). FIX: resolve and validate the path with os.path.realpath() and confirm it starts with the expected base directory before opening.

Rule source requires an active Pro or Enterprise subscription.
no-os-system error block

os.system() and os.popen() pass commands to the shell unsanitized. Use subprocess.run() with a list of arguments and shell=False.

Rule source requires an active Pro or Enterprise subscription.
no-pickle-loads error block

pickle.loads() with untrusted data is a remote code execution vulnerability. Use json.loads() or a safe serialization format for untrusted input.

Rule source requires an active Pro or Enterprise subscription.
no-print-in-src warning log

print() detected in source code. Use the logging module for structured output that can be controlled in production.

Rule source requires an active Pro or Enterprise subscription.
no-random-for-tokens error block

RISK: random module is not cryptographically secure and is predictable. FIX: use the secrets module — secrets.token_urlsafe(32), secrets.token_hex(), or secrets.choice().

Rule source requires an active Pro or Enterprise subscription.
no-requests-timeout-missing warning log

RISK: requests calls without timeout= can hang indefinitely, causing resource exhaustion. FIX: pass timeout=(connect, read) seconds, e.g. requests.get(url, timeout=(5, 30)).

Rule source requires an active Pro or Enterprise subscription.
no-requests-verify-false error block

RISK: verify=False disables TLS certificate validation, enabling MITM attacks. FIX: remove the argument, or pass verify='/path/to/ca-bundle.pem' for a private CA.

Rule source requires an active Pro or Enterprise subscription.
no-shell-true error block

subprocess with shell=True passes the command through the shell, enabling injection attacks. Use shell=False and pass arguments as a list.

Rule source requires an active Pro or Enterprise subscription.
no-sql-string-format error block

String formatting in SQL queries enables SQL injection. Use parameterized queries: cursor.execute('SELECT * FROM t WHERE id = %s', (user_id,))

Rule source requires an active Pro or Enterprise subscription.
no-ssl-unverified-context error block

RISK: ssl._create_unverified_context / CERT_NONE disables certificate verification. FIX: use ssl.create_default_context() and configure a trusted CA bundle.

Rule source requires an active Pro or Enterprise subscription.
no-subprocess-user-input error log

subprocess calls with string interpolation/concatenation enable command injection. Pass arguments as a list with shell=False: subprocess.run(['cmd', user_arg], shell=False)

Rule source requires an active Pro or Enterprise subscription.
no-tarfile-extractall-unfiltered error block

RISK: tarfile extractall without filter= is vulnerable to path traversal (CVE-2007-4559); Python 3.14 requires explicit filter. FIX: pass filter='data' to reject absolute paths, symlinks, and special files.

Rule source requires an active Pro or Enterprise subscription.
no-tempfile-mktemp error block

RISK: tempfile.mktemp() has a TOCTOU race — an attacker can pre-create the path as a symlink. FIX: use tempfile.mkstemp() or NamedTemporaryFile(), which atomically create the file.

Rule source requires an active Pro or Enterprise subscription.
no-wildcard-import warning log

Wildcard imports pollute the namespace and make it hard to trace where names come from. Use explicit imports.

Rule source requires an active Pro or Enterprise subscription.
no-xml-untrusted-parser error block

RISK: stdlib xml parsers are vulnerable to XXE, billion-laughs, and entity-expansion attacks on untrusted input. FIX: use defusedxml (pip install defusedxml) as a drop-in replacement.

Rule source requires an active Pro or Enterprise subscription.
no-yaml-load-unsafe error block

yaml.load() with untrusted input allows arbitrary code execution. Use yaml.safe_load() instead.

Rule source requires an active Pro or Enterprise subscription.

Version metadata

Published metadata

The hash-locked record of this published ruleset. When source contents change, the maintainer resyncs and the version bumps.

Version
v4
Published
Apr 8, 2026
Source commits
0
Synced
Oct 11, 2026
Hash
08c9daeca44925a622ac45b0784db031e8127f917c4016e4292e2c72675f808c
Signature
Verified (publisher key)
Tested with
claude-code@current
Plan
Starter (free)
Visibility
Public

Source history

Recent commits

Latest commits touching rulesets/rules-python/.sigmashake/rules in sigmashakeinc/rules/rulesets/rules-python. The published version only bumps when a maintainer resyncs.

No commit history available.