{
  "type": "module",
  "source": "doc/api/permissions.md",
  "modules": [
    {
      "textRaw": "Permissions",
      "name": "permissions",
      "introduced_in": "v20.0.0",
      "type": "module",
      "desc": "<p>Permissions can be used to control what system resources the\nNode.js process has access to or what actions the process can take\nwith those resources.</p>\n<ul>\n<li><a href=\"#process-based-permissions\">Process-based permissions</a> control the Node.js\nprocess's access to resources.\nThe resource can be entirely allowed or denied, or actions related to it can\nbe controlled. For example, file system reads can be allowed while denying\nwrites.\nThis feature does not protect against malicious code. According to the Node.js\n<a href=\"https://github.com/nodejs/node/blob/main/SECURITY.md\">Security Policy</a>, Node.js trusts any code it is asked to run.</li>\n</ul>\n<p>The permission model implements a \"seat belt\" approach, which prevents trusted\ncode from unintentionally changing files or using resources that access has\nnot explicitly been granted to. It does not provide security guarantees in the\npresence of malicious code. Malicious code can bypass the permission model and\nexecute arbitrary code without the restrictions imposed by the permission\nmodel.</p>\n<p>If you find a potential security vulnerability, please refer to our\n<a href=\"https://github.com/nodejs/node/blob/main/SECURITY.md\">Security Policy</a>.</p>",
      "modules": [
        {
          "textRaw": "Process-based permissions",
          "name": "process-based_permissions",
          "type": "module",
          "modules": [
            {
              "textRaw": "Permission Model",
              "name": "permission_model",
              "type": "module",
              "meta": {
                "added": [
                  "v20.0.0"
                ],
                "changes": [
                  {
                    "version": [
                      "v23.5.0",
                      "v22.13.0"
                    ],
                    "pr-url": "https://github.com/nodejs/node/pull/56201",
                    "description": "This feature is no longer experimental."
                  }
                ]
              },
              "stability": 2,
              "stabilityText": "Stable",
              "desc": "<p>The Node.js Permission Model is a mechanism for restricting access to specific\nresources during execution.\nThe API exists behind a flag <a href=\"cli.html#--permission\"><code>--permission</code></a> which when enabled,\nwill restrict access to all available permissions.</p>\n<p>The available permissions are documented by the <a href=\"cli.html#--permission\"><code>--permission</code></a>\nflag.</p>\n<p>The Permission Model has two operational modes:</p>\n<ul>\n<li><strong>Enforce mode</strong> (default when using <a href=\"cli.html#--permission\"><code>--permission</code></a>): Access is denied and\nan <code>ERR_ACCESS_DENIED</code> error is thrown for any operation the process has not\nbeen granted permission to perform.</li>\n<li><strong>Audit mode</strong> (when using <a href=\"cli.html#--permission-audit\"><code>--permission-audit</code></a>): Permission checks are\nperformed and violations are published through the diagnostics channel, but\naccess is <strong>not</strong> denied. Execution continues normally. This mode is useful\nfor discovering what permissions your application requires before deploying\nwith enforce mode.</li>\n</ul>\n<p>When starting Node.js with <code>--permission</code>,\nthe ability to access the file system through the <code>fs</code> module, access the network,\nspawn processes, use <code>node:worker_threads</code>, use native addons, use WASI, use\nFFI, and enable the runtime inspector will be restricted (the listener for\nSIGUSR1 won't be created).</p>\n<pre><code class=\"language-console\">$ node --permission index.js\n\nError: Access to this API has been restricted\n    at node:internal/main/run_main_module:23:47 {\n  code: 'ERR_ACCESS_DENIED',\n  permission: 'FileSystemRead',\n  resource: '/home/user/index.js'\n}\n</code></pre>\n<p>Allowing access to spawning a process and creating worker threads can be done\nusing the <a href=\"cli.html#--allow-child-process\"><code>--allow-child-process</code></a> and <a href=\"cli.html#--allow-worker\"><code>--allow-worker</code></a> respectively.</p>\n<p>To allow network access, use <a href=\"cli.html#--allow-net\"><code>--allow-net</code></a> and for allowing native addons\nwhen using permission model, use the <a href=\"cli.html#--allow-addons\"><code>--allow-addons</code></a>\nflag. For WASI, use the <a href=\"cli.html#--allow-wasi\"><code>--allow-wasi</code></a> flag. For FFI, use the\n<a href=\"cli.html#--allow-ffi\"><code>--allow-ffi</code></a> flag. The <a href=\"ffi.html\"><code>node:ffi</code></a> module also requires the\n<code>--experimental-ffi</code> flag and is only available in builds with FFI support.</p>\n<p>To allow use of OpenSSL STORE loaders, for example to load a private key\nfrom a <a href=\"url.html#the-whatwg-url-api\"><code>&#x3C;URL></code></a> passed to <a href=\"crypto.html#cryptocreateprivatekeykey\"><code>crypto.createPrivateKey()</code></a>, use the\n<a href=\"cli.html#--allow-openssl-store\"><code>--allow-openssl-store</code></a> flag.\nThis flag grants broad authority to configured OpenSSL STORE loaders, which may\naccess files, devices, tokens, or the network. Access performed by a loader is\nnot constrained by the <code>fs.read</code>, <code>fs.write</code>, or <code>net</code> permission scopes.</p>",
              "modules": [
                {
                  "textRaw": "Runtime API",
                  "name": "runtime_api",
                  "type": "module",
                  "desc": "<p>When enabling the Permission Model through the <a href=\"cli.html#--permission\"><code>--permission</code></a>\nor <a href=\"cli.html#--permission-audit\"><code>--permission-audit</code></a> flags, a new property <code>permission</code> is added to the\n<code>process</code> object. This property contains the following functions:</p>",
                  "methods": [
                    {
                      "textRaw": "`permission.has(scope[, reference])`",
                      "name": "has",
                      "type": "method",
                      "signatures": [
                        {
                          "params": [
                            {
                              "name": "scope"
                            },
                            {
                              "name": "reference",
                              "optional": true
                            }
                          ]
                        }
                      ],
                      "desc": "<p>API call to check permissions at runtime (<a href=\"process.html#processpermissionhasscope-reference\"><code>permission.has()</code></a>)</p>\n<pre><code class=\"language-js\">process.permission.has('fs.write'); // true\nprocess.permission.has('fs.write', '/home/rafaelgss/protected-folder'); // true\n\nprocess.permission.has('fs.read'); // true\nprocess.permission.has('fs.read', '/home/rafaelgss/protected-folder'); // false\n</code></pre>"
                    },
                    {
                      "textRaw": "`permission.drop(scope[, reference])`",
                      "name": "drop",
                      "type": "method",
                      "signatures": [
                        {
                          "params": [
                            {
                              "name": "scope"
                            },
                            {
                              "name": "reference",
                              "optional": true
                            }
                          ]
                        }
                      ],
                      "desc": "<p>API call to drop permissions at runtime. This operation is <strong>irreversible</strong>.</p>\n<p>When called without a reference, the entire scope is dropped. When called\nwith a reference, only the permission for that specific resource is revoked.\nDropping a permission only affects future access checks. It does not close or\nrevoke access to resources that are already open, such as file descriptors,\nnetwork sockets, child processes, or worker threads. Applications are\nresponsible for closing or terminating those resources when they are no longer\nneeded.</p>\n<p>You can only drop the exact resource that was explicitly granted. The\nreference passed to <code>drop()</code> must match the original grant. If a permission\nwas granted using a wildcard (<code>*</code>), only the entire scope can be dropped\n(by calling <code>drop()</code> without a reference). If a directory was granted\n(e.g. <code>--allow-fs-read=/my/folder</code>), you cannot drop individual files\ninside it - you must drop the same directory that was originally granted.</p>\n<pre><code class=\"language-js\">const fs = require('node:fs');\n\n// Read config at startup while we still have permission\nconst config = fs.readFileSync('/etc/myapp/config.json', 'utf8');\n\n// Drop read access to /etc/myapp after initialization\nprocess.permission.drop('fs.read', '/etc/myapp');\n\n// This will now throw ERR_ACCESS_DENIED\nprocess.permission.has('fs.read', '/etc/myapp/config.json'); // false\n\n// Drop child process permission entirely\nprocess.permission.drop('child');\n</code></pre>"
                    }
                  ],
                  "displayName": "Runtime API"
                },
                {
                  "textRaw": "Audit Mode",
                  "name": "audit_mode",
                  "type": "module",
                  "desc": "<p>The <a href=\"cli.html#--permission-audit\"><code>--permission-audit</code></a> flag enables audit mode for the Permission Model.\nIn audit mode, permission checks are performed but access is <strong>not</strong> denied —\nno <code>ERR_ACCESS_DENIED</code> error is thrown. Instead, each permission violation is\npublished through the <code>node:diagnostics_channel</code> module, allowing the\napplication to observe and log which operations would be denied under enforce\nmode. Execution continues normally.</p>\n<p>Audit mode is useful for discovering what permissions your application\nrequires before deploying with <a href=\"cli.html#--permission\"><code>--permission</code></a>. It can also be combined\nwith the <a href=\"cli.html#--allow-fs-read\"><code>--allow-fs-read</code></a>, <a href=\"cli.html#--allow-fs-write\"><code>--allow-fs-write</code></a>, <a href=\"cli.html#--allow-net\"><code>--allow-net</code></a>,\n<a href=\"cli.html#--allow-child-process\"><code>--allow-child-process</code></a>, <a href=\"cli.html#--allow-worker\"><code>--allow-worker</code></a>, <a href=\"cli.html#--allow-addons\"><code>--allow-addons</code></a>,\n<a href=\"cli.html#--allow-wasi\"><code>--allow-wasi</code></a>, and <a href=\"cli.html#--allow-ffi\"><code>--allow-ffi</code></a> flags to audit a subset of\npermissions while granting others.</p>\n<p>When a permission check fails in audit mode, a message is published to the\ndiagnostics channel corresponding to the denied scope. The channel names are:</p>\n<ul>\n<li><code>node:permission-model:fs</code> — File System (read and write)</li>\n<li><code>node:permission-model:net</code> — Network</li>\n<li><code>node:permission-model:child</code> — Child Process</li>\n<li><code>node:permission-model:worker</code> — Worker Threads</li>\n<li><code>node:permission-model:inspector</code> — Inspector</li>\n<li><code>node:permission-model:wasi</code> — WASI</li>\n<li><code>node:permission-model:addon</code> — Native Addons</li>\n<li><code>node:permission-model:ffi</code> — FFI</li>\n</ul>\n<p>Each message is an object with the following properties:</p>\n<ul>\n<li><code>permission</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The name of the denied permission scope.</li>\n<li><code>resource</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The resource that access was denied to (e.g. a file path\nor host).</li>\n</ul>\n<pre><code class=\"language-js\">const diagnostics_channel = require('node:diagnostics_channel');\n\ndiagnostics_channel.channel('node:permission-model:fs').subscribe((msg) => {\n  console.log(`Permission denied: ${msg.permission} on ${msg.resource}`);\n});\n\n// Running with --permission-audit, this publishes a diagnostics channel\n// message but does not throw\nconst fs = require('node:fs');\nfs.readFileSync('/etc/passwd');\n</code></pre>\n<p>If both <a href=\"cli.html#--permission\"><code>--permission</code></a> and <a href=\"cli.html#--permission-audit\"><code>--permission-audit</code></a> are specified,\n<code>--permission</code> takes precedence and the Permission Model runs in enforce mode.</p>",
                  "displayName": "Audit Mode"
                },
                {
                  "textRaw": "File System Permissions",
                  "name": "file_system_permissions",
                  "type": "module",
                  "desc": "<p>The Permission Model, by default, restricts access to the file system through the <code>node:fs</code> module.\nIt does not guarantee that users will not be able to access the file system through other means,\nsuch as through the <code>node:sqlite</code> module.</p>\n<p>To allow access to the file system, use the <a href=\"cli.html#--allow-fs-read\"><code>--allow-fs-read</code></a> and\n<a href=\"cli.html#--allow-fs-write\"><code>--allow-fs-write</code></a> flags:</p>\n<pre><code class=\"language-console\">$ node --permission --allow-fs-read=* --allow-fs-write=* index.js\nHello world!\n</code></pre>\n<p>By default the entrypoints of your application are included\nin the allowed file system read list. For example:</p>\n<pre><code class=\"language-console\">$ node --permission index.js\n</code></pre>\n<ul>\n<li><code>index.js</code> will be included in the allowed file system read list</li>\n</ul>\n<pre><code class=\"language-console\">$ node -r /path/to/custom-require.js --permission index.js.\n</code></pre>\n<ul>\n<li><code>/path/to/custom-require.js</code> will be included in the allowed file system read\nlist.</li>\n<li><code>index.js</code> will be included in the allowed file system read list.</li>\n</ul>\n<p>The valid arguments for both flags are:</p>\n<ul>\n<li><code>*</code> - To allow all <code>FileSystemRead</code> or <code>FileSystemWrite</code> operations,\nrespectively.</li>\n<li>Relative paths to the current working directory.</li>\n<li>Absolute paths.</li>\n</ul>\n<p>Example:</p>\n<ul>\n<li><code>--allow-fs-read=*</code> - It will allow all <code>FileSystemRead</code> operations.</li>\n<li><code>--allow-fs-write=*</code> - It will allow all <code>FileSystemWrite</code> operations.</li>\n<li><code>--allow-fs-write=/tmp/</code> - It will allow <code>FileSystemWrite</code> access to the <code>/tmp/</code>\nfolder.</li>\n<li><code>--allow-fs-read=/tmp/ --allow-fs-read=/home/.gitignore</code> - It allows <code>FileSystemRead</code> access\nto the <code>/tmp/</code> folder <strong>and</strong> the <code>/home/.gitignore</code> path.</li>\n</ul>\n<p>Wildcards are supported too:</p>\n<ul>\n<li><code>--allow-fs-read=/home/test*</code> will allow read access to everything\nthat matches the wildcard. e.g: <code>/home/test/file1</code> or <code>/home/test2</code></li>\n</ul>\n<p>After passing a wildcard character (<code>*</code>) all subsequent characters will\nbe ignored. For example: <code>/home/*.js</code> will work similar to <code>/home/*</code>.</p>\n<p>When the permission model is initialized, it will automatically add a wildcard\n(*) if the specified directory exists. For example, if <code>/home/test/files</code>\nexists, it will be treated as <code>/home/test/files/*</code>. However, if the directory\ndoes not exist, the wildcard will not be added, and access will be limited to\n<code>/home/test/files</code>. If you want to allow access to a folder that does not exist\nyet, make sure to explicitly include the wildcard:\n<code>/my-path/folder-do-not-exist/*</code>.</p>",
                  "displayName": "File System Permissions"
                },
                {
                  "textRaw": "Configuration file support",
                  "name": "configuration_file_support",
                  "type": "module",
                  "desc": "<p>In addition to passing permission flags on the command line, they can also be\ndeclared in a Node.js configuration file when using the experimental\n[<code>--experimental-config-file</code>][] flag. Permission options must be placed inside\nthe <code>permission</code> top-level object.</p>\n<p>Example <code>node.config.json</code>:</p>\n<pre><code class=\"language-json\">{\n  \"permission\": {\n    \"allow-fs-read\": [\"./foo\"],\n    \"allow-fs-write\": [\"./bar\"],\n    \"allow-child-process\": true,\n    \"allow-worker\": true,\n    \"allow-net\": true,\n    \"allow-addons\": false,\n    \"allow-ffi\": false,\n    \"allow-openssl-store\": false\n  }\n}\n</code></pre>\n<p>When the <code>permission</code> namespace is present in the configuration file, Node.js\nautomatically enables the <code>--permission</code> flag. Run with:</p>\n<pre><code class=\"language-console\">$ node --experimental-default-config-file app.js\n</code></pre>",
                  "displayName": "Configuration file support"
                },
                {
                  "textRaw": "Using the Permission Model with `npx`",
                  "name": "using_the_permission_model_with_`npx`",
                  "type": "module",
                  "desc": "<p>If you're using <a href=\"https://docs.npmjs.com/cli/commands/npx\"><code>npx</code></a> to execute a Node.js script, you can enable the\nPermission Model by passing the <code>--node-options</code> flag. For example:</p>\n<pre><code class=\"language-bash\">npx --node-options=\"--permission\" package-name\n</code></pre>\n<p>This sets the <code>NODE_OPTIONS</code> environment variable for all Node.js processes\nspawned by <a href=\"https://docs.npmjs.com/cli/commands/npx\"><code>npx</code></a>, without affecting the <code>npx</code> process itself.</p>\n<p><strong>FileSystemRead Error with <code>npx</code></strong></p>\n<p>The above command will likely throw a <code>FileSystemRead</code> invalid access error\nbecause Node.js requires file system read access to locate and execute the\npackage. To avoid this:</p>\n<ol>\n<li>\n<p><strong>Using a Globally Installed Package</strong>\nGrant read access to the global <code>node_modules</code> directory by running:</p>\n<pre><code class=\"language-bash\">npx --node-options=\"--permission --allow-fs-read=$(npm prefix -g)\" package-name\n</code></pre>\n</li>\n<li>\n<p><strong>Using the <code>npx</code> Cache</strong>\nIf you are installing the package temporarily or relying on the <code>npx</code> cache,\ngrant read access to the npm cache directory:</p>\n<pre><code class=\"language-bash\">npx --node-options=\"--permission --allow-fs-read=$(npm config get cache)\" package-name\n</code></pre>\n</li>\n</ol>\n<p>Any arguments you would normally pass to <code>node</code> (e.g., <code>--allow-*</code> flags) can\nalso be passed through the <code>--node-options</code> flag. This flexibility makes it\neasy to configure permissions as needed when using <code>npx</code>.</p>",
                  "displayName": "Using the Permission Model with `npx`"
                },
                {
                  "textRaw": "Permission Model constraints",
                  "name": "permission_model_constraints",
                  "type": "module",
                  "desc": "<p>There are constraints you need to know before using this system:</p>\n<ul>\n<li>The model does not inherit to a worker thread.</li>\n<li>When using the Permission Model the following features will be restricted:\n<ul>\n<li>Native modules</li>\n<li>Network</li>\n<li>Child process</li>\n<li>Worker Threads</li>\n<li>Inspector protocol</li>\n<li>File system access</li>\n<li>WASI</li>\n<li>FFI</li>\n<li>OpenSSL STORE loaders</li>\n</ul>\n</li>\n<li>The Permission Model is initialized after the Node.js environment is set up.\nHowever, certain flags such as <code>--env-file</code> or <code>--openssl-config</code> are designed\nto read files before environment initialization. As a result, such flags are\nnot subject to the rules of the Permission Model. The same applies for V8\nflags that can be set via runtime through <code>v8.setFlagsFromString</code>.</li>\n<li>OpenSSL engines cannot be requested at runtime when the Permission\nModel is enabled, affecting the built-in crypto, https, and tls modules.</li>\n<li>Run-Time Loadable Extensions cannot be loaded when the Permission Model is\nenabled, affecting the sqlite module.</li>\n<li>Using existing file descriptors via the <code>node:fs</code> module bypasses the\nPermission Model.</li>\n</ul>",
                  "displayName": "Permission Model constraints"
                },
                {
                  "textRaw": "process._debugProcess() and cross-process Inspector activation",
                  "name": "process._debugprocess()_and_cross-process_inspector_activation",
                  "type": "module",
                  "desc": "<p>The <code>kInspector</code> permission scope restricts the current process from opening its own V8 Inspector. However,\nprocess._debugProcess(pid) — which sends an OS-level signal (SIGUSR1 on POSIX, a remote thread on Windows)\nto an external process — is not gated by the <code>kInspector</code> scope or any other Permission Model scope.</p>\n<p>A sandboxed process running under --permission with no additional grants can call process._debugProcess(pid)\nto force another Node.js process to open its V8 Inspector. The target process does not need to be running\nunder --permission for this to work — any Node.js process running on the same host under the same OS user\ncan be signaled.</p>\n<p>This is consistent with the Node.js threat model: Node.js trusts the OS environment in which it runs.\nCross-process signaling is an operating-system-level capability; restricting it is the responsibility of\nthe operator (for example, using OS-level process isolation, separate OS users per process, or\nseccomp/AppArmor profiles on Linux).</p>\n<p>Developers relying on --permission to sandbox untrusted code should be aware that:</p>\n<ul>\n<li>process._debugProcess() is callable from any sandboxed process with no grants.</li>\n<li>If a target Node.js process is running on the same host under the same OS user, it can be forced to\nopen its Inspector via this API.</li>\n<li>To prevent this, run sandboxed and target processes under different OS users, or use OS-level isolation\nmechanisms outside of Node.js.</li>\n</ul>",
                  "displayName": "process._debugProcess() and cross-process Inspector activation"
                },
                {
                  "textRaw": "Limitations and Known Issues",
                  "name": "limitations_and_known_issues",
                  "type": "module",
                  "desc": "<ul>\n<li>Symbolic links will be followed even to locations outside of the set of paths\nthat access has been granted to. Relative symbolic links may allow access to\narbitrary files and directories. When starting applications with the\npermission model enabled, you must ensure that no paths to which access has\nbeen granted contain relative symbolic links.</li>\n</ul>",
                  "displayName": "Limitations and Known Issues"
                }
              ],
              "displayName": "Permission Model"
            }
          ],
          "displayName": "Process-based permissions"
        }
      ],
      "displayName": "Permissions"
    }
  ]
}