Php Rsa No Padding
Description
This detector identifies RSA encryption/decryption operations that use no padding or unsafe padding schemes. RSA without proper padding is vulnerable to various cryptographic attacks including chosen plaintext attacks and can leak information about the encrypted data.
Detection Strategy
• Scans PHP code for calls to OpenSSL RSA functions that handle encryption, decryption, signing, or verification operations
• Identifies when these RSA functions are called with padding arguments that specify no padding or unsafe padding constants
• Reports a vulnerability when RSA cryptographic operations explicitly disable padding protection mechanisms
Vulnerable code example
<?php
function encryptData($plaintext, $publicKey) {
// VULNERABLE: OPENSSL_NO_PADDING disables RSA padding, making encryption deterministic and malleable
openssl_public_encrypt($plaintext, $encrypted, $publicKey, OPENSSL_NO_PADDING);
return $encrypted;
}
...✅ Secure code example
<?php
function encryptData($plaintext, $publicKey) {
// SAFE: OPENSSL_PKCS1_OAEP_PADDING provides secure, non-deterministic encryption
openssl_public_encrypt($plaintext, $encrypted, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
return $encrypted;
}
...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.