fix: use safe hasOwnProperty when parsing query params#69259
Open
rootvector2 wants to merge 1 commit into
Open
fix: use safe hasOwnProperty when parsing query params#69259rootvector2 wants to merge 1 commit into
rootvector2 wants to merge 1 commit into
Conversation
JeanMeche
reviewed
Jun 9, 2026
| const decodedVal = decodeQuery(value); | ||
|
|
||
| if (params.hasOwnProperty(decodedKey)) { | ||
| if (Object.prototype.hasOwnProperty.call(params, decodedKey)) { |
Contributor
Author
There was a problem hiding this comment.
good call, switched both call sites to Object.hasOwn.
`parseQueryParam` and the AngularJS-compat `parseKeyValue` accumulate query params into a plain object and check key presence with `obj.hasOwnProperty`, so a `hasOwnProperty` query key clobbers the method and the next lookup throws `TypeError`. Switch both to `Object.hasOwn`, which can't be shadowed by a query key.
baae253 to
04004ab
Compare
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.
PR Checklist
PR Type
What is the current behavior?
Issue Number: N/A
parseQueryParamin the router andparseKeyValuein@angular/common/upgradecheck for an existing key by callinghasOwnPropertydirectly on the object they accumulate parsed query params into, whose keys come straight from the URL. A query string like?hasOwnProperty=x&a=boverwrites that method with a string, so the existence check for the next param throwsTypeError: params.hasOwnProperty is not a functionand the whole parse fails on otherwise valid input reachable from any crafted link.What is the new behavior?
Both call sites use the non-clobberable
Object.prototype.hasOwnProperty.call(...), whichrouter/src/shared.tsalready uses for param lookups, so ahasOwnPropertyquery key parses like any other key and the repeated-key array handling is unchanged. Spotted while auditing the query-string parsers for the unsafeobj.hasOwnProperty(userKey)shape.Does this PR introduce a breaking change?
Other information