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

Protect VM denaying the use of constructor function #249

Closed
SecSamDev opened this issue Oct 4, 2019 · 2 comments
Closed

Protect VM denaying the use of constructor function #249

SecSamDev opened this issue Oct 4, 2019 · 2 comments

Comments

@SecSamDev
Copy link

In theory, this works, not many libraries need to modify the constructor.

Function.prototype.constructor = function (data) {
    console.log('Trying to use constructor...')
    console.log(data)
    return function(dat){
        return null;
    }
}
@SecSamDev SecSamDev changed the title Protect VM from using construct function Protect VM denaying the use of constructor function Oct 4, 2019
@XmiliaH
Copy link
Collaborator

XmiliaH commented Oct 4, 2019

I don't see a reason to do this. If you want to do so you can execute code in the VM that hides all the Function constructors. But don't forget the global Function object and also GeneratorFunction, AsyncFunction & AsyncGeneratorFunctions.

@SecSamDev
Copy link
Author

SecSamDev commented Oct 4, 2019

I just tested it:

const sandbox = {test : async function(){return 1}}
try{
    let result = vm.runInNewContext(`
try{
    test.constructor('return process')().then(dat=>{
        console.log(dat)
    })
}catch(e){console.log(e)}
`, sandbox,{timeout : 10000})

Outputs process {version: "v12.10.0", versions: Object, arch: "x64", platform: "linux", release: Object, …}

But I suppose that it can be helpful in some cases to disallow the creation of objects using the constructor functions.
Thnx for the recommendation.

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

No branches or pull requests

2 participants