Python Rsa Legacy Padding
Description
This vulnerability detector identifies the use of legacy RSA PKCS#1 v1.5 padding scheme in Python cryptographic operations. PKCS#1 v1.5 padding is vulnerable to padding oracle attacks and has been deprecated in favor of more secure padding schemes like OAEP (Optimal Asymmetric Encryption Padding).
Detection Strategy
• Reports when code uses PyCryptodome's Crypto.Cipher.PKCS1_v1_5.new() method for RSA encryption/decryption
• Reports when code uses cryptography library's PKCS1v15 padding with encrypt() or decrypt() operations
• Triggers specifically when importing and using either PyCryptodome's legacy PKCS1_v1_5 cipher or when passing PKCS1v15 padding as an argument to RSA encryption/decryption functions
Vulnerable code example
from cryptography.hazmat.primitives.asymmetric import padding
from Crypto.Cipher import PKCS1_v1_5
def encrypt_data(public_key, data):
# VULNERABLE: Uses legacy PKCS#1 v1.5 padding scheme
return public_key.encrypt(data, padding.PKCS1v15())
def decrypt_data(private_key, ciphertext):...✅ Secure code example
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes
from Crypto.Cipher import PKCS1_OAEP
def encrypt_data(public_key, data):
# SECURE: Uses OAEP padding instead of vulnerable PKCS#1 v1.5
return public_key.encrypt(
data,...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.