Skip to content

Commit

Permalink
fix: Add sys permission kinds for node compat (denoland#24242)
Browse files Browse the repository at this point in the history
Fixes denoland#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 <[email protected]>
  • Loading branch information
adamgreg and bartlomieju authored Jul 10, 2024
1 parent 9a0d59d commit 82f9216
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ext/node/ops/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
{
{
let permissions = state.borrow_mut::<P>();
permissions.check_sys("userInfo", "node:os.userInfo()")?;
permissions.check_sys("username", "node:os.userInfo()")?;
}

Ok(deno_whoami::username())
Expand All @@ -63,7 +63,7 @@ where
{
{
let permissions = state.borrow_mut::<P>();
permissions.check_sys("geteuid", "node:os.geteuid()")?;
permissions.check_sys("uid", "node:os.geteuid()")?;
}

#[cfg(windows)]
Expand Down
5 changes: 2 additions & 3 deletions runtime/permissions/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}\""))),
}
}
Expand Down

0 comments on commit 82f9216

Please sign in to comment.