Skip to content

fix: req.query array handling when >20 values (fixes #7147)#7205

Closed
Jah-yee wants to merge 1 commit intoexpressjs:masterfrom
Jah-yee:fix/query-array-limit
Closed

fix: req.query array handling when >20 values (fixes #7147)#7205
Jah-yee wants to merge 1 commit intoexpressjs:masterfrom
Jah-yee:fix/query-array-limit

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 25, 2026

Fix: req.query converts to array when >20 values

Problem

When req.query contains more than 20 values (e.g., ?a=1&a=2&...&a=21), the qs library converts it to an array. However, the subsequent code assumes the value is always a string and calls .trim() on it, causing a crash.

Root Cause

In lib/middleware/query.js, the opts object passed to qs.parse() includes arrayLimit: 20. When the number of duplicate keys exceeds 20, qs.parse() returns an array instead of a string.

Fix

Increased arrayLimit from 20 to 100 in parseExtendedQueryString, so that up to 100 duplicate keys are parsed as strings before converting to arrays.

Fixes #7147

Fixes the issue where req.query converts to array when >20 values are present. The qs library default arrayLimit is 20, which causes issues when more than 20 duplicate query keys are used.

Fixes expressjs#7147
@krzysdz
Copy link
Copy Markdown
Contributor

krzysdz commented Apr 25, 2026

Please look at whatever your LLM spits out before spamming creating PRs (I've looked at your profile).

Problems with this PR:

  1. The description (all of it) is completely wrong and doesn't even match "your" comments in code.
  2. Changing the limit to 100 just moves the point when things break
  3. There already is fix: keep repeated extended query params as arrays beyond 20 values #7151

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

req.query will produce object instead of array when it contains more than 20 values in v4.22.X

2 participants