Skip to content

Prevent mutation of whitelisted array during sorting - #5420

Open
MaddipatlaChetan24 wants to merge 1 commit into
uber:mainfrom
MaddipatlaChetan24:patch-8
Open

MaddipatlaChetan24 wants to merge 1 commit into
uber:mainfrom
MaddipatlaChetan24:patch-8

Conversation

@MaddipatlaChetan24

Copy link
Copy Markdown
Contributor

Ensure whitelisted array is not mutated by sorting directly.

Fixes #1, Fixes #2

Description

getOverrides in overrides.jsx called whitelisted.sort() directly
on the whitelisted prop array. Array.prototype.sort() sorts in
place and returns the same array reference — it does not return a new
sorted copy. Since whitelisted is 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 avoid
recreating 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 getOverrides once with a shared constant
array as whitelisted permanently reorders that constant in place.

Fix: [...whitelisted].sort() — copies the array before sorting, so
the 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 visible
symptom today. Regardless, mutating a prop array is an unsafe pattern
worth fixing on its own merits.)

Scope

Patch: Bug Fix

Ensure whitelisted array is not mutated by sorting directly.
@MaddipatlaChetan24

Copy link
Copy Markdown
Contributor Author

please check this !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant