asvd / jailed

execute untrusted code with custom permissions
MIT License
1k stars 73 forks source link

Exposing values from the app to the jailed worker. #52

Open nahumzs opened 4 years ago

nahumzs commented 4 years ago

do you know if it's possible to expose values or methods to the jailed plugin?

From what I'm understanding you can expose functions that the worker can execute 1 time and then pass information from the worker/plugin to the application.

I would like to do the opposite let the worker call a function to the application and the application returns a value or method that can be used on the code on the plugin side.

something like:

const api = {
   someFancyStuff: async () => {
     const response = await fetch(url, options);
     return response
  },
  output: () => {
    // do somehting with the ouput
}
}

new jailed.DynamicPlugin(code, api);

so far if I execute application.remote.someFancyStuff() the return value is undefined even if I'm just doing return 1

thank you.

willstott101 commented 4 years ago

You must use callbacks to communicate asynchronously. Return values are ignored in functions.