body-parser
Advanced tools
Comparing version 1.20.2 to 1.20.3
@@ -0,1 +1,8 @@ | ||
1.20.3 / 2024-09-10 | ||
=================== | ||
* deps: qs@6.13.0 | ||
* add `depth` option to customize the depth level in the parser | ||
* IMPORTANT: The default `depth` level for parsing URL-encoded data is now `32` (previously was `Infinity`) | ||
1.20.2 / 2023-02-21 | ||
@@ -2,0 +9,0 @@ =================== |
@@ -58,2 +58,5 @@ /*! | ||
var verify = opts.verify || false | ||
var depth = typeof opts.depth !== 'number' | ||
? Number(opts.depth || 32) | ||
: opts.depth | ||
@@ -122,3 +125,4 @@ if (verify !== false && typeof verify !== 'function') { | ||
limit: limit, | ||
verify: verify | ||
verify: verify, | ||
depth: depth | ||
}) | ||
@@ -138,2 +142,6 @@ } | ||
: 1000 | ||
var depth = typeof options.depth !== 'number' | ||
? Number(options.depth || 32) | ||
: options.depth | ||
var parse = parser('qs') | ||
@@ -145,2 +153,6 @@ | ||
if (isNaN(depth) || depth < 0) { | ||
throw new TypeError('option depth must be a zero or a positive number') | ||
} | ||
if (isFinite(parameterLimit)) { | ||
@@ -163,8 +175,19 @@ parameterLimit = parameterLimit | 0 | ||
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 | ||
} | ||
} | ||
} | ||
@@ -171,0 +194,0 @@ } |
{ | ||
"name": "body-parser", | ||
"description": "Node.js body parsing middleware", | ||
"version": "1.20.2", | ||
"version": "1.20.3", | ||
"contributors": [ | ||
@@ -20,3 +20,3 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"on-finished": "2.4.1", | ||
"qs": "6.11.0", | ||
"qs": "6.13.0", | ||
"raw-body": "2.5.2", | ||
@@ -23,0 +23,0 @@ "type-is": "~1.6.18", |
@@ -7,2 +7,3 @@ # body-parser | ||
[![Test Coverage][coveralls-image]][coveralls-url] | ||
[![OpenSSF Scorecard Badge][ossf-scorecard-badge]][ossf-scorecard-visualizer] | ||
@@ -281,2 +282,6 @@ Node.js body parsing middleware. | ||
#### depth | ||
The `depth` option is used to configure the maximum depth of the `qs` library when `extended` is `true`. This allows you to limit the amount of keys that are parsed and can be useful to prevent certain types of abuse. Defaults to `32`. It is recommended to keep this value as low as possible. | ||
## Errors | ||
@@ -378,2 +383,6 @@ | ||
### The input exceeded the depth | ||
This error occurs when using `bodyParser.urlencoded` with the `extended` property set to `true` and the input exceeds the configured `depth` option. The `status` property is set to `400`. It is recommended to review the `depth` option and evaluate if it requires a higher value. When the `depth` option is set to `32` (default value), the error will not be thrown. | ||
## Examples | ||
@@ -469,1 +478,3 @@ | ||
[npm-version-image]: https://badgen.net/npm/v/body-parser | ||
[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/expressjs/body-parser/badge | ||
[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/body-parser |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62624
947
476
4