logo

Database

Javascript Rsa No Padding

Description

This detector identifies RSA cryptographic operations that use insecure padding schemes in JavaScript code. Using RSA without proper padding (like PKCS#1 v1.5 or OAEP) makes the encryption vulnerable to padding oracle attacks and other cryptographic vulnerabilities, potentially allowing attackers to decrypt data or forge signatures.

Weakness:

052 - Insecure encryption algorithm

Category: Information Collection

Detection Strategy

    • Scans JavaScript source code for RSA cryptographic function calls and configurations

    • Identifies when RSA encryption, decryption, or signing operations are performed without secure padding schemes

    • Triggers when RSA operations use 'NoPadding', missing padding parameters, or other insecure padding configurations

    • Reports vulnerabilities in crypto libraries, Web Crypto API usage, or third-party cryptographic modules where RSA padding is improperly configured

Vulnerable code example

const crypto = require("crypto");

function encryptWithNoPadding(data, publicKey) {
  // VULNERABLE: RSA_NO_PADDING makes encryption deterministic and malleable
  return crypto.publicEncrypt(
    { key: publicKey, padding: crypto.constants.RSA_NO_PADDING },
    data
  );...

✅ Secure code example

const crypto = require("crypto");

function encryptWithNoPadding(data, publicKey) {
  // SAFE: Use OAEP padding instead of no padding to prevent attacks
  return crypto.publicEncrypt(
    { key: publicKey, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING },
    data
  );...