Typescript Rsa No Padding
Description
This vulnerability detector identifies usage of RSA encryption without proper padding in TypeScript code. RSA encryption without padding (NoPadding) is cryptographically insecure and vulnerable to various attacks including chosen plaintext attacks, making encrypted data susceptible to decryption by attackers.
Detection Strategy
• The detector scans TypeScript source code for RSA cryptographic operations
• It identifies method calls or configurations where RSA encryption is implemented without secure padding schemes
• A vulnerability is reported when RSA encryption uses 'NoPadding' or equivalent insecure padding configurations
• The detection focuses on cryptographic library calls that specify padding parameters for RSA operations
Vulnerable code example
import { constants, publicEncrypt, publicDecrypt, privateEncrypt } from "crypto";
function encryptNoPadding(data: Buffer, key: string): Buffer {
// VULNERABLE: RSA_NO_PADDING disables padding, making encryption insecure
return publicEncrypt({ key: key, padding: constants.RSA_NO_PADDING }, data);
}
function decryptNoPadding(data: Buffer, key: string): Buffer {...✅ Secure code example
import { constants, publicEncrypt, publicDecrypt, privateEncrypt } from "crypto";
function encryptNoPadding(data: Buffer, key: string): Buffer {
// SAFE: uses OAEP padding which is secure for RSA encryption
return publicEncrypt({ key: key, padding: constants.RSA_PKCS1_OAEP_PADDING }, data);
}
function decryptNoPadding(data: Buffer, key: string): Buffer {...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.