feat(rest): make qs arrayLimit configurable for query parameter parsing#11640
Open
KauanAfonso wants to merge 1 commit into
Open
feat(rest): make qs arrayLimit configurable for query parameter parsing#11640KauanAfonso wants to merge 1 commit into
KauanAfonso wants to merge 1 commit into
Conversation
Signed-off-by: kauanAfonso <kauan.afonso@ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Add configurable arrayLimit for query parameter parsing
Fixes #11396
Summary
This PR makes the
qsarrayLimit for query parameter parsing configurable in LoopBack. Previously, query parameters with more than 20 array items were converted to objects with numeric keys, causing validation errors in LoopBack endpoints.Problem
After the
qsupgrade in commit 1eedfd5 (to address GHSA-6rw7-vpxm-498p), the defaultarrayLimitof 20 caused issues for APIs that need to handle more than 20 items in query parameter arrays. When this limit is exceeded,qsconverts the array to an object to prevent DoS attacks with extremely large indices.Example of the issue:
Solution
Added a new
queryParserconfiguration option toRestServerOptionsthat allows applications to customize thearrayLimit:Changes Made
Added
queryParserconfiguration (packages/rest/src/rest.server.ts)queryParserproperty inRestServerResolvedOptionsarrayLimitoption with inline documentationConfigured Express query parser (
packages/rest/src/rest.server.ts)_applyExpressSettings()to set custom query parserqs.parse()with configurablearrayLimitallowPrototypes: false,depth: 20Added comprehensive tests (
packages/rest/src/__tests__/acceptance/request-parsing/array-limit.acceptance.ts)Usage Example
With the new configuration:
Breaking Changes
None. The default
arrayLimitremains 20, maintaining backward compatibility.Checklist
npm testpasses on your machinepackages/cliwere updated (N/A)examples/*were updated (N/A)Notes
Related Links