general-crypto-python-v1
11 rules · Keryn Software Licence · rules 0.8.0 · all packs
How to read a rule
- Severity
- How bad the finding is if it is real:
errorfails a default gate,warningandinfodo not. - Confidence
- P0 exploitable as written; P1 dangerous in context; P2 a heuristic or a posture check: confirm by reading the code.
- False-positive risk
- low: an exact API or flag, so hits are almost always real; medium: the pattern is legitimate in many programs, so check each hit; high: it finds a lead to confirm, so expect benign hits.
- Edge
- The relationship the finding sits on. reaches: content or traffic gets to a thing; calls: one thing invokes another; reads: one thing reads from another; writes: one thing writes to another; sends: data leaves for another party; grants: authority is given or left unchecked; depends_on: something relies on a component it does not verify; trusts: one party believes another without evidence. The boundary it crosses, when there is one: user->prompt (untrusted input reaching a prompt); model->code (model output reaching code, a shell, a query or a page); secret->outside (a secret leaving the trusted side); supply-chain (code, models or prompts pulled in from outside).
- Taxonomy chips
- References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.
keryn.general.python.weak-hash
Section titled “keryn.general.python.weak-hash”warning python python, hashlib, cryptography, pycryptodome
MD2, MD4, MD5 and SHA-1 have practical collision attacks, so a digest from them does not prove integrity and must not protect passwords, signatures or tokens. hashlib calls marked usedforsecurity=False are not reported.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: sends data leaves for another party.
Fix: Use SHA-256 or stronger (hashlib.sha256, hashes.SHA256) for integrity, an HMAC for authentication, and argon2/scrypt/bcrypt for passwords; mark a non-security checksum with hashlib.md5(data, usedforsecurity=False).
References: https://docs.python.org/3/library/hashlib.html#hashlib.new · https://cryptography.io/en/latest/hazmat/primitives/cryptographic-hashes/#sha-1 · https://csrc.nist.gov/pubs/sp/800/131/a/r2/final
keryn.general.python.weak-crypt-method
Section titled “keryn.general.python.weak-crypt-method”warning python python
crypt with METHOD_CRYPT (DES), METHOD_MD5 or METHOD_BLOWFISH produces password hashes that are fast to brute-force or truncate the password. The crypt module is also removed from Python 3.13.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party.
Fix: Hash passwords with argon2-cffi, hashlib.scrypt or bcrypt, with a per-password salt and a work factor reviewed yearly.
References: https://docs.python.org/3.12/library/crypt.html#hashing-methods · https://peps.python.org/pep-0594/#crypt
keryn.general.python.weak-cipher
Section titled “keryn.general.python.weak-cipher”warning python python, cryptography, pycryptodome
RC2, RC4, Blowfish, DES, Triple-DES, CAST5, IDEA, SEED and XOR are broken or legacy ciphers: short keys, 64-bit blocks (Sweet32) or keystream biases let an attacker recover plaintext. Encrypt with AES-GCM or ChaCha20-Poly1305.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party.
Fix: Use an authenticated cipher: cryptography.hazmat.primitives.ciphers.aead.AESGCM / ChaCha20Poly1305, or PyCryptodome AES in MODE_GCM, with a fresh nonce per message.
References: https://cryptography.io/en/latest/hazmat/decrepit/ciphers/ · https://www.pycryptodome.org/src/cipher/cipher · https://sweet32.info/
keryn.general.python.ecb-mode
Section titled “keryn.general.python.ecb-mode”warning python python, cryptography, pycryptodome
ECB encrypts every block independently, so equal plaintext blocks give equal ciphertext blocks and the structure of the data shows through. Use an authenticated mode such as GCM.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: trusts one party believes another without evidence.
Fix: Switch to AESGCM (cryptography) or AES.new(key, AES.MODE_GCM) (PyCryptodome) with a unique nonce per message.
References: https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption/#cryptography.hazmat.primitives.ciphers.modes.ECB · https://www.pycryptodome.org/src/cipher/classic#ecb-mode
keryn.general.python.weak-key-size
Section titled “keryn.general.python.weak-key-size”warning python python, cryptography, pycryptodome
The RSA/DSA key is shorter than 2048 bits or the elliptic curve is below 224 bits. Keys this small are within reach of factoring or discrete-log attacks and are disallowed by NIST SP 800-131A.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party.
Fix: Generate RSA keys of 3072 bits (2048 at the very least), DSA only for legacy verification, and EC keys on SECP256R1 or stronger (or Ed25519).
References: https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/#generation · https://csrc.nist.gov/pubs/sp/800/131/a/r2/final
keryn.general.python.ssl-insecure-protocol
Section titled “keryn.general.python.ssl-insecure-protocol”error python python, ssl, pyopenssl
The TLS context or socket is pinned to SSL 2/3, TLS 1.0/1.1 or the legacy SSLv23 negotiation constant. These protocol versions have known downgrade and decryption attacks (POODLE, BEAST) and are disabled by modern peers.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party.
Fix: Create the context with ssl.create_default_context() (or SSLContext(PROTOCOL_TLS_CLIENT)) and set minimum_version = ssl.TLSVersion.TLSv1_2; for pyOpenSSL use TLS_METHOD with set_min_proto_version(TLS1_2_VERSION).
References: https://docs.python.org/3/library/ssl.html#ssl.SSLContext.minimum_version · https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.Context · https://datatracker.ietf.org/doc/html/rfc8996
keryn.general.python.ssl-insecure-protocol-default
Section titled “keryn.general.python.ssl-insecure-protocol-default”warning python python, ssl, pyopenssl
A function takes its TLS protocol version as a parameter whose default is SSL 2/3, TLS 1.0/1.1 or the SSLv23 constant, so every caller that omits it gets a broken protocol.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party.
Fix: Default the parameter to None and build the context with ssl.create_default_context(); require TLS 1.2 or later.
References: https://docs.python.org/3/library/ssl.html#protocol-versions · https://datatracker.ietf.org/doc/html/rfc8996
keryn.general.python.ssl-wrap-socket
Section titled “keryn.general.python.ssl-wrap-socket”warning python python, ssl
ssl.wrap_socket was deprecated in 3.7 and removed in 3.12. It builds a context without hostname checking and, unless ssl_version is given, negotiates whatever the platform default allows.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party.
Fix: ctx = ssl.create_default_context(); ctx.minimum_version = ssl.TLSVersion.TLSv1_2; ctx.wrap_socket(sock, server_hostname=host).
References: https://docs.python.org/3.11/library/ssl.html#ssl.wrap_socket · https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket
keryn.general.python.paramiko-auto-add-host-key
Section titled “keryn.general.python.paramiko-auto-add-host-key”error python paramiko
set_missing_host_key_policy(AutoAddPolicy / WarningPolicy) accepts any host key the server presents, so a man-in-the-middle can impersonate the SSH server and read or alter the session.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: depends_on something relies on a component it does not verify; it crosses the supply-chain boundary (code, models or prompts pulled in from outside).
Fix: Load known hosts (client.load_system_host_keys() / load_host_keys(path)) and keep the default RejectPolicy; pin the expected key for automation.
References: https://docs.paramiko.org/en/stable/api/client.html#paramiko.client.SSHClient.set_missing_host_key_policy
keryn.general.python.snmp-insecure-security
Section titled “keryn.general.python.snmp-insecure-security”warning python pysnmp
SNMP v1/v2c community data, or SNMPv3 user data without both an authentication and a privacy key (noAuthNoPriv / authNoPriv), sends credentials and values in clear text.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party; it crosses the secret->outside boundary (a secret leaving the trusted side).
Fix: Use UsmUserData(user, authKey, privKey, authProtocol=usmHMAC192SHA256AuthProtocol, privProtocol=usmAesCfb128Protocol).
References: https://docs.lextudio.com/pysnmp/v7.1/docs/api-reference#security-parameters · https://datatracker.ietf.org/doc/html/rfc3414
keryn.general.python.cleartext-protocol-client
Section titled “keryn.general.python.cleartext-protocol-client”warning python python
telnetlib.Telnet and ftplib.FTP send the login and all data unencrypted, so anyone on the network path can read or change them. telnetlib is also removed from Python 3.13.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party; it crosses the secret->outside boundary (a secret leaving the trusted side).
Fix: Use SSH (paramiko / asyncssh) instead of Telnet and ftplib.FTP_TLS (with prot_p()) or SFTP instead of FTP.
References: https://docs.python.org/3/library/ftplib.html#ftplib.FTP_TLS · https://peps.python.org/pep-0594/#telnetlib