berstend / node-safe

🤠 Make using Node.js safe again with Deno-like permissions
https://node-safe.com
203 stars 8 forks source link

[feature discussion] granular permissions for packages #1

Open clouedoc opened 2 years ago

clouedoc commented 2 years ago

Would it be desirable and technically feasible to define package-based configurations instead of project-based configurations?

I.e.:

berstend commented 2 years ago

Thanks for starting the discussion on packages 😄

(This is a more long form answer with context, as the project is new and it might be a good reference)

Behind the scenes:

Would it be possible to define package-based permissions?

Caveats:

Where would these package permission definitions come from?

Overall the next step of the node-safe project is to figure out where to go with the sandboxing idea, to make it really frictionless so it's a no brainer to use sandboxing by default.

In #2 I'm discussing the idea of supporting a default config file that would scope all permissions to the project folder (and temp) by default, which should make most common projects work out of the box without the need to configure anything.

We're still in the early days of this project but I'm eager to build something that is useful for myself, working on this made me acutely aware of the madness of not sandboxing random code from the internet. 😄

berstend commented 2 years ago

Thinking about it: Using a default configuration file mentioned in #2 in combo with package name specific extra permissions (defined in the default file) makes a lot of sense:

We get good security by default with zero work for everything we work on and when using packages like puppeteer we only need to add their name and special permissions once to our default config and whenever puppeteer is used anywhere the extra permissions will apply automatically.

azerum commented 1 year ago

How exactly would such feature work? Will it still be a set of permissions for a single process, but now needed permissions would be automatically enabled/disabled according to used packages?

Having read discussions about module-based granular permissions in deno repos, it seems like there's no simple way to detect what code belongs to what package and what permissions it should have. For example, a library might take user function as callback

clouedoc commented 1 year ago

Here are some ideas:

  1. Create multiple Sandboxes; put modules with similar profiles in the same sandboxes. Communications are done via IPC
  2. Mark user function callbacks with read-only Symbol at startup by analysing the codebase. Hook NodeJS low-level APIs and check the call stack to see functions permissions.
OmgImAlexis commented 1 year ago

I wonder if the new permissions API + https://github.com/nodejs/node/pull/47855 can be used for this.