Skip to content

Commit e65e9f1

Browse files
[AUTO-CHERRYPICK] Fixed CVE-2023-42282 in nodejs. - branch main (#8159)
Co-authored-by: chalamalasetty <42326515+chalamalasetty@users.noreply.github.com>
1 parent 3249aa8 commit e65e9f1

3 files changed

Lines changed: 123 additions & 3 deletions

File tree

SPECS/nodejs/CVE-2023-42282.patch

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
From 32f468f1245574785ec080705737a579be1223aa Mon Sep 17 00:00:00 2001
2+
From: Luke McFarlane <luke@innoware.com.au>
3+
Date: Mon, 12 Feb 2024 13:22:18 +1100
4+
Subject: [PATCH] lib: fixed CVE-2023-42282 and added unit test
5+
6+
Unit test code is not applicable for NodeJS sources hence not included.
7+
8+
diff --git a/deps/npm/node_modules/ip/lib/ip.js b/deps/npm/node_modules/ip/lib/ip.js
9+
index 4b2adb5add..9022443ae5 100644
10+
--- a/deps/npm/node_modules/ip/lib/ip.js
11+
+++ b/deps/npm/node_modules/ip/lib/ip.js
12+
@@ -306,12 +306,26 @@ ip.isEqual = function (a, b) {
13+
};
14+
15+
ip.isPrivate = function (addr) {
16+
- return /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i
17+
- .test(addr)
18+
+ // check loopback addresses first
19+
+ if (ip.isLoopback(addr)) {
20+
+ return true;
21+
+ }
22+
+
23+
+ // ensure the ipv4 address is valid
24+
+ if (!ip.isV6Format(addr)) {
25+
+ const ipl = ip.normalizeToLong(addr);
26+
+ if (ipl < 0) {
27+
+ throw new Error('invalid ipv4 address');
28+
+ }
29+
+ // normalize the address for the private range checks that follow
30+
+ addr = ip.fromLong(ipl);
31+
+ }
32+
+
33+
+ // check private ranges
34+
+ return /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr)
35+
|| /^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr)
36+
|| /^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i
37+
.test(addr)
38+
- || /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr)
39+
|| /^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr)
40+
|| /^f[cd][0-9a-f]{2}:/i.test(addr)
41+
|| /^fe80:/i.test(addr)
42+
@@ -324,9 +338,16 @@ ip.isPublic = function (addr) {
43+
};
44+
45+
ip.isLoopback = function (addr) {
46+
+ // If addr is an IPv4 address in long integer form (no dots and no colons), convert it
47+
+ if (!/\./.test(addr) && !/:/.test(addr)) {
48+
+ addr = ip.fromLong(Number(addr));
49+
+ }
50+
+
51+
return /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/
52+
.test(addr)
53+
- || /^fe80::1$/.test(addr)
54+
+ || /^0177\./.test(addr)
55+
+ || /^0x7f\./i.test(addr)
56+
+ || /^fe80::1$/i.test(addr)
57+
|| /^::1$/.test(addr)
58+
|| /^::$/.test(addr);
59+
};
60+
@@ -420,3 +441,51 @@ ip.fromLong = function (ipl) {
61+
ipl >> 8 & 255}.${
62+
ipl & 255}`);
63+
};
64+
+
65+
+ip.normalizeToLong = function (addr) {
66+
+ const parts = addr.split('.').map(part => {
67+
+ // Handle hexadecimal format
68+
+ if (part.startsWith('0x') || part.startsWith('0X')) {
69+
+ return parseInt(part, 16);
70+
+ }
71+
+ // Handle octal format (strictly digits 0-7 after a leading zero)
72+
+ else if (part.startsWith('0') && part !== '0' && /^[0-7]+$/.test(part)) {
73+
+ return parseInt(part, 8);
74+
+ }
75+
+ // Handle decimal format, reject invalid leading zeros
76+
+ else if (/^[1-9]\d*$/.test(part) || part === '0') {
77+
+ return parseInt(part, 10);
78+
+ }
79+
+ // Return NaN for invalid formats to indicate parsing failure
80+
+ else {
81+
+ return NaN;
82+
+ }
83+
+ });
84+
+
85+
+ if (parts.some(isNaN)) return -1; // Indicate error with -1
86+
+
87+
+ let val = 0;
88+
+ const n = parts.length;
89+
+
90+
+ switch (n) {
91+
+ case 1:
92+
+ val = parts[0];
93+
+ break;
94+
+ case 2:
95+
+ if (parts[0] > 0xff || parts[1] > 0xffffff) return -1;
96+
+ val = (parts[0] << 24) | (parts[1] & 0xffffff);
97+
+ break;
98+
+ case 3:
99+
+ if (parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xffff) return -1;
100+
+ val = (parts[0] << 24) | (parts[1] << 16) | (parts[2] & 0xffff);
101+
+ break;
102+
+ case 4:
103+
+ if (parts.some(part => part > 0xff)) return -1;
104+
+ val = (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3];
105+
+ break;
106+
+ default:
107+
+ return -1; // Error case
108+
+ }
109+
+
110+
+ return val >>> 0;
111+
+};

SPECS/nodejs/nodejs.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Name: nodejs
55
# WARNINGS: MUST check and update the 'npm_version' macro for every version update of this package.
66
# The version of NPM can be found inside the sources under 'deps/npm/package.json'.
77
Version: 16.20.2
8-
Release: 2%{?dist}
8+
Release: 3%{?dist}
99
License: BSD AND MIT AND Public Domain AND NAIST-2003 AND Artistic-2.0
1010
Vendor: Microsoft Corporation
1111
Distribution: Mariner
@@ -18,6 +18,7 @@ Source0: https://nodejs.org/download/release/v%{version}/node-v%{version}
1818
Patch0: disable-tlsv1-tlsv1-1.patch
1919
Patch1: CVE-2022-25883.patch
2020
Patch2: CVE-2023-35945.patch
21+
Patch3: CVE-2023-42282.patch
2122
BuildRequires: brotli-devel
2223
BuildRequires: c-ares-devel
2324
BuildRequires: coreutils >= 8.22
@@ -115,6 +116,10 @@ make cctest
115116
%{_datadir}/systemtap/tapset/node.stp
116117

117118
%changelog
119+
* Mon Feb 26 2024 Suresh Babu Chalamalasetty <schalam@microsoft.com> - 16.20.2-3
120+
- Patch CVE-2023-42282
121+
- Unit test code is not applicable for this NodeJS version sources
122+
118123
* Wed Sep 06 2023 Brian Fjeldstad <bfjelds@microsoft.com> - 16.20.2-2
119124
- Patch CVE-2023-35945
120125

SPECS/nodejs/nodejs18.spec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Name: nodejs18
66
# WARNINGS: MUST check and update the 'npm_version' macro for every version update of this package.
77
# The version of NPM can be found inside the sources under 'deps/npm/package.json'.
88
Version: 18.18.2
9-
Release: 2%{?dist}
9+
Release: 3%{?dist}
1010
License: BSD and MIT and Public Domain and NAIST-2003 and Artistic-2.0
1111
Group: Applications/System
1212
Vendor: Microsoft Corporation
@@ -17,7 +17,7 @@ URL: https://github.com/nodejs/node
1717
# !!! => use clean-source-tarball.sh script to create a clean and reproducible source tarball.
1818
Source0: https://nodejs.org/download/release/v%{version}/node-v%{version}.tar.xz
1919
Patch0: disable-tlsv1-tlsv1-1.patch
20-
20+
Patch1: CVE-2023-42282.patch
2121
BuildRequires: brotli-devel
2222
BuildRequires: coreutils >= 8.22
2323
BuildRequires: gcc
@@ -116,6 +116,10 @@ make cctest
116116
%{_datadir}/systemtap/tapset/node.stp
117117

118118
%changelog
119+
* Mon Feb 26 2024 Suresh Babu Chalamalasetty <schalam@microsoft.com> - 18.18.2-3
120+
- Patch CVE-2023-42282
121+
- Unit test code is not applicable for this NodeJS version sources
122+
119123
* Thu Oct 19 2023 Dan Streetman <ddstreet@ieee.org> - 18.18.2-2
120124
- Re-enable building debuginfo. We can just ignore the dirs conflict failure in the pipelines! :)
121125

0 commit comments

Comments
 (0)