jkcfg / jk

Configuration as Code with ECMAScript
https://jkcfg.github.io
Apache License 2.0
404 stars 30 forks source link

Use "virtual file systems" for sandboxing reads and module resolution #307

Closed squaremo closed 4 years ago

squaremo commented 4 years ago

This PR changes the handling of file lookups so that they are mediated via a virtual filesystem (or "vfs", a thin wrapper around http.FileSystem). Instead of passing around paths on the host system, locations which comprise a vfs and a path within it are used.

The point of it all is to reduce the opportunities for escaping the "sandbox" -- instead of having to carefully guard which paths can be read to make sure they are under an allowed directory, they are just read from a filesystem that doesn't include anything outside the directory.

As a benefit, other implementations of http.FileSystem can now be substituted, to introduce alternative sources of files (e.g., container images).

There are complications:

This also rationalised the import system: there is now an importer that uses NPM rules, an importer that uses the simpler "module/path" rules, and an importer that resolves paths that are explicitly relative to the importing module. This reduces some duplication, especially of that latter mode of resolution.

squaremo commented 4 years ago

TODO