Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: known issue with CopyProperties throw on empty code #11902

Closed
jasnell opened this issue Mar 17, 2017 · 7 comments
Closed

vm: known issue with CopyProperties throw on empty code #11902

jasnell opened this issue Mar 17, 2017 · 7 comments
Labels
confirmed-bug Issues with confirmed bugs. vm Issues and PRs related to the vm subsystem.

Comments

@jasnell
Copy link
Member

jasnell commented Mar 17, 2017

CopyProperties() causes sandboxed Proxy to throw error
despite no code being run. The CopyProperties() function
will be removed shortly with the updates to the V8 API.

Refs: #11671

'use strict';

//Sandbox throws in CopyProperties() despite no code being run

require('../common');
const assert = require('assert');
const vm = require('vm');

const handler = {
    getOwnPropertyDescriptor: (target, prop) => {
      throw new Error('whoops');
    }
};
const sandbox = new Proxy({foo: 'bar'}, handler);
const context = vm.createContext(sandbox);


assert.doesNotThrow(() => vm.runInContext('', context));
@jasnell jasnell added the confirmed-bug Issues with confirmed bugs. label Mar 17, 2017
@fhinkel fhinkel added the vm Issues and PRs related to the vm subsystem. label Mar 17, 2017
@ace-n
Copy link

ace-n commented Apr 16, 2017

Not sure if this is related (or even a problem), but the example below throws an error on v8.0.0-pre:

'use strict';

const handler = {
    getOwnPropertyDescriptor: function(target, prop) {
      throw new Error('whoops');
    }
};
const sandbox = new Proxy({foo: 'bar'}, handler);
console.log(sandbox);
/Users/ace/Desktop/node/test.js:5
      throw new Error('whoops');
      ^

Error: whoops
    at Object.get (/Users/ace/Desktop/node/test.js:5:13)
    at formatValue (util.js:311:38)
    at inspect (util.js:152:10)
    at exports.format (util.js:34:24)
    at Console.log (console.js:85:24)
    at Object.<anonymous> (/Users/ace/Desktop/node/test.js:9:9)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)

AFAICT, console.log(sandbox) uses the getOwnPropertyDescriptor method as defined in the sandbox (i.e. in handler).

Since the console.log is running in the 'global' context, I'm guessing that it should be using the global getOwnPropertyDescriptor version (and not that of the sandbox).

Happy to investigate this further if this is indeed the/an issue and I'm on the right track.

@TimothyGu
Copy link
Member

TimothyGu commented Apr 16, 2017

Since the console.log is running in the 'global' context, I'm guessing that it should be using the global getOwnPropertyDescriptor version (and not that of the sandbox).

Can you elaborate? What did you mean by "'global' context"? If you mean Object.getOwnPropertyDescriptors(), that function uses the getOwnPropertyDescriptor trap of the proxy per spec.

@ace-n
Copy link

ace-n commented Apr 16, 2017

@TimothyGu yeah - that is what I meant by the global context. What I'm not sure of is whether that trap is supposed to occur.

The error itself is triggered by calling Object.keys() on the sandbox object here.

It seems like it is, given that running the following example in Chrome's version of v8 gives this pattern:

/* sandbox code from previous comment */

console.log(sandbox); // no error
console.log(Object.keys(sandbox)); // raises error

To tie this back to the original issue: it seems like CopyProperties() calls Object.getOwnPropertyDescriptor() - but I don't know whether it should call the proxy's version or the default one.

@addaleax
Copy link
Member

@ace-n I’m not sure how CopyProperties() relates to the code that you are using, though? Unless you’re using the vm module in some way, I would say it’s unrelated, so I’d suggest opening a new issue.

@ace-n
Copy link

ace-n commented Apr 16, 2017

@addaleax thanks - I've filed a new issue here and will continue the discussion there. Sorry for any confusion!

@Trott
Copy link
Member

Trott commented Aug 2, 2017

Should this stay open?

@fhinkel
Copy link
Member

fhinkel commented Oct 19, 2017

Yes, it's still an issue.

fhinkel added a commit to fhinkel/node that referenced this issue Oct 23, 2017
Remove the CopyProperties() hack in the vm module, i.e., Contextify.
Use different V8 API methods, that allow interception of
DefineProperty() and do not flatten accessor descriptors to
property descriptors.

Move many known issues to test cases. Factor out the last test in
test-vm-context.js for
nodejs#10223
into its own file, test-vm-strict-assign.js.

Part of this CL is taken from a stalled PR by
https://github.com/AnnaMag
nodejs#13265

This PR requires a backport of
https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f

Refs: nodejs#6283
Refs: nodejs#15114
Refs: nodejs#13265

Fixes: nodejs#2734
Fixes: nodejs#10223
Fixes: nodejs#11803
Fixes: nodejs#11902
addaleax pushed a commit to ayojs/ayo that referenced this issue Oct 26, 2017
Remove the CopyProperties() hack in the vm module, i.e., Contextify.
Use different V8 API methods, that allow interception of
DefineProperty() and do not flatten accessor descriptors to
property descriptors.

Move many known issues to test cases. Factor out the last test in
test-vm-context.js for
nodejs/node#10223
into its own file, test-vm-strict-assign.js.

Part of this CL is taken from a stalled PR by
https://github.com/AnnaMag
nodejs/node#13265

This PR requires a backport of
https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f

PR-URL: nodejs/node#16293
Fixes: nodejs/node#2734
Fixes: nodejs/node#10223
Fixes: nodejs/node#11803
Fixes: nodejs/node#11902
Ref: nodejs/node#6283
Ref: nodejs/node#15114
Ref: nodejs/node#13265
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this issue Dec 7, 2017
Remove the CopyProperties() hack in the vm module, i.e., Contextify.
Use different V8 API methods, that allow interception of
DefineProperty() and do not flatten accessor descriptors to
property descriptors.

Move many known issues to test cases. Factor out the last test in
test-vm-context.js for
nodejs/node#10223
into its own file, test-vm-strict-assign.js.

Part of this CL is taken from a stalled PR by
https://github.com/AnnaMag
nodejs/node#13265

This PR requires a backport of
https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f

PR-URL: nodejs/node#16293
Fixes: nodejs/node#2734
Fixes: nodejs/node#10223
Fixes: nodejs/node#11803
Fixes: nodejs/node#11902
Ref: nodejs/node#6283
Ref: nodejs/node#15114
Ref: nodejs/node#13265
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants