Skip to content

Commit

Permalink
fix(ses): set fn instance prototype to undefined on Hermes
Browse files Browse the repository at this point in the history
  • Loading branch information
leotm committed Oct 28, 2024
1 parent 1d4bd35 commit 048efd3
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions packages/ses/src/intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,40 @@ export const makeIntrinsicsCollector = () => {
if (typeof permit !== 'object') {
throw TypeError(`Expected permit object at whitelist.${name}`);
}
const namePrototype = permit.prototype;
if (!namePrototype) {
const permitPrototype = permit.prototype;

if (
typeof intrinsic === 'function' &&
intrinsic.prototype !== undefined &&
permitPrototype === 'undefined' // permits.js
) {
// Set non-standard `.prototype` properties to `undefined` on Hermes.
// These include intrinsics that are additional properties of the global object,
// proposed by SES defined as function instances
// - arrow functions: lockdown, harden
// - concise methods: %InitialGetStackString%
intrinsic.prototype = undefined;
}

const intrinsicPrototype = intrinsic.prototype;

if (!permitPrototype) {
throw TypeError(`${name}.prototype property not whitelisted`);
}
if (
typeof namePrototype !== 'string' ||
!objectHasOwnProperty(permitted, namePrototype)
typeof permitPrototype !== 'string' ||
!objectHasOwnProperty(permitted, permitPrototype)
) {
throw TypeError(`Unrecognized ${name}.prototype whitelist entry`);
}
const intrinsicPrototype = intrinsic.prototype;
if (objectHasOwnProperty(intrinsics, namePrototype)) {
if (intrinsics[namePrototype] !== intrinsicPrototype) {
throw TypeError(`Conflicting bindings of ${namePrototype}`);
if (objectHasOwnProperty(intrinsics, permitPrototype)) {
if (intrinsics[permitPrototype] !== intrinsicPrototype) {
throw TypeError(`Conflicting bindings of ${permitPrototype}`);
}
// eslint-disable-next-line no-continue
continue;
}
intrinsics[namePrototype] = intrinsicPrototype;
intrinsics[permitPrototype] = intrinsicPrototype;
}
};
freeze(completePrototypes);
Expand Down

0 comments on commit 048efd3

Please sign in to comment.