Skip to content

feat: add an opt-in fieldArrayIndexLimit - #1438

Merged
UlisesGascon merged 5 commits into
expressjs:mainfrom
arpitjain099:feat/field-array-index-limit
Aug 28, 2026
Merged

UlisesGascon merged 5 commits into
expressjs:mainfrom
arpitjain099:feat/field-array-index-limit

Conversation

@arpitjain099

@arpitjain099 arpitjain099 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Adds an opt-in limits.fieldArrayIndexLimit that bounds the numeric index allowed inside a bracket field name, complementing the existing fieldNestingDepth limit.

fieldNestingDepth counts bracket groups, not the number inside them, so a[1000000] is one level and passes. append-field reads an all-digit bracket group as an array index, and the resulting array carries that length. Applications that want to bound this can now opt in.

The change

A new limits.fieldArrayIndexLimit checked next to the existing fieldNestingDepth check, plus a LIMIT_FIELD_ARRAY_INDEX error code. Only bracket groups that are entirely digits count, so a[99999999x] stays an object key and is untouched. It is opt-in and defaults to unbounded, so with the limit unset behavior is unchanged (there is a test asserting that).

Tests

test/array-index-limit.js covers rejection above the limit, rejection nested behind object keys, acceptance exactly at the limit, a numeric key bounded at a limit of zero, object keys left alone, field names stored as literal keys, and unbounded when unset.

Notes

The name fieldArrayIndexLimit follows multer's field* convention. Whether a future major enforces a default, and what value, is a separate call.

append-field turns a bracket group whose contents are all digits into an
array index, so a[3] produces an array of length 4. The index is not
bounded by fieldNestingDepth, which counts bracket groups rather than
what is inside them, so a single field name such as a[4294967294] can
materialize a sparse array with a multi-billion length.

Creating it costs append-field almost nothing. The cost lands on the
application when it later iterates or serializes req.body, which is why
this is a missing knob rather than resource consumption inside multer.
Until now there was no limit to opt into.

This adds one, in the spirit of the arrayLimit option in qs. It defaults
to unbounded, so existing behaviour is unchanged and the change is
semver-safe on the 2.x line. Only bracket groups that are entirely
digits are considered, so object keys are unaffected.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Comment thread lib/make-middleware.js Fixed

@UlisesGascon UlisesGascon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @arpitjain099! I added some minor changes that I had locally for this 👍

@UlisesGascon
UlisesGascon merged commit 73c1759 into expressjs:main Aug 28, 2026
28 of 40 checks passed
YasharF added a commit to sahat/hackathon-starter that referenced this pull request Aug 28, 2026
config/morgan.js: colors moved out of the token and into the format string, where morgan doesn't touch them

Dependency Release Notes:

Multer v2.3.0
- Fix [CVE-2026-77078](https://www.cve.org/CVERecord?id=CVE-2026-77078) ([GHSA-wc9g-mqfw-jrwm](GHSA-wc9g-mqfw-jrwm))
- Fix [CVE-2026-77037](https://www.cve.org/CVERecord?id=CVE-2026-77037) ([GHSA-qfvm-cv95-jqjf](GHSA-qfvm-cv95-jqjf))
- Fix [CVE-2026-77063](https://www.cve.org/CVERecord?id=CVE-2026-77063) ([GHSA-qvfw-j98x-7q72](GHSA-qvfw-j98x-7q72))
- Fix [CVE-2026-82333](https://www.cve.org/CVERecord?id=CVE-2026-82333) ([GHSA-535w-7cp7-47q4](GHSA-535w-7cp7-47q4))
- Add `MulterError` codes `INVALID_FIELD_NAME` and `STREAM_DESTROYED`
- Add opt-in `limits.fieldArrayIndexLimit` to bound numeric array indexes in field names ([#1438](expressjs/multer#1438))
- Accept files whose size is exactly `limits.fileSize` ([#1407](expressjs/multer#1407))
- Preserve the caller's async context (`AsyncLocalStorage`) when calling `next()` ([#1124](expressjs/multer#1124))
- Decode WHATWG-escaped characters (`%0A`, `%0D`, `%22`) in `file.originalname` ([#1421](expressjs/multer#1421))
- Do not crash when `fileFilter` invokes its callback more than once ([#1427](expressjs/multer#1427))
- Use a fallback message for `MulterError` codes without a mapping ([#1448](expressjs/multer#1448))
- Docs: clarify `preservePath` and `parts`, use `crypto.randomBytes` in the `DiskStorage` example ([#1414](expressjs/multer#1414), [#1430](expressjs/multer#1430), [#1436](expressjs/multer#1436))
- Docs: add Indonesian, Japanese and Tamil translations and refresh all translations from the current README ([#1431](expressjs/multer#1431), [#1354](expressjs/multer#1354), [#1462](expressjs/multer#1462))
- Internal: run the test suite on Windows ([#1334](expressjs/multer#1334))

Morgan 1.12.0
- Security fix for [CVE-2026-15603](https://www.cve.org/CVERecord?id=CVE-2026-15603)([GHSA-jxfw-x594-9x9m](https://github.com/expressjs/morgan/security/advisories/GHSA-jxfw-x594-9x9m))
- Allow format functions to return objects for streams in `objectMode`
- Respect the `NO_COLOR` environment variable in the `dev` format
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.

3 participants