CVE-2021-23400 (published 2021-06-29T12:15Z)

The package nodemailer before 6.6.1 are vulnerable to HTTP Header Injection if unsanitized user input that may contain newlines and carriage returns is passed into an address object.

Severity: MEDIUM
CVSS v2 base score: 6.8 (AV:N/AC:M/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 8.8, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-74
cwe_name: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
extended_description: Software or other automated logic has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features that classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed.
         

Fix information:
repo_url: https://github.com/nodemailer/nodemailer
commit_details: repo_url: https://github.com/nodemailer/nodemailer
author: Andris Reinman
author_date: 2021-05-23 13:18:53+03:00
msg: v6.6.1
repository: repo_url: https://github.com/nodemailer/nodemailer
repo_name: nodemailer/nodemailer
description: ✉️ Send e-mails with Node.JS – easy as cake!
repo_language: JavaScript
owner: nodemailer
file_changes: filename: .travis.yml
change_type: ModificationType.MODIFY
diff: @@ -4,7 +4,7 @@ node_js:
     - 10
     - 12
     - 14
-    - 15
+    - 16
 notifications:
     email:
         - andris@kreata.ee

programming_language: Markdown
filename: CHANGELOG.md
change_type: ModificationType.MODIFY
diff: @@ -1,5 +1,9 @@
 # CHANGELOG
 
+## 6.6.1 2021-05-23
+
+-   Fixed address formatting issue where newlines in an email address, if provided via address object, were not properly removed. Reported by tmazeika (#1289)
+
 ## 6.6.0 2021-04-28
 
 -   Added new option `newline` for MailComposer

programming_language: Markdown
filename: mailcomposer.js
change_type: ModificationType.MODIFY
diff: @@ -9,7 +9,9 @@ const mailOptions = {
         from: 'Daemon <deamon@kreata.ee>',
         to: 'mailer@kreata.ee, Mailer <mailer2@kreata.ee>'
     },
-    text: 'Test\n 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ö\r\nsage',
+    text: `Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?'
+
+So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.`,
     newline: '\r\n'
 };
 

programming_language: JavaScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -1147,9 +1147,9 @@ class MimeNode {
                 address.address = this._normalizeAddress(address.address);
 
                 if (!address.name) {
-                    values.push(address.address);
+                    values.push(address.address.indexOf(' ') >= 0 ? `<${address.address}>` : `${address.address}`);
                 } else if (address.name) {
-                    values.push(this._encodeAddressName(address.name) + ' <' + address.address + '>');
+                    values.push(`${this._encodeAddressName(address.name)} <${address.address}>`);
                 }
 
                 if (address.address) {
@@ -1158,9 +1158,8 @@ class MimeNode {
                     }
                 }
             } else if (address.group) {
-                values.push(
-                    this._encodeAddressName(address.name) + ':' + (address.group.length ? this._convertAddresses(address.group, uniqueList) : '').trim() + ';'
-                );
+                let groupListAddresses = (address.group.length ? this._convertAddresses(address.group, uniqueList) : '').trim();
+                values.push(`${this._encodeAddressName(address.name)}:${groupListAddresses};`);
             }
         });
 
@@ -1174,13 +1173,17 @@ class MimeNode {
      * @return {String} address string
      */
     _normalizeAddress(address) {
-        address = (address || '').toString().trim();
+        address = (address || '')
+            .toString()
+            .replace(/[\x00-\x1F<>]+/g, ' ') // remove unallowed characters
+            .trim();
 
         let lastAt = address.lastIndexOf('@');
         if (lastAt < 0) {
             // Bare username
             return address;
         }
+
         let user = address.substr(0, lastAt);
         let domain = address.substr(lastAt + 1);
 
@@ -1189,7 +1192,24 @@ class MimeNode {
         // 'jõgeva.ee' will be converted to 'xn--jgeva-dua.ee'
         // non-unicode domains are left as is
 
-        return user + '@' + punycode.toASCII(domain.toLowerCase());
+        let encodedDomain;
+
+        try {
+            encodedDomain = punycode.toASCII(domain.toLowerCase());
+        } catch (err) {
+            // keep as is?
+        }
+
+        if (user.indexOf(' ') >= 0) {
+            if (user.charAt(0) !== '"') {
+                user = '"' + user;
+            }
+            if (user.substr(-1) !== '"') {
+                user = user + '"';
+            }
+        }
+
+        return `${user}@${encodedDomain}`;
     }
 
     /**

programming_language: JavaScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,6 @@
 {
     "name": "nodemailer",
-    "version": "6.6.0",
+    "version": "6.6.1",
     "description": "Easy as cake e-mail sending from your Node.js applications",
     "main": "lib/nodemailer.js",
     "scripts": {
@@ -31,7 +31,7 @@
         "libbase64": "1.2.1",
         "libmime": "5.0.0",
         "libqp": "1.1.0",
-        "mocha": "8.3.2",
+        "mocha": "8.4.0",
         "nodemailer-ntlm-auth": "1.0.1",
         "proxy": "1.0.2",
         "proxy-test-server": "1.0.0",

programming_language: JavaScript