Repository navigation
fix(urlencoded): prevent 32-bit integer overflow in parameterLimit - #785
Open
helmipradita wants to merge 1 commit into
Open
helmipradita wants to merge 1 commit into
helmipradita wants to merge 1 commit into
Conversation
Using bitwise `parameterLimit | 0` truncated the limit to a 32-bit signed integer (ToInt32). When `parameterLimit` was set to a value >= 2^31 (e.g. 3000000000), it wrapped to a negative number, causing `parameterCount` to immediately treat any request as exceeding the limit and return 413. Use `Math.trunc(parameterLimit)` to truncate floating-point numbers without overflowing large integers within JavaScript safe integer range.
Contributor
|
Setting |
Author
|
Agreed @krzysdz! The primary goal of this PR is to prevent the 32-bit integer overflow where setting |
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.
Problem
In
lib/types/urlencoded.js,parameterLimitwas coerced to an integer using bitwise OR:Because bitwise operators in JavaScript convert operands to 32-bit signed integers ($2^{31}$ (such as
ToInt32), configuringparameterLimitto a value greater than or equal to3000000000) caused it to overflow into a negative integer (-1294967296).When parsing any incoming URL-encoded payload (even a valid single-parameter request like
user=tobi),parameterCountcheckedcount > limit(1 > -1294967296), immediately returningundefinedand rejecting legitimate requests with HTTP 413too many parameters.Solution
Replace
parameterLimit | 0withMath.trunc(parameterLimit). This preserves floating-point truncation (e.g.10.5becomes10) while correctly handling numbers up toNumber.MAX_SAFE_INTEGERwithout 32-bit overflow.Validation
extended: falseandextended: trueintest/urlencoded.jsasserting thatparameterLimit: 3000000000succeeds for incoming payloads.npm test.npm run lint.