Skip to content

feat!: enforce default fieldArrayIndexLimit of 1000 - #1477

Open
official-burak wants to merge 2 commits into
expressjs:v3from
official-burak:feat/v3-default-field-array-index-limit
Open

official-burak wants to merge 2 commits into
expressjs:v3from
official-burak:feat/v3-default-field-array-index-limit

Conversation

@official-burak

@official-burak official-burak commented Sep 2, 2026 •

Copy link
Copy Markdown

Ulises asked for this on v3 in #1461, matching the fieldNestingDepth default in #1433. A name like items[1000000] currently builds a huge sparse array even when only one value is sent, so this ports the index check from #1438 and defaults it to 1000.

items[1000] still works, items[1001] is rejected with LIMIT_FIELD_ARRAY_INDEX, and you can raise the limit if you need larger indices. Literal keys such as items[1000]tail are left alone.

@kilisamemarisaaa kilisamemarisaaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found a false positive in exceedsArrayIndexLimit for a fallback key containing a nested [.

append-field@2.0.0 parses items[[1001] as a literal object key (the bracket group is [1001), not an array path: its numeric step matcher requires [ to be followed immediately by digits. However, this PR's global /\\[(\\d+)\\]/g scan finds the inner [1001] and rejects the field with the default limit:

items[[1001] rejected LIMIT_FIELD_ARRAY_INDEX items[[1001]
items[1001]tail accepted {"items[1001]tail":"value"}

I reproduced this on d6d25b4b in multer-pr1477; the existing 71-test suite and lint still pass. This contradicts the stated “literal fallback keys … left alone” behavior and breaks a previously accepted field name under the new default. Please add a regression test and make the scan follow append-field's actual path grammar (so digits inside an object-key bracket are not treated as an array step).

A bracket group is an array index only when it holds nothing but digits, and a name that does not parse completely stays a literal key. Digits inside an object-key group such as the [1001 key in items[[1001] are therefore no longer counted as an array step.
@official-burak

official-burak commented Oct 20, 2026 •

Copy link
Copy Markdown
Author

Good catch, thanks for the detailed report and the reproduction.

The check now walks the name using the same grammar append-field does: a bracket group only counts as an array index when it holds nothing but digits, and a name that does not parse completely stays a literal key. So items[[1001] is accepted and stored under items['[1001'], and items[1001]tail keeps the literal key behavior.

Both cases are covered as regression tests in ae4f9ff.

@yxshee yxshee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I checked out ae4f9ff on top of v3 and ran it on Node 22.

  • The new file has 10 tests and all pass. On v3 without the lib and index.js changes, 2 of them fail ("reject an index above the default limit" and "oversized index nested behind object keys", both Missing expected rejection). The other 8 pass there too, which is expected since they only check names that should be accepted.
  • The full suite gives 68 passing, 5 failing. The same 5 fail on plain v3 on my machine (aborted requests x2, Express integration, orphan cleanup x2), and v3's own CI has been red since August, so they aren't from this PR. standard is clean.
  • I compared exceedsArrayIndexLimit with what append-field 2.0.0 actually builds. I generated 300,000 random names from a, [, ], [], [6], [[, ]], digits and so on, called appendField on each one, and checked whether the result contained an array longer than limit + 1. With limit 5, the function agreed with append-field on every name. So the grammar walk in the second commit does match the parser, including items[[1001] and a[6]suffix.

One thing to decide before merge: fieldArrayIndexLimit goes through parseLimit, so { fieldArrayIndexLimit: Infinity } now throws Invalid limit "fieldArrayIndexLimit" given: Infinity. On 2.x, Infinity is the documented default. Someone who set it explicitly to keep large indices will get a constructor error after upgrading, and fieldNestingDepth on v3 still accepts Infinity. If that's intended (the other parseLimit limits behave the same way), a line in the migration notes saying to use Number.MAX_SAFE_INTEGER would help. parseLimit also passes the value through bytes, so '1KB' is taken as 1024. That's harmless, just a bit odd for an index.

Related, but outside this PR: the 2.x check from #1438 on main still has the false positive this PR fixes. With fieldArrayIndexLimit: 1000, multer 2.5.0 rejects items[[1001] even though append-field 1.0.0 stores it as the object key '[1001'. The walk here could be backported.

The change looks correct to me as written.

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.

4 participants