@@ -191,6 +191,45 @@ This behavior also applies to `child_process.spawn()`, but in that case, the
191191flags are propagated via the ` NODE_OPTIONS ` environment variable rather than
192192directly through the process arguments.
193193
194+ ### ` --allow-env `
195+
196+ > Stability: 1.1 - Active development
197+
198+ When using the [ Permission Model] [ ] , access to environment variables is
199+ restricted by default unless the user explicitly passes the ` --allow-env `
200+ flag when starting Node.js.
201+
202+ * Reading a restricted variable (` process.env.HOME ` ) silently returns
203+ ` undefined ` .
204+ * Writing (` process.env.FOO = 'bar' ` ) or deleting (` delete process.env.FOO ` )
205+ a restricted variable throws ` ERR_ACCESS_DENIED ` .
206+
207+ The valid arguments for the ` --allow-env ` flag are:
208+
209+ * ` * ` - To allow access to all environment variables.
210+ * Specific environment variable names can be allowed using a comma-separated
211+ list. Example: ` --allow-env=HOME,PATH,NODE_ENV `
212+
213+ Example:
214+
215+ ``` js
216+ console .log (process .env .HOME ); // undefined (silently denied)
217+ process .env .FOO = ' bar' ; // ERR_ACCESS_DENIED (throws)
218+ ```
219+
220+ ``` console
221+ $ node --permission --allow-fs-read=* index.js
222+ node:internal/process/per_thread:12
223+ throw new ERR_ACCESS_DENIED('EnvVar', name);
224+ ^
225+
226+ Error: Access to this API has been restricted
227+ at node:internal/main/run_main_module:17:47 {
228+ code: 'ERR_ACCESS_DENIED',
229+ permission: 'EnvVar'
230+ }
231+ ```
232+
194233### ` --allow-ffi `
195234
196235<!-- YAML
@@ -2224,6 +2263,7 @@ following permissions are restricted:
22242263* Worker Threads - manageable through [ ` --allow-worker ` ] [ ] flag
22252264* WASI - manageable through [ ` --allow-wasi ` ] [ ] flag
22262265* Addons - manageable through [ ` --allow-addons ` ] [ ] flag
2266+ * Environment Variables - manageable through [ ` --allow-env ` ] [ ] flag
22272267* FFI - manageable through [ ` --allow-ffi ` ] ( #--allow-ffi ) flag
22282268
22292269### ` --permission-audit `
@@ -3671,6 +3711,7 @@ one is included in the list below.
36713711
36723712* ` --allow-addons `
36733713* ` --allow-child-process `
3714+ * ` --allow-env `
36743715* ` --allow-ffi `
36753716* ` --allow-fs-read `
36763717* ` --allow-fs-write `
@@ -4309,6 +4350,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
43094350[ `"type"` ] : packages.md#type
43104351[ `--allow-addons` ] : #--allow-addons
43114352[ `--allow-child-process` ] : #--allow-child-process
4353+ [ `--allow-env` ] : #--allow-env
43124354[ `--allow-fs-read` ] : #--allow-fs-read
43134355[ `--allow-fs-write` ] : #--allow-fs-write
43144356[ `--allow-net` ] : #--allow-net
0 commit comments