Skip to content

Commit 044bed8

Browse files
authored
fix(ext/node): require env permission for process.loadEnvFile (#34350)
process.loadEnvFile() checked only read permission for the dotenv file and then wrote each parsed key into the process environment via env::set_var, making it the only env-mutation API in the runtime that didn't go through the --allow-env gate. Add a check_env_all() call upfront so the call fails before any mutation when env access is denied, keeping loadEnvFile consistent with Deno.env.set and friends. The check is all-or-nothing rather than per-key — partial-grant shapes like --allow-env=FOO no longer satisfy loadEnvFile even when FOO is the only key in the file. The simpler behavior matches how dotenv files are conventionally used (you either want the whole file applied or you don't) and avoids the partial-mutation edge case where one denied key would leave the env half-populated.
1 parent 12a12f2 commit 044bed8

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

ext/node/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ fn op_node_load_env_file(
113113
#[string] path: &str,
114114
) -> Result<(), DotEnvLoadErr> {
115115
let fs = state.borrow::<deno_fs::FileSystemRc>().clone();
116-
let path = state
117-
.borrow::<PermissionsContainer>()
116+
let permissions = state.borrow::<PermissionsContainer>().clone();
117+
permissions
118+
.check_env_all()
119+
.map_err(DotEnvLoadErr::Permission)?;
120+
let path = permissions
118121
.check_open(
119122
Cow::Borrowed(Path::new(path)),
120123
OpenAccessKind::ReadNoFollow,

tests/specs/run/process_env_load/__test__.jsonc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
"env_load_file": {
44
"args": "run --allow-env --allow-read env_file.ts",
55
"output": "env_file.out"
6+
},
7+
"env_load_file_without_env_permission": {
8+
"args": "run --allow-read --no-prompt env_file.ts",
9+
"output": "env_file_no_env_perm.out",
10+
"exitCode": 1
11+
},
12+
"env_load_file_with_partial_env_permission": {
13+
"args": "run --allow-read --allow-env=FOO --no-prompt env_file.ts",
14+
"output": "env_file_no_env_perm.out",
15+
"exitCode": 1
616
}
717
}
818
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[WILDCARD]NotCapable: Requires env access, run again with the --allow-env flag[WILDCARD]

0 commit comments

Comments
 (0)