logo

Database

Php Rsa Legacy Padding

Description

This detector identifies PHP code that uses RSA encryption functions with legacy or insecure padding schemes. Legacy padding schemes like PKCS#1 v1.5 are vulnerable to padding oracle attacks, which can lead to complete decryption of sensitive data without knowing the private key.

Weakness:

052 - Insecure encryption algorithm

Category: Information Collection

Detection Strategy

    • Scans PHP source code for function calls that perform RSA encryption operations

    • Identifies specific RSA encryption functions that are known to be vulnerable when used with legacy padding

    • Checks if the RSA encryption function call uses legacy padding schemes (such as PKCS#1 v1.5) instead of secure alternatives like OAEP

    • Reports a vulnerability when an RSA encryption function is called with legacy padding configuration

Vulnerable code example

<?php

// VULNERABLE: Using legacy PKCS#1 v1.5 padding vulnerable to Bleichenbacher attacks
function encryptData($data, $publicKey) {
    openssl_public_encrypt($data, $encrypted, $publicKey, OPENSSL_PKCS1_PADDING);
    return $encrypted;
}
...

✅ Secure code example

<?php

// SAFE: Using OAEP padding which is resistant to padding oracle attacks
function encryptData($data, $publicKey) {
    openssl_public_encrypt($data, $encrypted, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
    return $encrypted;
}
...