|
| 1 | +From 8007c86f9772612b795ddd2733ec8d8f7c9957b8 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Rohit Rawat <xordux@gmail.com> |
| 3 | +Date: Wed, 25 Sep 2024 17:14:58 +0000 |
| 4 | +Subject: [PATCH] CVE-2024-45590: Set default depth limit to 32 |
| 5 | + |
| 6 | +--- |
| 7 | + .../body-parser/lib/types/urlencoded.js | 37 +++++++++++++++---- |
| 8 | + 1 file changed, 30 insertions(+), 7 deletions(-) |
| 9 | + |
| 10 | +diff --git a/tb_tmp/b069b9e9814ff76ffa6219506d1f1e79/external/npm/_/node_modules/body-parser/lib/types/urlencoded.js b/tb_tmp/b069b9e9814ff76ffa6219506d1f1e79/external/npm/_/node_modules/body-parser/lib/types/urlencoded.js |
| 11 | +index b2ca8f16d..886a3ce23 100644 |
| 12 | +--- a/tb_tmp/b069b9e9814ff76ffa6219506d1f1e79/external/npm/_/node_modules/body-parser/lib/types/urlencoded.js |
| 13 | ++++ b/tb_tmp/b069b9e9814ff76ffa6219506d1f1e79/external/npm/_/node_modules/body-parser/lib/types/urlencoded.js |
| 14 | +@@ -55,6 +55,9 @@ function urlencoded (options) { |
| 15 | + : opts.limit |
| 16 | + var type = opts.type || 'application/x-www-form-urlencoded' |
| 17 | + var verify = opts.verify || false |
| 18 | ++ var depth = typeof opts.depth !== 'number' |
| 19 | ++ ? Number(opts.depth || 32) |
| 20 | ++ : opts.depth |
| 21 | + |
| 22 | + if (verify !== false && typeof verify !== 'function') { |
| 23 | + throw new TypeError('option verify must be function') |
| 24 | +@@ -118,7 +121,8 @@ function urlencoded (options) { |
| 25 | + encoding: charset, |
| 26 | + inflate: inflate, |
| 27 | + limit: limit, |
| 28 | +- verify: verify |
| 29 | ++ verify: verify, |
| 30 | ++ depth: depth |
| 31 | + }) |
| 32 | + } |
| 33 | + } |
| 34 | +@@ -133,12 +137,20 @@ function extendedparser (options) { |
| 35 | + var parameterLimit = options.parameterLimit !== undefined |
| 36 | + ? options.parameterLimit |
| 37 | + : 1000 |
| 38 | ++ |
| 39 | ++ var depth = typeof options.depth !== 'number' |
| 40 | ++ ? Number(options.depth || 32) |
| 41 | ++ : options.depth |
| 42 | + var parse = parser('qs') |
| 43 | + |
| 44 | + if (isNaN(parameterLimit) || parameterLimit < 1) { |
| 45 | + throw new TypeError('option parameterLimit must be a positive number') |
| 46 | + } |
| 47 | + |
| 48 | ++ if(isNaN(depth) || depth < 0) { |
| 49 | ++ throw new TypeError('option depth must be a zero or a positive number') |
| 50 | ++ } |
| 51 | ++ |
| 52 | + if (isFinite(parameterLimit)) { |
| 53 | + parameterLimit = parameterLimit | 0 |
| 54 | + } |
| 55 | +@@ -156,12 +168,23 @@ function extendedparser (options) { |
| 56 | + var arrayLimit = Math.max(100, paramCount) |
| 57 | + |
| 58 | + debug('parse extended urlencoding') |
| 59 | +- return parse(body, { |
| 60 | +- allowPrototypes: true, |
| 61 | +- arrayLimit: arrayLimit, |
| 62 | +- depth: Infinity, |
| 63 | +- parameterLimit: parameterLimit |
| 64 | +- }) |
| 65 | ++ try { |
| 66 | ++ return parse(body, { |
| 67 | ++ allowPrototypes: true, |
| 68 | ++ arrayLimit: arrayLimit, |
| 69 | ++ depth: depth, |
| 70 | ++ strictDepth: true, |
| 71 | ++ parameterLimit: parameterLimit |
| 72 | ++ }) |
| 73 | ++ } catch (err) { |
| 74 | ++ if (err instanceof RangeError) { |
| 75 | ++ throw createError(400, 'The input exceeded the depth', { |
| 76 | ++ type: 'querystring.parse.rangeError' |
| 77 | ++ }) |
| 78 | ++ } else { |
| 79 | ++ throw err |
| 80 | ++ } |
| 81 | ++ } |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | +-- |
| 86 | +2.39.4 |
| 87 | + |
0 commit comments