Ruby Rsa Legacy Padding
Description
This detector identifies Ruby applications using RSA encryption with legacy padding schemes that are cryptographically insecure. Legacy padding methods like PKCS#1 v1.5 are vulnerable to padding oracle attacks, which can allow attackers to decrypt encrypted data or forge digital signatures without knowing the private key.
Detection Strategy
• The detector first checks if the OpenSSL library is imported in the Ruby code, as this is required for RSA operations
• It then scans for RSA-related method calls and expressions throughout the codebase
• The detector flags code that uses legacy RSA padding APIs or creates new RSA instances with insecure padding configurations
• Specifically looks for both deprecated legacy API usage and new API calls that specify vulnerable padding schemes
• A vulnerability is reported when RSA encryption/decryption operations are found that do not use secure padding methods like OAEP
Vulnerable code example
require 'openssl'
def encrypt_data(message)
rsa = OpenSSL::PKey::RSA.new(2048)
# VULNERABLE: Uses deprecated PKCS1_PADDING vulnerable to padding oracle attacks
rsa.public_encrypt(message, OpenSSL::PKey::RSA::PKCS1_PADDING)
end
...✅ Secure code example
require 'openssl'
def encrypt_data(message)
rsa = OpenSSL::PKey::RSA.new(2048)
# SAFE: Uses OAEP padding which is secure against padding oracle attacks
rsa.public_encrypt(message, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
end
...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.