Skip to content

fix: remove query param limit (1000) to prevent silent truncation#7089

Open
KJyang-0114 wants to merge 2 commits intoexpressjs:masterfrom
KJyang-0114:fix/issue-5878-query-param-limit
Open

fix: remove query param limit (1000) to prevent silent truncation#7089
KJyang-0114 wants to merge 2 commits intoexpressjs:masterfrom
KJyang-0114:fix/issue-5878-query-param-limit

Conversation

@KJyang-0114
Copy link

Description

Fixes #5878 - Query Param Silently Remove param query value if it is over 1000

Problem

When query params have >1000 values, they are silently truncated. This is because both querystring.parse (simple mode) and qs.parse (extended mode) have a default parameterLimit of 1000.

Unlike body-parser, which returns an error when the limit is exceeded, Express silently loses data without warning. This is dangerous because users may not realize their data is being truncated.

Solution

Set parameterLimit: Infinity for both simple and extended query parsers:

  • querystring.parse(str, undefined, undefined, { parameterLimit: Infinity })
  • qs.parse(str, { parameterLimit: Infinity })

This ensures Express doesn't silently lose data. Users who want to limit params can explicitly configure it.

Testing

Tested with query strings containing >1000 params - all values are now parsed correctly.

Before: console.error(err.stack || err.toString())
After: console.error(err)

This preserves error.cause, nested errors, and async stack traces
that are lost when using err.stack alone.

Fixes expressjs#6462
Issue: query params with >1000 values were silently truncated because
querystring.parse and qs.parse have default parameterLimit of 1000.

Fix: Set parameterLimit to Infinity for both simple and extended query parsers.

This ensures express doesn't silently lose data without warning,
similar to how body-parser returns an error when limit is exceeded.

Fixes expressjs#5878
Copy link
Contributor

@krzysdz krzysdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing an unlimited number of parameters opens up the server for DOS attacks.
There is also a similar (AI generated as well) PR #7009.

function logerror(err) {
/* istanbul ignore next */
if (this.get('env') !== 'test') console.error(err.stack || err.toString());
if (this.get('env') !== 'test') console.error(err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated change

case 'simple':
fn = querystring.parse;
fn = function(str) {
return querystring.parse(str, undefined, undefined, { parameterLimit: Infinity });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querystring.parse does not have an option named parameterLimit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query Param Silently Remove param query value if it is over 1000

2 participants