Prevent mutation of whitelisted array during sorting - #5420
Open
MaddipatlaChetan24 wants to merge 1 commit into
Open
MaddipatlaChetan24 wants to merge 1 commit into
MaddipatlaChetan24 wants to merge 1 commit into
Conversation
Ensure whitelisted array is not mutated by sorting directly.
MaddipatlaChetan24
requested review from
DianaSuvorova,
dyesin,
hualf1995 and
lijim
as code owners
September 17, 2026 01:02
Contributor
Author
|
please check this !!! |
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.
Ensure whitelisted array is not mutated by sorting directly.
Fixes #1, Fixes #2
Description
getOverridesinoverrides.jsxcalledwhitelisted.sort()directlyon the
whitelistedprop array.Array.prototype.sort()sorts inplace and returns the same array reference — it does not return a new
sorted copy. Since
whitelistedis a prop passed in by the caller(potentially a shared/reused array reference, e.g. a module-level
constant reused across multiple
<Overrides>usages to avoidrecreating the array on every render), this silently reordered the
caller's own array as a side effect of simply rendering this component.
Reproduced directly: calling
getOverridesonce with a shared constantarray as
whitelistedpermanently reorders that constant in place.Fix:
[...whitelisted].sort()— copies the array before sorting, sothe caller's array is left untouched while still returning the sorted
result. Verified this produces the same sorted output as before while
leaving the original array reference unmodified.
No other changes. (Note: I don't have visibility into whether any
current call site in this codebase actually reuses a shared array
reference for
whitelisted— I can't confirm this has caused a visiblesymptom today. Regardless, mutating a prop array is an unsafe pattern
worth fixing on its own merits.)
Scope
Patch: Bug Fix