Repository navigation
Conversation
Summary: `jsi::valueFromDynamic` fills each new object with `setProperty`, which acts like JS assignment and consults the prototype chain, while `JSON.parse` defines own data properties. So a `"__proto__"` key in native data, such as server JSON parsed with folly and passed to JS by React Native, calls the `__proto__` setter on `Object.prototype` instead of becoming an own property: an object or null value replaces the converted object's prototype, and any other value is dropped. Fix, without a JSI API change: an object whose `folly::dynamic` has a `"__proto__"` key is filled while its prototype is null, then gets its prototype back. With no prototype chain, the store defines an own data property. Other objects, and arrays, are converted as before, so they keep their hidden classes; the added cost is one key lookup per object. Assignment also differs from `JSON.parse` when `Object.prototype` or `Array.prototype` has an accessor or a read-only property. That needs a modified prototype, which should be prevented where the prototype is modified, so those cases are left alone. For the same reason, `jsi::Array::createWithElements` is unchanged. On JSC this is incomplete: JSCRuntime cuts property names at the first NUL, so a key such as `"__proto__\0x"` becomes `"__proto__"` without matching the lookup, and can still call the setter. A code comment records this existing JSCRuntime limitation. Changelog: [General][Fixed] - Fix "__proto__" handling in JSI `valueFromDynamic` Differential Revision: D132359056
|
@lavenzg has exported this pull request. If you are a Meta employee, you can view the originating Diff in D132359056. |
This branch has not been deployed
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:
jsi::valueFromDynamicfills each new object withsetProperty, whichacts like JS assignment and consults the prototype chain, while
JSON.parsedefines own data properties. So a"__proto__"key innative data, such as server JSON parsed with folly and passed to JS by
React Native, calls the
__proto__setter onObject.prototypeinstead of becoming an own property: an object or null value replaces
the converted object's prototype, and any other value is dropped.
Fix, without a JSI API change: an object whose
folly::dynamichas a"__proto__"key is filled while its prototype is null, then gets itsprototype back. With no prototype chain, the store defines an own data
property. Other objects, and arrays, are converted as before, so they
keep their hidden classes; the added cost is one key lookup per object.
Assignment also differs from
JSON.parsewhenObject.prototypeorArray.prototypehas an accessor or a read-only property. That needs amodified prototype, which should be prevented where the prototype is
modified, so those cases are left alone. For the same reason,
jsi::Array::createWithElementsis unchanged.On JSC this is incomplete: JSCRuntime cuts property names at the first
NUL, so a key such as
"__proto__\0x"becomes"__proto__"withoutmatching the lookup, and can still call the setter. A code comment
records this existing JSCRuntime limitation.
Changelog:
[General][Fixed] - Fix "proto" handling in JSI
valueFromDynamicDifferential Revision: D132359056