Repository navigation
fix: Handle flag keys that are names of built-in object members - #2170
Merged
Merged
Conversation
Contributor
|
@launchdarkly/js-sdk-common size report |
Contributor
|
@launchdarkly/js-client-sdk size report |
Contributor
|
@launchdarkly/js-client-sdk-common size report |
kinyoklion
force-pushed
the
rlamb/prototype-named-flag-keys
branch
from
November 4, 2026 23:18
551861e to
e33ad89
Compare
- The event summarizer threw when it summarized an evaluation of a flag whose key is a built-in object member, such as constructor, toString or __proto__. It now uses maps, and builds the summary on a null-prototype object. - The all-flags state dropped a flag named __proto__ from allValues() and toJSON(), and getFlagValue() could return an inherited property for a key that is not in the state. The state still serializes to plain objects. - The in-memory store dropped a flag named __proto__ from all() and when it applied an update, and the FDv2 payload conversion dropped it unless it was the first item of its kind. Both now use null-prototype objects. Generated-by: termag
kinyoklion
force-pushed
the
rlamb/prototype-named-flag-keys
branch
from
November 4, 2026 23:23
e33ad89 to
4f67776
Compare
kinyoklion
marked this pull request as ready for review
November 4, 2026 23:51
joker23
approved these changes
Nov 5, 2026
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.
Summary
Flag keys such as
constructor,toStringor__proto__are ordinary keys, but some code kept them in plain objects:variation()failed for that flag in the server and client SDKs. It now uses maps, and builds the summary on a null-prototype object so that a flag named__proto__stays in the summary.allFlagsState()dropped a flag named__proto__fromallValues()andtoJSON(), andgetFlagValue()could return an inherited property for a key that is not in the state. The state still serializes to plain objects, which React server components require.__proto__fromall()and when it applied an update, and the FDv2 payload conversion dropped it unless it was the first item of its kind, so the flag was not found. Both now use null-prototype objects, as the override layer already does. The in-memory store'sall()result now has no prototype, like the override layer's.New unit tests cover each case. The node-server contract tests pass new server-side evaluation tests for these keys with FDv1 and FDv2.
Opened from termag
Note
Overview
Fixes incorrect handling when feature flag keys are JavaScript built-in names such as
__proto__,constructor, ortoString. Assigning those keys on normal objects can mutate the prototype or hide entries, which broke summarization, bootstrap state, the in-memory store, and FDv2 payload conversion.Event summarization now keeps counters in
Mapinstances and builds the summaryfeaturesobject withObject.create(null), so every flag key is summarized and survivesJSON.stringify.FlagsStateBuilderstores values and metadata viaObject.defineProperty, useshasOwnPropertyfor lookups, and still emits plain objects fromtoJSON()for frameworks like React server components.In-memory feature store and FDv2 payload listener use null-prototype maps when listing, snapshotting, merging, and converting updates so flags like
__proto__are retained even when they are not the first item in a batch.New unit tests cover these paths across
EventSummarizer,FlagsStateBuilder,InMemoryFeatureStore, andcreatePayloadListenerFDv2.Reviewed by Cursor Bugbot for commit b67ad28. Bugbot is set up for automated code reviews on this repo. Configure here.