-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
From 58b0b02d2501825235a1c1c2598171513621df45 Mon Sep 17 00:00:00 2001 | ||
From: Rohit Rawat <[email protected]> | ||
Date: Wed, 25 Sep 2024 12:35:30 +0000 | ||
Subject: [PATCH] CVE-2024-45590: Set default depth limit to 32 | ||
|
||
--- | ||
.../body-parser/lib/types/urlencoded.js | 37 +++++++++++++++---- | ||
1 file changed, 30 insertions(+), 7 deletions(-) | ||
|
||
diff --git a/src/ui/node_modules/body-parser/lib/types/urlencoded.js b/src/ui/node_modules/body-parser/lib/types/urlencoded.js | ||
index b2ca8f16..886a3ce2 100644 | ||
--- a/src/ui/node_modules/body-parser/lib/types/urlencoded.js | ||
+++ b/src/ui/node_modules/body-parser/lib/types/urlencoded.js | ||
@@ -55,6 +55,9 @@ function urlencoded (options) { | ||
: opts.limit | ||
var type = opts.type || 'application/x-www-form-urlencoded' | ||
var verify = opts.verify || false | ||
+ var depth = typeof opts.depth !== 'number' | ||
+ ? Number(opts.depth || 32) | ||
+ : opts.depth | ||
|
||
if (verify !== false && typeof verify !== 'function') { | ||
throw new TypeError('option verify must be function') | ||
@@ -118,7 +121,8 @@ function urlencoded (options) { | ||
encoding: charset, | ||
inflate: inflate, | ||
limit: limit, | ||
- verify: verify | ||
+ verify: verify, | ||
+ depth: depth | ||
}) | ||
} | ||
} | ||
@@ -133,12 +137,20 @@ function extendedparser (options) { | ||
var parameterLimit = options.parameterLimit !== undefined | ||
? options.parameterLimit | ||
: 1000 | ||
+ | ||
+ var depth = typeof options.depth !== 'number' | ||
+ ? Number(options.depth || 32) | ||
+ : options.depth | ||
var parse = parser('qs') | ||
|
||
if (isNaN(parameterLimit) || parameterLimit < 1) { | ||
throw new TypeError('option parameterLimit must be a positive number') | ||
} | ||
|
||
+ if(isNaN(depth) || depth < 0) { | ||
+ throw new TypeError('option depth must be a zero or a positive number') | ||
+ } | ||
+ | ||
if (isFinite(parameterLimit)) { | ||
parameterLimit = parameterLimit | 0 | ||
} | ||
@@ -156,12 +168,23 @@ function extendedparser (options) { | ||
var arrayLimit = Math.max(100, paramCount) | ||
|
||
debug('parse extended urlencoding') | ||
- return parse(body, { | ||
- allowPrototypes: true, | ||
- arrayLimit: arrayLimit, | ||
- depth: Infinity, | ||
- parameterLimit: parameterLimit | ||
- }) | ||
+ try { | ||
+ return parse(body, { | ||
+ allowPrototypes: true, | ||
+ arrayLimit: arrayLimit, | ||
+ depth: depth, | ||
+ strictDepth: true, | ||
+ parameterLimit: parameterLimit | ||
+ }) | ||
+ } catch (err) { | ||
+ if (err instanceof RangeError) { | ||
+ throw createError(400, 'The input exceeded the depth', { | ||
+ type: 'querystring.parse.rangeError' | ||
+ }) | ||
+ } else { | ||
+ throw err | ||
+ } | ||
+ } | ||
} | ||
} | ||
|
||
-- | ||
2.39.4 | ||
|