ESLint InterlaceESLint Interlace
Plugin: node-securityRules

no-insecure-rsa-padding

ESLint rule documentation for no-insecure-rsa-padding

📡 Live from GitHub — This documentation is fetched directly from no-insecure-rsa-padding.md and cached for 6 hours.

Keywords: RSA, PKCS#1, padding, Marvin Attack, CVE-2023-46809, OAEP, CWE-327, security, ESLint rule CWE: CWE-327
CVE: CVE-2023-46809
OWASP: A02:2021-Cryptographic Failures

Disallow RSA PKCS#1 v1.5 padding (CVE-2023-46809 Marvin Attack)

Detects usage of RSA PKCS#1 v1.5 padding which is vulnerable to the Marvin Attack. This rule is part of eslint-plugin-node-security and provides LLM-optimized error messages with fix suggestions.

🚨 Security rule | 💡 Provides suggestions | ⚠️ Set to error in recommended

Quick Summary

AspectDetails
CWE ReferenceCWE-327 (Broken Crypto)
CVE ReferenceCVE-2023-46809
SeverityHigh (security vulnerability)
Auto-Fix💡 Suggests OAEP padding
CategorySecurity
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForNode.js applications using RSA encryption

Vulnerability and Risk

Vulnerability: RSA PKCS#1 v1.5 padding is vulnerable to timing side-channel attacks known as the "Marvin Attack" (CVE-2023-46809). Node.js's privateDecrypt() function had a timing vulnerability that allowed attackers to decrypt ciphertexts or forge signatures.

Risk: An attacker who can measure the time taken to decrypt ciphertexts can use statistical analysis to recover the plaintext without knowing the private key. This attack was demonstrated against Node.js in 2023.

Rule Details

This rule detects usage of RSA_PKCS1_PADDING in crypto.privateDecrypt(), crypto.publicDecrypt(), crypto.privateEncrypt(), and crypto.publicEncrypt() calls.

Why This Matters

RiskImpactSolution
⏱️ Timing AttackMeasure decryption time to decrypt dataUse RSA_PKCS1_OAEP_PADDING
📜 Signature ForgeryCreate valid signatures without keyNever use PKCS#1 v1.5 for encryption
🔒 CVE-2023-46809Specific Node.js vulnerabilityUpdate Node.js and use OAEP

Configuration

OptionTypeDefaultDescription
allowInTestsbooleanfalseAllow in test files
{
  rules: {
    'node-security/no-insecure-rsa-padding': ['error', {
      allowInTests: false
    }]
  }
}

Examples

❌ Incorrect

import crypto from 'crypto';

// PKCS#1 v1.5 padding - vulnerable to Marvin Attack
const decrypted = crypto.privateDecrypt(
  {
    key: privateKey,
    padding: crypto.constants.RSA_PKCS1_PADDING, // ❌ Vulnerable
  },
  encryptedData,
);

// Also vulnerable patterns
crypto.publicEncrypt(
  {
    key: publicKey,
    padding: constants.RSA_PKCS1_PADDING, // ❌ Vulnerable
  },
  data,
);

✅ Correct

import crypto from 'crypto';

// Use OAEP padding - secure against padding oracle attacks
const decrypted = crypto.privateDecrypt(
  {
    key: privateKey,
    padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, // ✅ Secure
    oaepHash: 'sha256', // Specify hash for OAEP
  },
  encryptedData,
);

// For encryption
const encrypted = crypto.publicEncrypt(
  {
    key: publicKey,
    padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
    oaepHash: 'sha256',
  },
  data,
);

// For signatures, use RSA-PSS instead of PKCS#1 v1.5
const sign = crypto.createSign('RSA-SHA256');
sign.update(data);
const signature = sign.sign({
  key: privateKey,
  padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
});

The Marvin Attack

The Marvin Attack (named after the paranoid android from Hitchhiker's Guide) exploits timing differences in RSA decryption:

  1. Padding Check Timing: PKCS#1 v1.5 decryption checks if padding is valid
  2. Error Timing: Different error paths take different times
  3. Statistical Analysis: Attackers measure thousands of decryption attempts
  4. Key Recovery: Timing differences reveal the plaintext

Security Impact

VulnerabilityCWEOWASPCVSSImpact
Broken Crypto327A02:20217.5 HighPlaintext recovery
Timing Attack208A02:20215.9 MediumSide-channel information leak

Migration Guide

Phase 1: Discovery

{
  rules: {
    'node-security/no-insecure-rsa-padding': 'warn'
  }
}

Phase 2: Replacement

// Replace PKCS#1 v1.5 with OAEP
padding: crypto.constants.RSA_PKCS1_PADDING; // ❌ Before
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING; // ✅ After

Phase 3: Enforcement

{
  rules: {
    'node-security/no-insecure-rsa-padding': 'error'
  }
}

Known False Negatives

Variable Padding Constants

Why: Dynamic values cannot be analyzed statically.

// ❌ NOT DETECTED
const padding = getPaddingFromConfig();
crypto.privateDecrypt({ key, padding }, data);

Mitigation: Use constants directly, avoid indirection.

Further Reading

On this page

No Headings