安全
🌐 Security
VFS API 不是沙箱、权限系统或访问控制机制。它不会将不受信任的代码与主文件系统或其他 Node.js 功能隔离开来。可以访问 VirtualFileSystem 实例、挂载它、选择它的提供者或向它传递路径的代码都是受信任的应用代码。
🌐 The VFS API is not a sandbox, permission system, or access-control mechanism.
It does not isolate untrusted code from the host file system or from other
Node.js capabilities. Code that can access a VirtualFileSystem instance,
mount it, select its provider, or pass paths to it is trusted application code.
挂载 VFS 只是重定向受支持的 node:fs 调用,这些调用解析的路径位于挂载点下。它并不能阻止代码使用其他路径或其他 Node.js API 来访问进程可用的资源。RealFSProvider 会将 VFS 路径映射到其配置的根目录下,并拒绝解析到该根目录之外的路径,但这个检查不是安全边界。ZipProvider 本身没有真正的文件系统路径可供逃逸;它的条目只存在于归档自己的命名空间中。不要依赖 VFS 来运行不可信的代码;在需要安全边界时,请使用操作系统级别的隔离,例如不同的用户、容器或平台沙箱。
🌐 Mounting a VFS only redirects supported node:fs calls whose resolved paths
are under the mount point. It does not prevent code from using other paths or
other Node.js APIs to access resources available to the process.
RealFSProvider maps VFS paths under its configured root and rejects paths
that resolve outside that root, but that check is not a security boundary.
ZipProvider has no real file-system paths of its own to escape; its
entries only ever exist within the archive's own namespace. Do not rely on VFS
to run untrusted code; use operating-system-level isolation, such as separate
users, containers, or platform sandboxes, when a security boundary is
required.