patriksimek / vm2

Advanced vm/sandbox for Node.js
MIT License
3.86k stars 294 forks source link

built-in modules "set on proxy: trap returned falsish for property x" #481

Closed Mahmoud-Abousereaa closed 1 year ago

Mahmoud-Abousereaa commented 1 year ago

Hi @XmiliaH ,

I am encountering an issue trying to set a property on one of the built-in modules.

Here is an example of the code

const {NodeVM} = require('vm2');

const vm = new NodeVM({
  require: {
    external: true,
    builtin: ['url'],
    context: 'sandbox',
  },
  strict: true,
});

vm.run(`
  const URL = require('url').URL;
  const url = new URL('someurl');
  url.pathname = url.pathname + '/test';
`);

The above code throws the following error

set' on proxy: trap returned falsish for property 'pathname

From what I understand the URL class is not extending any proxied class, therefore, I was expecting that it should be possible to modify its properties.

I am running node v14.19.3

XmiliaH commented 1 year ago

This is the expected behavior. The builtin modules are loaded in the host and are read-only in the sandbox and instances created with it too.