# general-crypto-python-v1

> general-crypto-python-v1: 11 Keryn rules for python (2 error, 9 warning).

Source: https://keryn.dev/rules/general-crypto-python-v1/

11 rules · Keryn Software Licence · rules 0.8.0 · [all packs](https://keryn.dev/rules/)

**How to read a rule**

- **Severity**: How bad the finding is if it is real: `error` fails a default gate, `warning` and `info` do 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

`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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-327](https://keryn.dev/taxonomies/cwe/#cwe-327) [CWE-328](https://keryn.dev/rules/?cwe=CWE-328) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://docs.python.org/3/library/hashlib.html#hashlib.new) · [https://cryptography.io/en/latest/hazmat/primitives/cryptographic-hashes/#sha-1](https://cryptography.io/en/latest/hazmat/primitives/cryptographic-hashes/#sha-1) · [https://csrc.nist.gov/pubs/sp/800/131/a/r2/final](https://csrc.nist.gov/pubs/sp/800/131/a/r2/final)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-916](https://keryn.dev/rules/?cwe=CWE-916) [CWE-327](https://keryn.dev/taxonomies/cwe/#cwe-327) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://docs.python.org/3.12/library/crypt.html#hashing-methods) · [https://peps.python.org/pep-0594/#crypt](https://peps.python.org/pep-0594/#crypt)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-327](https://keryn.dev/taxonomies/cwe/#cwe-327) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://cryptography.io/en/latest/hazmat/decrepit/ciphers/) · [https://www.pycryptodome.org/src/cipher/cipher](https://www.pycryptodome.org/src/cipher/cipher) · [https://sweet32.info/](https://sweet32.info/)

## 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](https://keryn.dev/docs/edges/edge-kinds/#trusts) one party believes another without evidence.

[CWE-327](https://keryn.dev/taxonomies/cwe/#cwe-327) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption/#cryptography.hazmat.primitives.ciphers.modes.ECB) · [https://www.pycryptodome.org/src/cipher/classic#ecb-mode](https://www.pycryptodome.org/src/cipher/classic#ecb-mode)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-326](https://keryn.dev/rules/?cwe=CWE-326) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/#generation) · [https://csrc.nist.gov/pubs/sp/800/131/a/r2/final](https://csrc.nist.gov/pubs/sp/800/131/a/r2/final)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-327](https://keryn.dev/taxonomies/cwe/#cwe-327) [CWE-757](https://keryn.dev/rules/?cwe=CWE-757) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://docs.python.org/3/library/ssl.html#ssl.SSLContext.minimum_version) · [https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.Context](https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.Context) · [https://datatracker.ietf.org/doc/html/rfc8996](https://datatracker.ietf.org/doc/html/rfc8996)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-327](https://keryn.dev/taxonomies/cwe/#cwe-327) [CWE-757](https://keryn.dev/rules/?cwe=CWE-757) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://docs.python.org/3/library/ssl.html#protocol-versions) · [https://datatracker.ietf.org/doc/html/rfc8996](https://datatracker.ietf.org/doc/html/rfc8996)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-295](https://keryn.dev/rules/?cwe=CWE-295) [CWE-327](https://keryn.dev/taxonomies/cwe/#cwe-327) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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.11/library/ssl.html#ssl.wrap_socket) · [https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket](https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket)

## 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](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-295](https://keryn.dev/rules/?cwe=CWE-295) [CWE-322](https://keryn.dev/rules/?cwe=CWE-322) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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](https://docs.paramiko.org/en/stable/api/client.html#paramiko.client.SSHClient.set_missing_host_key_policy)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party; it crosses the [`secret->outside`](https://keryn.dev/docs/edges/trust-boundaries/#secret-to-outside) boundary (a secret leaving the trusted side).

[CWE-319](https://keryn.dev/rules/?cwe=CWE-319) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**Fix:** Use UsmUserData(user, authKey, privKey, authProtocol=usmHMAC192SHA256AuthProtocol, privProtocol=usmAesCfb128Protocol).

**References:** [https://docs.lextudio.com/pysnmp/v7.1/docs/api-reference#security-parameters](https://docs.lextudio.com/pysnmp/v7.1/docs/api-reference#security-parameters) · [https://datatracker.ietf.org/doc/html/rfc3414](https://datatracker.ietf.org/doc/html/rfc3414)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party; it crosses the [`secret->outside`](https://keryn.dev/docs/edges/trust-boundaries/#secret-to-outside) boundary (a secret leaving the trusted side).

[CWE-319](https://keryn.dev/rules/?cwe=CWE-319) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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://docs.python.org/3/library/ftplib.html#ftplib.FTP_TLS) · [https://peps.python.org/pep-0594/#telnetlib](https://peps.python.org/pep-0594/#telnetlib)
