From 82f9216610ec9cc32697ca77cb95da4b229117d4 Mon Sep 17 00:00:00 2001 From: Adam Gregory Date: Wed, 10 Jul 2024 14:15:43 +0100 Subject: [PATCH] fix: Add sys permission kinds for node compat (#24242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #24241 * Support "statfs", "username", "getPriority" and "setPriority" kinds for `--allow-sys`. * Check individual permissions in `node:os.userInfo()` instead of a single "userInfo" permission. * Check for "uid" permission in `node:process.geteuid()` instead of "geteuid". * Add missing "homedir" to `SysPermissionDescriptor.kind` union Co-authored-by: Bartek IwaƄczuk --- cli/tsc/dts/lib.deno.ns.d.ts | 7 ++++++- ext/node/ops/os/mod.rs | 4 ++-- runtime/permissions/lib.rs | 5 ++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index c3a80e6db2..ae8d4acf8d 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -4969,7 +4969,12 @@ declare namespace Deno { | "osUptime" | "uid" | "gid" - | "cpus"; + | "username" + | "cpus" + | "homedir" + | "statfs" + | "getPriority" + | "setPriority"; } /** The permission descriptor for the `allow-ffi` and `deny-ffi` permissions, which controls diff --git a/ext/node/ops/os/mod.rs b/ext/node/ops/os/mod.rs index b7374dc322..ca91895f22 100644 --- a/ext/node/ops/os/mod.rs +++ b/ext/node/ops/os/mod.rs @@ -50,7 +50,7 @@ where { { let permissions = state.borrow_mut::

(); - permissions.check_sys("userInfo", "node:os.userInfo()")?; + permissions.check_sys("username", "node:os.userInfo()")?; } Ok(deno_whoami::username()) @@ -63,7 +63,7 @@ where { { let permissions = state.borrow_mut::

(); - permissions.check_sys("geteuid", "node:os.geteuid()")?; + permissions.check_sys("uid", "node:os.geteuid()")?; } #[cfg(windows)] diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index a2245316b7..0d9d37a362 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -997,9 +997,8 @@ impl Descriptor for SysDescriptor { pub fn parse_sys_kind(kind: &str) -> Result<&str, AnyError> { match kind { "hostname" | "osRelease" | "osUptime" | "loadavg" | "networkInterfaces" - | "systemMemoryInfo" | "uid" | "gid" | "cpus" | "homedir" | "getegid" => { - Ok(kind) - } + | "systemMemoryInfo" | "uid" | "gid" | "cpus" | "homedir" | "getegid" + | "username" | "statfs" | "getPriority" | "setPriority" => Ok(kind), _ => Err(type_error(format!("unknown system info kind \"{kind}\""))), } }