77bd23
https://github.com/jbgutierrez/path-parse/pull/10
77bd23
77bd23
From 72c38e3a36b8ed2ec03960ac659aa114cbe6a420 Mon Sep 17 00:00:00 2001
77bd23
From: Jeffrey Pinyan <jeffrey.pinyan@ithreat.com>
77bd23
Date: Thu, 13 May 2021 10:53:50 -0400
77bd23
Subject: [PATCH 1/2] fixed regexes to avoid ReDoS attacks
77bd23
77bd23
Signed-off-by: rpm-build <rpm-build>
77bd23
---
77bd23
 deps/npm/node_modules/path-parse/index.js |  6 +++---
77bd23
 deps/npm/node_modules/path-parse/redos.js | 20 ++++++++++++++++++++
77bd23
 2 files changed, 23 insertions(+), 3 deletions(-)
77bd23
 create mode 100644 deps/npm/node_modules/path-parse/redos.js
77bd23
77bd23
diff --git a/deps/npm/node_modules/path-parse/index.js b/deps/npm/node_modules/path-parse/index.js
77bd23
index 3b7601f..e6b2af1 100644
77bd23
--- a/deps/npm/node_modules/path-parse/index.js
77bd23
+++ b/deps/npm/node_modules/path-parse/index.js
77bd23
@@ -5,11 +5,11 @@ var isWindows = process.platform === 'win32';
77bd23
 // Regex to split a windows path into three parts: [*, device, slash,
77bd23
 // tail] windows-only
77bd23
 var splitDeviceRe =
77bd23
-    /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
77bd23
+    /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?(.*)$/s;
77bd23
77bd23
 // Regex to split the tail part of the above into [*, dir, basename, ext]
77bd23
 var splitTailRe =
77bd23
-    /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
77bd23
+    /^((?:[^\\\/]*[\\\/])*)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
77bd23
77bd23
 var win32 = {};
