Skip to content

Make a "__proto__" key an own property in valueFromDynamic - #60241

Open
lavenzg wants to merge 1 commit into
react:mainfrom
lavenzg:export-D132359056
Open

lavenzg wants to merge 1 commit into
react:mainfrom
lavenzg:export-D132359056

Conversation

@lavenzg

@lavenzg lavenzg commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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

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
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 23, 2026
@meta-codesync

meta-codesync Bot commented Nov 23, 2026

Copy link
Copy Markdown

@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

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant