logo

Database

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.

Weakness:

052 - Insecure encryption algorithm

Category: Information Collection

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
...