77bd23
77bd23
@@ -51,7 +51,7 @@ win32.parse = function(pathString) {
77bd23
 // Split a filename into [root, dir, basename, ext], unix version
77bd23
 // 'root' is just a slash, or nothing.
77bd23
 var splitPathRe =
77bd23
-    /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
77bd23
+    /^(\/?|)((?:[^\/]*\/)*)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
77bd23
 var posix = {};
77bd23
77bd23
77bd23
diff --git a/deps/npm/node_modules/path-parse/redos.js b/deps/npm/node_modules/path-parse/redos.js
77bd23
new file mode 100644
77bd23
index 0000000..261947f
77bd23
--- /dev/null
77bd23
+++ b/deps/npm/node_modules/path-parse/redos.js
77bd23
@@ -0,0 +1,20 @@
77bd23
+var pathParse = require('.');
77bd23
+
77bd23
+function build_attack(n) {
77bd23
+    var ret = ""
77bd23
+    for (var i = 0; i < n; i++) {
77bd23
+        ret += "/"
77bd23
+    }
77bd23
+    return ret + "◎";
77bd23
+}
77bd23
+
77bd23
+for(var i = 1; i <= 5000000; i++) {
77bd23
+    if (i % 10000 == 0) {
77bd23
+        var time = Date.now();
77bd23
+        var attack_str = build_attack(i)
77bd23
+        pathParse.posix(attack_str);
77bd23
+        pathParse.win32(attack_str);
77bd23
+        var time_cost = Date.now() - time;
77bd23
+        console.log("attack_str.length: " + attack_str.length + ": " + time_cost+" ms")
77bd23
+    }
77bd23
+}
77bd23
--
77bd23
2.31.1
77bd23
77bd23
77bd23
From 44d1c9cd047988bb819707c726d9640f8aabe04d Mon Sep 17 00:00:00 2001
77bd23
From: Jeffrey Pinyan <jeffrey.pinyan@ithreat.com>
77bd23
Date: Thu, 13 May 2021 11:51:45 -0400
77bd23
Subject: [PATCH 2/2] streamlined regexes, simplified parse() returns
77bd23
77bd23
Signed-off-by: rpm-build <rpm-build>
77bd23
---
77bd23
 deps/npm/node_modules/path-parse/index.js | 52 ++++++++---------------
77bd23
 1 file changed, 17 insertions(+), 35 deletions(-)
77bd23
77bd23
diff --git a/deps/npm/node_modules/path-parse/index.js b/deps/npm/node_modules/path-parse/index.js
77bd23
index e6b2af1..f062d0a 100644
77bd23
--- a/deps/npm/node_modules/path-parse/index.js
77bd23
+++ b/deps/npm/node_modules/path-parse/index.js
77bd23
@@ -2,29 +2,14 @@
77bd23
77bd23
 var isWindows = process.platform === 'win32';
77bd23
77bd23
-// Regex to split a windows path into three parts: [*, device, slash,
77bd23
-// tail] windows-only
77bd23
-var splitDeviceRe =
77bd23
-    /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?(.*)$/s;
77bd23
-
77bd23
-// Regex to split the tail part of the above into [*, dir, basename, ext]
77bd23
-var splitTailRe =
77bd23
-    /^((?:[^\\\/]*[\\\/])*)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
77bd23
+// Regex to split a windows path into into [dir, root, basename, name, ext]
77bd23
+var splitWindowsRe =
77bd23
+    /^(((?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?[\\\/]?)(?:[^\\\/]*[\\\/])*)((\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))[\\\/]*$/;
77bd23
77bd23
 var win32 = {};
77bd23
77bd23
-// Function to split a filename into [root, dir, basename, ext]
77bd23
 function win32SplitPath(filename) {
77bd23
-  // Separate device+slash from tail
77bd23
-  var result = splitDeviceRe.exec(filename),
77bd23
-      device = (result[1] || '') + (result[2] || ''),
77bd23
-      tail = result[3] || '';
77bd23
-  // Split the tail into dir, basename and extension
77bd23
-  var result2 = splitTailRe.exec(tail),
77bd23
-      dir = result2[1],
77bd23
-      basename = result2[2],
77bd23
-      ext = result2[3];
77bd23
-  return [device, dir, basename, ext];
77bd23
+  return splitWindowsRe.exec(filename).slice(1);
77bd23
 }
77bd23
77bd23
 win32.parse = function(pathString) {
77bd23
@@ -34,24 +19,24 @@ win32.parse = function(pathString) {
77bd23
     );
77bd23
   }
77bd23
   var allParts = win32SplitPath(pathString);
77bd23
-  if (!allParts || allParts.length !== 4) {
77bd23
+  if (!allParts || allParts.length !== 5) {
77bd23
     throw new TypeError("Invalid path '" + pathString + "'");
77bd23
   }
77bd23
   return {
77bd23
-    root: allParts[0],
77bd23
-    dir: allParts[0] + allParts[1].slice(0, -1),
77bd23
+    root: allParts[1],
77bd23
+    dir: allParts[0] === allParts[1] ? allParts[0] : allParts[0].slice(0, -1),
77bd23
     base: allParts[2],
77bd23
-    ext: allParts[3],
77bd23
-    name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
77bd23
+    ext: allParts[4],
77bd23
+    name: allParts[3]
77bd23
   };
77bd23
 };
77bd23
77bd23
77bd23
77bd23
-// Split a filename into [root, dir, basename, ext], unix version
77bd23
+// Split a filename into [dir, root, basename, name, ext], unix version
77bd23
 // 'root' is just a slash, or nothing.
77bd23
 var splitPathRe =
77bd23
-    /^(\/?|)((?:[^\/]*\/)*)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
77bd23
+    /^((\/?)(?:[^\/]*\/)*)((\.{1,2}|[^\/]+?|)(\.[^.\/]*|))[\/]*$/;
77bd23
 var posix = {};
77bd23
77bd23
77bd23
@@ -67,19 +52,16 @@ posix.parse = function(pathString) {
77bd23
     );
77bd23
   }
77bd23
   var allParts = posixSplitPath(pathString);
77bd23
-  if (!allParts || allParts.length !== 4) {
77bd23
+  if (!allParts || allParts.length !== 5) {
77bd23
     throw new TypeError("Invalid path '" + pathString + "'");
77bd23
   }
77bd23
-  allParts[1] = allParts[1] || '';
77bd23
-  allParts[2] = allParts[2] || '';
77bd23
-  allParts[3] = allParts[3] || '';
77bd23
-
77bd23
+
77bd23
   return {
77bd23
-    root: allParts[0],
77bd23
-    dir: allParts[0] + allParts[1].slice(0, -1),
77bd23
+    root: allParts[1],
77bd23
+    dir: allParts[0].slice(0, -1),
77bd23
     base: allParts[2],
77bd23
-    ext: allParts[3],
77bd23
-    name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
77bd23
+    ext: allParts[4],
77bd23
+    name: allParts[3],
77bd23
   };
77bd23
 };
77bd23
77bd23
--
77bd23
2.31.1
77bd23