callum
callum

Reputation: 37859

Is fs the only builtin module that can access the filesystem?

I know there are other things like require that can access the real filesystem, but this appears to use fs to do so.

Am I right in thinking that there are no other builtins that have direct access to the disk?

That is, if I was able to globally overwrite all fs methods with my own mocks that read from (and write to) an in-memory virtual filesystem, then there would be no way to access the real filesystem – is that correct?

Upvotes: 3

Views: 69

Answers (2)

Vinayk93
Vinayk93

Reputation: 355

There are many ways you can access the file system.
Make a child process execute

ls
cd ..
nano filename

and fetch the result.

Upvotes: 0

rsp
rsp

Reputation: 111506

In principle, that is correct. But other modules could spawn processes to access the file system or they could use some native addons that use the file system. If you want to do it as a security measure then it will not be sufficient. If you wanted to make sure that no module can access the real file system then you would have to hijack the system calls on the OS level and make sure that no external process could be run as well. Not an easy task. Probably the same could be achieved easier using containers that would run with an in memory file system and would have no way to access the external file system on the host system, not on the level of JavaScript.

Upvotes: 2

Related Questions