Skip to content

Remove $FlowFixMe from __proto__ JSON test - #2203

Merged
robhogan merged 1 commit into
mainfrom
vzaidman/fix-json-proto-test-flowfixme-main
Nov 9, 2026
Merged

robhogan merged 1 commit into
mainfrom
vzaidman/fix-json-proto-test-flowfixme-main

Conversation

@vzaidman

@vzaidman vzaidman commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2199. The __proto__ JSON test annotated the evaluated module value as $FlowFixMe with no justification. This replaces the suppression with a runtime refinement of unknown: throw unless the export is a non-null object.

The prototype-pollution check is expect('x' in value).toBe(false) instead of reading the untyped value.x. in also sees inherited properties, so it catches a polluted prototype, and unlike a getPrototypeOf identity comparison it works across the Jest vm realm boundary (the evaluated value is created in another realm, so its prototype is not identical to the test file's Object.prototype). A value as {[key: string]: unknown} cast is not an option: Flow rejects casting unknown to the indexer type.

The Object.keys assertion is unchanged.

Test plan

yarn jest packages/metro/src/ModuleGraph/worker/__tests__/JsFileWrapping-test.js
Tests: 13 passed, 13 total

yarn flow check
No errors!

ESLint and Prettier on the changed file are clean. I also verified the new assertion fails if jsonToCommonJS goes back to emitting the object literal.

Replace the `$FlowFixMe` annotation on the evaluated JSON module value
with a runtime refinement of `unknown`: throw unless the export is a
non-null object. Check for prototype pollution with `'x' in value`
instead of reading the untyped `value.x`: `in` also sees inherited
properties, so it catches a polluted prototype, and unlike a
`getPrototypeOf` identity comparison it works across the Jest vm realm
boundary. The `Object.keys` assertion is unchanged.
@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 9, 2026
@vzaidman
vzaidman requested review from huntie and robhogan November 9, 2026 15:32

const value: $FlowFixMe = evaluateJsonModule(sources[0]);
const value = evaluateJsonModule(sources[0]);
if (typeof value !== 'object' || value === null) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this warning is expected

@robhogan
robhogan merged commit f52801f into main Nov 9, 2026
16 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants