文件系统权限
【File System Permissions】
默认情况下,权限模型通过 node:fs 模块限制对文件系统的访问。它并不能保证用户无法通过其他方式访问文件系统,例如通过 node:sqlite 模块。
【The Permission Model, by default, restricts access to the file system through the node:fs module.
It does not guarantee that users will not be able to access the file system through other means,
such as through the node:sqlite module.】
要允许访问文件系统,请使用 --allow-fs-read 和 --allow-fs-write 标志:
【To allow access to the file system, use the --allow-fs-read and
--allow-fs-write flags:】
$ node --permission --allow-fs-read=* --allow-fs-write=* index.js
Hello world! 默认情况下,你的应用的入口点会被包含在允许读取的文件系统列表中。例如:
【By default the entrypoints of your application are included in the allowed file system read list. For example:】
$ node --permission index.js index.js将被包含在允许的文件系统读取列表中
$ node -r /path/to/custom-require.js --permission index.js. /path/to/custom-require.js将被包含在允许的文件系统读取列表中。index.js将被包含在允许的文件系统读取列表中。
两个标志的有效参数是:
【The valid arguments for both flags are:】
*- 分别允许所有FileSystemRead或FileSystemWrite操作。- 相对于当前工作目录的路径。
- 绝对路径。
示例:
【Example:】
--allow-fs-read=*- 它将允许所有FileSystemRead操作。--allow-fs-write=*- 它将允许所有FileSystemWrite操作。--allow-fs-write=/tmp/- 它将允许对/tmp/文件夹进行FileSystemWrite访问。--allow-fs-read=/tmp/ --allow-fs-read=/home/.gitignore- 它允许对/tmp/文件夹 以及/home/.gitignore路径进行FileSystemRead访问。
也支持通配符:
【Wildcards are supported too:】
--allow-fs-read=/home/test*将允许读取与通配符匹配的所有内容。例如:/home/test/file1或/home/test2
在通配符字符(*)之后,所有后续字符将被忽略。例如:/home/*.js 的效果类似于 /home/*。
【After passing a wildcard character (*) all subsequent characters will
be ignored. For example: /home/*.js will work similar to /home/*.】
当权限模型初始化时,如果指定的目录存在,它会自动添加通配符(*)。例如,如果 /home/test/files 存在,它将被视为 /home/test/files/*。然而,如果目录不存在,将不会添加通配符,并且访问将限制在 /home/test/files。如果你想允许访问尚不存在的文件夹,请确保明确包含通配符:/my-path/folder-do-not-exist/*。
【When the permission model is initialized, it will automatically add a wildcard
(*) if the specified directory exists. For example, if /home/test/files
exists, it will be treated as /home/test/files/*. However, if the directory
does not exist, the wildcard will not be added, and access will be limited to
/home/test/files. If you want to allow access to a folder that does not exist
yet, make sure to explicitly include the wildcard:
/my-path/folder-do-not-exist/*.】