@whyvix/remote 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyvix/remote",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [
@@ -1,13 +1,10 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import path from "node:path";
3
3
 
4
- const DEFAULT_EXECUTABLES = Object.freeze({
5
- node: process.execPath,
6
- npm: "npm",
7
- npx: "npx",
8
- php: "php",
9
- composer: "composer"
10
- });
4
+ const DEFAULT_EXECUTABLES = null;
5
+ const BLOCKED_SHELL_EXECUTABLES = new Set([
6
+ "cmd", "command", "powershell", "pwsh", "sh", "bash", "dash", "zsh", "fish", "wsl"
7
+ ]);
11
8
 
12
9
  function fail(code, message) { throw Object.assign(new Error(message), { code }); }
13
10
 
@@ -20,19 +17,25 @@ function appendBounded(state, key, chunk, maxBytes) {
20
17
  }
21
18
 
22
19
  function normalizeRegistry(value) {
23
- if (Array.isArray(value)) return new Map(value.map((x) => [String(x).toLowerCase(), String(x)]));
24
- return new Map(Object.entries(value || {}).map(([name, command]) => [String(name).toLowerCase(), String(command)]));
20
+ if (value == null) return null;
21
+ if (Array.isArray(value)) return new Map(value.map((x) => [String(x).toLowerCase().replace(/\.exe$/, ""), String(x)]));
22
+ return new Map(Object.entries(value || {}).map(([name, command]) => [String(name).toLowerCase().replace(/\.exe$/, ""), String(command)]));
25
23
  }
26
24
 
27
25
  function resolveExecutable(registry, requested) {
28
26
  const raw = String(requested || "").trim();
29
27
  if (!raw) fail("INVALID_ARGUMENT", "command is required");
28
+ if (raw.includes("/") || raw.includes("\\") || raw.includes(":") || raw === "." || raw === "..") {
29
+ fail("LOCAL_EXEC_NOT_ALLOWED", "Executable must be a bare command name resolved by the operating system");
30
+ }
31
+ if (!/^[A-Za-z0-9][A-Za-z0-9._+-]*$/.test(raw)) fail("LOCAL_EXEC_NOT_ALLOWED", "Executable name is invalid");
30
32
  const key = raw.toLowerCase().replace(/\.exe$/, "");
31
- if (registry.has(key) && !raw.includes("/") && !raw.includes("\\") && !raw.includes(":")) return { name: key, command: registry.get(key) };
32
- for (const [name, command] of registry) {
33
- if (raw.toLowerCase() === command.toLowerCase()) return { name, command };
33
+ if (BLOCKED_SHELL_EXECUTABLES.has(key)) fail("LOCAL_EXEC_NOT_ALLOWED", "Shell executables are not allowed");
34
+ if (registry) {
35
+ if (registry.has(key)) return { name: key, command: registry.get(key) };
36
+ fail("LOCAL_EXEC_NOT_ALLOWED", "Local executable is not allowed by configured policy");
34
37
  }
35
- fail("LOCAL_EXEC_NOT_ALLOWED", "Local executable is not allowed");
38
+ return { name: key, command: raw };
36
39
  }
37
40
 
38
41
  export class ProcessManager {