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: strict mode ReferenceError with assignment to context property #12300

Closed
bnoordhuis opened this issue Apr 10, 2017 · 6 comments
Closed

vm: strict mode ReferenceError with assignment to context property #12300

bnoordhuis opened this issue Apr 10, 2017 · 6 comments
Labels
vm Issues and PRs related to the vm subsystem.

Comments

@bnoordhuis
Copy link
Member

Split off from #5344 (comment).

'use strict';
const vm = require('vm');
const ctx = vm.createContext({ x: 42 });

try {
  const result = vm.runInContext('"use strict"; x = 1', ctx);
} catch(e) {
  console.log(e.stack);
  console.log('x is', ctx.x)
}
@bnoordhuis bnoordhuis added the vm Issues and PRs related to the vm subsystem. label Apr 10, 2017
@bnoordhuis
Copy link
Member Author

Probably cannot be fixed easily without regressing #10223. The problem is that GlobalPropertySetterCallback() does not check if the property exists on the context object.

Adding the check is not enough by itself. It should also record and check property attributes, otherwise non-writable properties can be overwritten.

@hashseed
Copy link
Member

hashseed commented Apr 11, 2017

@fhinkel

@fhinkel
Copy link
Member

fhinkel commented Apr 12, 2017

We don't have coherent behavior what to do on the sandbox, when the setting/getting/deleting/defining fails or has side effects.

@AnnaMag is about to open a PR that removes the CopyProperties() hack. Once that landed we should come back to this and rethink it.

@Trott
Copy link
Member

Trott commented Aug 2, 2017

Should this remain open?

@fhinkel
Copy link
Member

fhinkel commented Aug 4, 2017

It's still an issue. We could add a known_issue test for it and close this.

fhinkel added a commit to fhinkel/node that referenced this issue Aug 7, 2017
GlobalPropertySetterCallback() does not check the
property on the sandbox. It wrongly throws an error
instead of updating `x`.

Refs: nodejs#12300
jasnell pushed a commit that referenced this issue Aug 23, 2017
GlobalPropertySetterCallback() does not check the
property on the sandbox. It wrongly throws an error
instead of updating `x`.

PR-URL: #14661
Ref: #12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
addaleax pushed a commit to addaleax/ayo that referenced this issue Aug 25, 2017
GlobalPropertySetterCallback() does not check the
property on the sandbox. It wrongly throws an error
instead of updating `x`.

PR-URL: nodejs/node#14661
Ref: nodejs/node#12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this issue Aug 28, 2017
GlobalPropertySetterCallback() does not check the
property on the sandbox. It wrongly throws an error
instead of updating `x`.

PR-URL: nodejs/node#14661
Ref: nodejs/node#12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
MylesBorins pushed a commit that referenced this issue Sep 10, 2017
GlobalPropertySetterCallback() does not check the
property on the sandbox. It wrongly throws an error
instead of updating `x`.

PR-URL: #14661
Ref: #12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
MylesBorins pushed a commit that referenced this issue Sep 12, 2017
GlobalPropertySetterCallback() does not check the
property on the sandbox. It wrongly throws an error
instead of updating `x`.

PR-URL: #14661
Ref: #12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
MylesBorins pushed a commit that referenced this issue Sep 20, 2017
GlobalPropertySetterCallback() does not check the
property on the sandbox. It wrongly throws an error
instead of updating `x`.

PR-URL: #14661
Ref: #12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
fhinkel added a commit to fhinkel/node that referenced this issue Oct 25, 2017
This patch fixes the problem with variables that
are declared only on the sandbox but not on the
global proxy.

Fixes: nodejs#12300
gibfahn pushed a commit that referenced this issue Oct 30, 2017
This patch fixes the problem with variables that
are declared only on the sandbox but not on the
global proxy.

PR-URL: #16487
Fixes: #12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
gibfahn pushed a commit that referenced this issue Oct 30, 2017
This patch fixes the problem with variables that
are declared only on the sandbox but not on the
global proxy.

PR-URL: #16487
Fixes: #12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
gibfahn pushed a commit that referenced this issue Oct 31, 2017
This patch fixes the problem with variables that
are declared only on the sandbox but not on the
global proxy.

PR-URL: #16487
Fixes: #12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Qard pushed a commit to ayojs/ayo that referenced this issue Nov 2, 2017
This patch fixes the problem with variables that
are declared only on the sandbox but not on the
global proxy.

PR-URL: nodejs/node#16487
Fixes: nodejs/node#12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Qard pushed a commit to ayojs/ayo that referenced this issue Nov 2, 2017
This patch fixes the problem with variables that
are declared only on the sandbox but not on the
global proxy.

PR-URL: nodejs/node#16487
Fixes: nodejs/node#12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax pushed a commit to ayojs/ayo that referenced this issue Dec 7, 2017
This patch fixes the problem with variables that
are declared only on the sandbox but not on the
global proxy.

PR-URL: nodejs/node#16487
Fixes: nodejs/node#12300
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@guo-yu
Copy link

guo-yu commented Sep 17, 2018

I found the vm module still throws a weird error when replace 1 with a function like this:

'use strict';
const vm = require('vm');
const ctx = vm.createContext({ x: 42 });

try {
  const result = vm.runInContext('"use strict"; x = function demo(){};', ctx);
} catch(e) {
  console.log(e.stack);
  console.log('x is', ctx.x)
}

as it throw this error:

ReferenceError: x is not defined

Is there anything might be missing in the last bugfix patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants