summaryrefslogtreecommitdiff
path: root/tests/specs/run/allow_run_allowlist_resolution
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-09-04 14:51:24 +0200
committerGitHub <noreply@github.com>2024-09-04 14:51:24 +0200
commit74fc66da110ec20d12751e7a0922cea300314399 (patch)
treeb0b057b7539b506b8db39287cd799e7c9cbd526f /tests/specs/run/allow_run_allowlist_resolution
parent334c842392e2587b8ca1d7cc7cc7d9231fc15286 (diff)
fix: lock down allow-run permissions more (#25370)
`--allow-run` even with an allow list has essentially been `--allow-all`... this locks it down more. 1. Resolves allow list for `--allow-run=` on startup to an absolute path, then uses these paths when evaluating if a command can execute. Also, adds these paths to `--deny-write` 1. Resolves the environment (cwd and env vars) before evaluating permissions and before executing a command. Then uses this environment to evaluate the permissions and then evaluate the command.
Diffstat (limited to 'tests/specs/run/allow_run_allowlist_resolution')
-rw-r--r--tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc8
-rw-r--r--tests/specs/run/allow_run_allowlist_resolution/main.out15
-rw-r--r--tests/specs/run/allow_run_allowlist_resolution/main.ts67
3 files changed, 90 insertions, 0 deletions
diff --git a/tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc b/tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc
new file mode 100644
index 000000000..173e13027
--- /dev/null
+++ b/tests/specs/run/allow_run_allowlist_resolution/__test__.jsonc
@@ -0,0 +1,8 @@
+{
+ "args": "run --quiet -A main.ts",
+ "output": "main.out",
+ "envs": {
+ "DYLD_FALLBACK_LIBRARY_PATH": "",
+ "LD_LIBRARY_PATH": ""
+ }
+}
diff --git a/tests/specs/run/allow_run_allowlist_resolution/main.out b/tests/specs/run/allow_run_allowlist_resolution/main.out
new file mode 100644
index 000000000..f61f9b550
--- /dev/null
+++ b/tests/specs/run/allow_run_allowlist_resolution/main.out
@@ -0,0 +1,15 @@
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "prompt", onchange: null }
+PermissionStatus { state: "granted", onchange: null }
+---
+Info Failed to resolve 'deno' for allow-run: cannot find binary path
+PermissionStatus { state: "prompt", onchange: null }
+PermissionStatus { state: "prompt", onchange: null }
+PermissionStatus { state: "prompt", onchange: null }
+PermissionStatus { state: "prompt", onchange: null }
+---
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "granted", onchange: null }
+PermissionStatus { state: "prompt", onchange: null }
+PermissionStatus { state: "granted", onchange: null }
diff --git a/tests/specs/run/allow_run_allowlist_resolution/main.ts b/tests/specs/run/allow_run_allowlist_resolution/main.ts
new file mode 100644
index 000000000..bf33d8cbe
--- /dev/null
+++ b/tests/specs/run/allow_run_allowlist_resolution/main.ts
@@ -0,0 +1,67 @@
+// Testing the following (but with `deno` instead of `echo`):
+// | `deno run --allow-run=echo` | `which path == "/usr/bin/echo"` at startup | `which path != "/usr/bin/echo"` at startup |
+// |-------------------------------------|--------------------------------------------|--------------------------------------------|
+// | **`Deno.Command("echo")`** | ✅ | ✅ |
+// | **`Deno.Command("/usr/bin/echo")`** | ✅ | ❌ |
+
+// | `deno run --allow-run=/usr/bin/echo | `which path == "/usr/bin/echo"` at runtime | `which path != "/usr/bin/echo"` at runtime |
+// |-------------------------------------|--------------------------------------------|--------------------------------------------|
+// | **`Deno.Command("echo")`** | ✅ | ❌ |
+// | **`Deno.Command("/usr/bin/echo")`** | ✅ | ✅ |
+
+const execPath = Deno.execPath();
+const execPathParent = execPath.replace(/[/\\][^/\\]+$/, "");
+
+const testUrl = `data:application/typescript;base64,${
+ btoa(`
+ console.error(await Deno.permissions.query({ name: "run", command: "deno" }));
+ console.error(await Deno.permissions.query({ name: "run", command: "${
+ execPath.replaceAll("\\", "\\\\")
+ }" }));
+ Deno.env.set("PATH", "");
+ console.error(await Deno.permissions.query({ name: "run", command: "deno" }));
+ console.error(await Deno.permissions.query({ name: "run", command: "${
+ execPath.replaceAll("\\", "\\\\")
+ }" }));
+`)
+}`;
+
+const process1 = await new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "--allow-env",
+ "--allow-run=deno",
+ testUrl,
+ ],
+ stdout: "inherit",
+ stderr: "inherit",
+ env: { "PATH": execPathParent },
+}).output();
+
+console.error("---");
+
+await new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "--allow-env",
+ "--allow-run=deno",
+ testUrl,
+ ],
+ stderr: "inherit",
+ stdout: "inherit",
+ env: { "PATH": "" },
+}).output();
+
+console.error("---");
+
+await new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "--allow-env",
+ `--allow-run=${execPath}`,
+ testUrl,
+ ],
+ stderr: "inherit",
+ stdout: "inherit",
+ env: { "PATH": execPathParent },
+}).output();