isolated-vm icon indicating copy to clipboard operation
isolated-vm copied to clipboard

`reference.set` fails if the property already exists

Open issuefiler opened this issue 3 years ago • 2 comments

await execution_context.eval("var window = {};"); // Created “globalThis.window” from inside
await execution_context.global.set("window", 1); // Setting it fails, not overwriting.

https://github.com/laverdet/isolated-vm/blob/22ed400de4cd65cbe537614af59228b3fc416f4b/src/module/reference_handle.cc#L597-L599

TypeError: Set failed
    at (<isolated-vm boundary>)

Is this intended behavior?

issuefiler avatar Apr 18 '22 16:04 issuefiler

7.3.5 CreateDataProperty(O, P, V)

The abstract operation CreateDataProperty takes arguments O (an Object), P (a property key), and V (an ECMAScript language value) and returns either a normal completion containing a Boolean or an abrupt completion. It is used to create a new own property of an object. It performs the following steps when called:

  1. Let newDesc be the PropertyDescriptor {[[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}.
  2. Return ? O.[[DefineOwnProperty]](P, newDesc).

This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false.


var a;
Object.getOwnPropertyDescriptor(globalThis, "a");
// {value: undefined, writable: true, enumerable: true, configurable: false}

I get the CreateDataProperty returning false because a non-configurable property already exists for the key; but the question is: is it expected behavior for (reference).set, which has enough force to alter the property descriptor? Isn’t it a bit a misnomer, “set?”

issuefiler avatar Apr 18 '22 17:04 issuefiler

Is there any way to force-set the non-configurable Object.prototype and replace it with a Proxy to it? For the obfuscated code analysis purposes. I need to track down what properties it accesses.

issuefiler avatar Apr 19 '22 07:04 issuefiler