Skip to content

Fix structuredClone WeakMap/WeakSet/Promise prototype mutations for H… - #60003

Open
leotm wants to merge 2 commits into
react:mainfrom
leotm:fix/structuredclone-prototype-mutation
Open

leotm wants to merge 2 commits into
react:mainfrom
leotm:fix/structuredclone-prototype-mutation

Conversation

@leotm

@leotm leotm commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fix: #60002

This is the minimal fix, if preferred here or followup, can be refactored to preserve original style e.g.

const NON_SERIALIZABLE_PROTOTYPES: Array<interface {}> = [];

function isNonSerializableObject<T extends interface {}>(obj: T): boolean {
  let proto = Object.getPrototypeOf(obj);
  while (proto != null) {
    if (NON_SERIALIZABLE_PROTOTYPES.includes(proto)) return true;
    proto = Object.getPrototypeOf(proto);
  }
  return false;
}

function markClassAsNonSerializable<T>(cls: Class<T>): void {
  NON_SERIALIZABLE_PROTOTYPES.push(cls.prototype);
}

// Non-serializable built-ins.
markClassAsNonSerializable(WeakMap);
markClassAsNonSerializable(WeakSet);
markClassAsNonSerializable(Promise);

then naturally storing the Array instead as a Set or better WeakSet

Changelog:

[INTERNAL] [SECURITY] - Fix structuredClone WeakMap/WeakSet/Promise prototype mutations

Test Plan:

Added unit tests for WeakMap, WeakSet and Promise

@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 13, 2026

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WebAPIs] structuredClone: WeakMap/WeakSet/Promise prototype mutations break initial render under Hardened JS (SES)

1 participant