my-durable 0.0.68 → 0.0.69

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.
@@ -72,7 +72,18 @@ const emptyAgentState = (): AgentViewState => ({
72
72
  ready: false,
73
73
  });
74
74
 
75
+ /** Wire-controlled path elements that must never be walked or written:
76
+ * reading node["__proto__"] returns Object.prototype and the walk descends
77
+ * onto it silently, and "constructor" reaches the inherited Function — both
78
+ * end in process-wide prototype pollution from a hostile/corrupt delta
79
+ * (R15: run-1 NV v3-13). A delta carrying any of these is dropped whole
80
+ * rather than partially applied. */
81
+ const FORBIDDEN_PATH_KEYS = new Set(["__proto__", "constructor", "prototype"]);
82
+
75
83
  function setPath(target: Record<string | number, unknown>, path: readonly (string | number)[], delta: string) {
84
+ for (const key of path) {
85
+ if (typeof key === "string" && FORBIDDEN_PATH_KEYS.has(key)) return;
86
+ }
76
87
  let node = target;
77
88
  for (let i = 0; i < path.length - 1; i++) {
78
89
  const key = path[i];
package/bin/update.mjs CHANGED
@@ -12,6 +12,8 @@
12
12
  // Everything here is dependency-injected so it can be tested without npm, a
13
13
  // network, or a real daemon.
14
14
  import { spawn } from "node:child_process";
15
+ import { dirname, isAbsolute, join } from "node:path";
16
+ import { accessSync, constants } from "node:fs";
15
17
 
16
18
  /** Numeric triple + prerelease flag. A prerelease counts as older. */
17
19
  export function rank(version) {
@@ -152,15 +154,52 @@ export async function runUpdate(deps) {
152
154
 
153
155
  // ------------------------------------------------------------------ real deps
154
156
 
155
- /** Spawn npm correctly on every platform (npm is npm.cmd on Windows). */
156
- export function spawnNpm(args) {
157
+ function readableFile(p) {
158
+ try {
159
+ accessSync(p, constants.R_OK);
160
+ return true;
161
+ } catch {
162
+ return false;
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Resolve npm's cli script to an ABSOLUTE .js path (R15: run-1 NV v3-06).
168
+ * cmd.exe resolves a bare `npm.cmd` CURRENT-DIRECTORY-FIRST unless
169
+ * NoDefaultCurrentDirectoryInExePath is set, so a planted npm.cmd in the
170
+ * operator's invoking cwd would execute as the operator during self-update.
171
+ * Spawning node + npm-cli.js with shell:false removes cmd.exe — and therefore
172
+ * any cwd/PATH .cmd search — from the resolution path entirely. Returns null
173
+ * when no known layout matches; the caller then uses the hardened fallback.
174
+ */
175
+ export function resolveNpmCli(nodePath = process.execPath, env = process.env) {
176
+ const binDir = dirname(nodePath);
177
+ const rootDir = dirname(binDir);
178
+ const candidates = [
179
+ env.npm_execpath, // npm itself exports its cli path
180
+ join(binDir, "node_modules", "npm", "bin", "npm-cli.js"), // nodejs.org / nvm4windows layout
181
+ join(rootDir, "lib", "node_modules", "npm", "bin", "npm-cli.js"), // POSIX nvm/prefix layout
182
+ ];
183
+ for (const c of candidates) {
184
+ if (typeof c === "string" && isAbsolute(c) && c.endsWith(".js") && readableFile(c)) return c;
185
+ }
186
+ return null;
187
+ }
188
+
189
+ /** Hardened fallback env for the (unusual) no-npm-cli.js layouts: suppress
190
+ * cmd.exe's current-directory-first .cmd resolution in the child. */
191
+ export function windowsFallbackEnv(env = process.env) {
192
+ return { ...env, NoDefaultCurrentDirectoryInExePath: "1" };
193
+ }
194
+
195
+ /** The fallback child cwd is pinned to a trusted directory — never the
196
+ * operator's invoking cwd, where a planted npm.cmd could live. */
197
+ export function windowsFallbackCwd(env = process.env, nodePath = process.execPath) {
198
+ return env.SystemRoot || dirname(nodePath);
199
+ }
200
+
201
+ function settle(child) {
157
202
  return new Promise((resolve) => {
158
- const onWindows = process.platform === "win32";
159
- const child = spawn(onWindows ? "npm.cmd" : "npm", args, {
160
- stdio: ["ignore", "pipe", "pipe"],
161
- shell: onWindows,
162
- windowsHide: true,
163
- });
164
203
  let output = "";
165
204
  child.stdout?.on("data", (x) => {
166
205
  output += x;
@@ -175,6 +214,29 @@ export function spawnNpm(args) {
175
214
  });
176
215
  }
177
216
 
217
+ /** Spawn npm correctly on every platform (npm is npm.cmd on Windows).
218
+ * win32 NEVER spawns a bare `npm.cmd` through a cwd-searching shell when an
219
+ * absolute npm-cli.js can be resolved (R15). */
220
+ export function spawnNpm(args) {
221
+ const onWindows = process.platform === "win32";
222
+ if (!onWindows) {
223
+ return settle(spawn("npm", args, { stdio: ["ignore", "pipe", "pipe"], windowsHide: true }));
224
+ }
225
+ const cli = resolveNpmCli();
226
+ if (cli) {
227
+ return settle(spawn(process.execPath, [cli, ...args], { stdio: ["ignore", "pipe", "pipe"], windowsHide: true }));
228
+ }
229
+ return settle(
230
+ spawn("npm.cmd", args, {
231
+ stdio: ["ignore", "pipe", "pipe"],
232
+ shell: true,
233
+ windowsHide: true,
234
+ env: windowsFallbackEnv(),
235
+ cwd: windowsFallbackCwd(),
236
+ }),
237
+ );
238
+ }
239
+
178
240
  export async function fetchLatestVersion() {
179
241
  const res = await fetch("https://registry.npmjs.org/my-durable/latest", {
180
242
  headers: { accept: "application/json" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-durable",
3
- "version": "0.0.68",
3
+ "version": "0.0.69",
4
4
  "description": "Durable Pi — the durable agent network: hub web UI, device backend daemon, TUI admin and the shared SDK, packaged as one runnable monorepo install",
5
5
  "license": "MIT",
6
6
  "repository": {