Sitelet https://github.com/nodejs/node/issues/5350
Skip to content

sandbox inheritied properties flattened after vm.runInNewContext #5350

Description

@waynedpj

on node-4.5.1 when using a sandbox Object with inherited properties, after running sandbox in vm.runInNewContext all properties up the prototype chain are copied to sandbox Object, even if they are not changed by code, though the prototype chain is still there. here is a failing test case

'use strict';

let vm = require('vm'), assert = require('assert');

let base = Object.create(null);
base.x = 1;
base.y = 2;

let sandbox = Object.create(base);
sandbox.z = 3;

console.log('base:\n%j', base);
console.log('sandbox:\n%j', sandbox);
console.log("sandbox's own keys:\n%j", Object.keys(sandbox));

let code = 'x = 0; z = 4;';
let result = vm.runInNewContext(code, sandbox);
console.log('result: %s', result);

console.log('base:\n%j', base);
console.log('sandbox:\n%j', sandbox);
console.log("sandbox's own keys:\n%j", Object.keys(sandbox));

assert((Object.keys(sandbox)).indexOf('y') === -1);  // fails

note that the same problem occurs even if code is empty, as well as with vm.runInContext.

not sure if this is expected behavior or not, but i was surprised to have sandbox modified like that. if it is normal, i did not find any mention of it in the docs, and would ask if someone could kindly explain why?

thanks.

Activity

  1. added
    vmIssues and PRs related to the vm subsystem.
    on Feb 21, 2016
  2. abenhamdine commented on Feb 29, 2016

    @abenhamdine

    @waynedpj do you see the same behaviour with the last stable version of nodejs ?
    I also see some strange behaviours with the sandbox object properties on node 5.7 (but not exactly the same problem as your), but i'm still investigating before opening an issue.

  3. waynedpj commented on Feb 29, 2016

    @waynedpj
    Author

    @abenhamdine yes, i still see the same issue w/ 5.7. i have been investigating this further, and though i am not totally following what is going on yet, i suspect that this flattening of sandbox's prototype chain might be happening here in CopyProperties. but i am not familiar enough yet w/ Node.js's C++ code yet ;)

    does your issue involve the sandbox being modified unexpectedly?

    please let us know if you find anything and thanks.

  4. waynedpj commented on Feb 29, 2016

    @waynedpj
    Author

    PS. @abenhamdine which strange behaviors are you seeing?

  5. abenhamdine commented on Feb 29, 2016

    @abenhamdine

    I just opened an issue : #5491

  6. jasnell commented on Apr 19, 2016

    @jasnell
    Member

    Pretty certain this is the same issue as #2734

  7. jasnell commented on Apr 19, 2016

    @jasnell
    Member

    @nodejs/v8 ... can anyone on the v8 site assist with this one?

  8. jeisinger commented on Apr 19, 2016

    @jeisinger
    Contributor

    I'll sync with Domenic and Ali to understand the exact requirements here.

  9. 16 remaining items

  10. fhinkel commented on Oct 23, 2017

    @fhinkel
    Contributor

    This got fixed in #16293.

  11. waynedpj commented on Oct 23, 2017

    @waynedpj
    Author

    thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions