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

Internal restructuring and security improvements #395

Merged
merged 2 commits into from Feb 8, 2022

Conversation

XmiliaH
Copy link
Collaborator

@XmiliaH XmiliaH commented Feb 8, 2022

This PR splits large files into multiple for better maintainability. Furthermore, the contextify.js module was rewritten from scratch to handle RangeErrors in the correct context and be able to handle RangeErrors from the different context too.
This also includes security improvements for NodeVM's require which had issues with options being circumvented with relative or absolute requires.

@XmiliaH XmiliaH merged commit 532120d into patriksimek:master Feb 8, 2022
@patriksimek
Copy link
Owner

This is awesome! Thank you ❤️

cacheUtilScript = new VMScript(`return function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
}`, {__proto__: null, filename: 'util.js'});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setPrototypeOf(target, value) {
  // Note: target@this(unsafe) throws@this(unsafe)
  throw new VMError(OPNA);
}

I have some questions about inherits:

  • Why forbidden to use inherits in vm2?
  • As mentioned in the above code, why not just throw an exception but use setPrototypeOf instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually allows to use inherits in the sandbox. Without it would not work for sandboxed objects and would allow the sandbox to change the prototype chain of host objects passed into the sandbox. The code you copied will only be called when inherits is used on a host object where it should not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants