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-CRYPTO-SEC-001 --project .About This Rule
Understanding the vulnerability and how it is detected
This rule detects instantiation of the ARC4 (RC4) algorithm via the `cryptography` library's `cryptography.hazmat.primitives.ciphers.algorithms.ARC4` class. RC4 was once widely deployed in SSL/TLS, WEP, and WPA, but it has been cryptographically broken for over a decade.
RC4 produces a biased keystream: the first few bytes are strongly correlated with the key, and the output distribution is non-uniform across the full byte range. The BEAST, RC4NOMORE, and related attacks exploit these biases to recover plaintext from captured ciphertext. RFC 7465 explicitly prohibits RC4 in all versions of TLS, and NIST SP 800-131A disallows it for federal use.
The rule matches `CryptoCipherAlgorithms.method("ARC4")` — any call to the ARC4 constructor in the hazmat algorithms module. There is no safe configuration for RC4; the algorithm itself is the problem, regardless of key size.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Biased Keystream Enables Plaintext Recovery
RC4's keystream is statistically biased from the very first byte. Attackers who observe enough ciphertext encrypted under the same or related keys can statistically recover the plaintext. The RC4NOMORE attack demonstrated full HTTP cookie recovery in under 75 hours against a live HTTPS connection using only network traffic capture.
Prohibited in TLS by RFC 7465
RFC 7465 (2015) mandates that TLS implementations MUST NOT negotiate any RC4-based cipher suite. Code that uses RC4 in a network context directly violates this requirement and will fail compliance reviews for any system handling PCI DSS, HIPAA, or FedRAMP data.
No Authentication -- Ciphertext is Malleable
RC4 provides only stream confidentiality, with no built-in integrity or authentication. An attacker who can flip bits in the ciphertext will produce predictable, corresponding bit flips in the plaintext, enabling undetected message tampering without knowledge of the key.
Key Reuse Eliminates All Security
If the same RC4 key is ever reused across two messages, an attacker who XORs the two ciphertexts removes the keystream entirely. Both plaintexts can then be recovered using statistical analysis. WEP was broken at scale this way, and the same risk applies to any RC4-encrypted data at rest or in transit.
How to Fix
Recommended remediation steps
- 1Replace ARC4 with AES-256-GCM (AESGCM from cryptography.hazmat.primitives.ciphers.aead) for authenticated encryption
- 2Use ChaCha20-Poly1305 (ChaCha20Poly1305) as an alternative when AES hardware acceleration is unavailable
- 3Never reuse a key with any stream cipher -- generate a cryptographically random key per encryption operation
- 4Migrate any data previously encrypted with RC4 by decrypting and re-encrypting under AES-256-GCM with a new key
- 5Run this rule in CI to prevent RC4 from being reintroduced during future development or library upgrades
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule matches calls to the ARC4 constructor in the cryptography library's hazmat algorithms module via the QueryType pattern `CryptoCipherAlgorithms.method("ARC4")`. It fires whenever the ARC4 class is instantiated, regardless of key size or any surrounding wrapper logic. There is no safe configuration for RC4, so no sanitizer exclusions apply. The companion rule PYTHON-CRYPTO-SEC-001a covers the same algorithm in the PyCryptodome library.
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
RC4 (ARC4) Cipher Usage via PyCryptodome
Detects use of the RC4 stream cipher through PyCryptodome's ARC4 module, which has known keystream biases and is prohibited by RFC 7465.
Blowfish Cipher Usage via cryptography Library
Detects use of the Blowfish cipher through the cryptography library, which has a 64-bit block size making it vulnerable to Sweet32 birthday attacks after approximately 32GB of data.
DES Cipher Usage via PyCryptodome
Detects use of single DES through PyCryptodome, which has only a 56-bit key that has been publicly brute-forceable since 1999 and is disallowed by FIPS 46-3 (withdrawn 2005).
Frequently Asked Questions
Common questions about RC4 (ARC4) Cipher Usage via cryptography Library
New feature
Get these findings posted directly on your GitHub pull requests
The RC4 (ARC4) Cipher Usage via cryptography Library rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.