@node9/policy-engine 2.51.0 → 2.53.0

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/dist/index.js CHANGED
@@ -157,6 +157,7 @@ __export(src_exports, {
157
157
  gitInvocations: () => gitInvocations,
158
158
  gitRepoPath: () => gitRepoPath,
159
159
  hashDestination: () => hashDestination,
160
+ holdsSendsWithoutDaemon: () => holdsSendsWithoutDaemon,
160
161
  hostMatches: () => hostMatches,
161
162
  incompleteFileVerdict: () => incompleteFileVerdict,
162
163
  inlineExecDescription: () => inlineExecDescription,
@@ -2384,15 +2385,15 @@ function ssrfExemptMatches(entries, normalized) {
2384
2385
  continue;
2385
2386
  }
2386
2387
  if (!target) continue;
2387
- const base2 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2388
+ const base3 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2388
2389
  const prefixText = entry.slice(slash + 1);
2389
2390
  const prefix = /^\d+$/.test(prefixText) ? Number(prefixText) : NaN;
2390
- if (!base2 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2391
+ if (!base3 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2391
2392
  // differ, so `0.0.0.0/0` does not release `::1`.
2392
- base2.length !== target.length || prefix > base2.length) {
2393
+ base3.length !== target.length || prefix > base3.length) {
2393
2394
  continue;
2394
2395
  }
2395
- if (base2.slice(0, prefix) === target.slice(0, prefix)) return true;
2396
+ if (base3.slice(0, prefix) === target.slice(0, prefix)) return true;
2396
2397
  }
2397
2398
  return false;
2398
2399
  }
@@ -2689,7 +2690,7 @@ var CHECK_TEXT = {
2689
2690
  advice: "Fixed at Review for now."
2690
2691
  },
2691
2692
  "commands.node9-disarm": {
2692
- plain: "The agent runs a node9 command that would switch off a protection: clear a session flag, trust an address, pause the gate, weaken a shield.",
2693
+ plain: "The agent switches node9 off or weakens it: stops or kills the daemon, stops its service, uninstalls node9, changes files in ~/.node9, clears a session flag, trusts an address, pauses the gate, weakens a shield.",
2693
2694
  example: "After reading a web page, the agent runs node9 session-exposure clear --all",
2694
2695
  advice: "Keep Review: these are your commands to run. Block if the agent should never touch node9."
2695
2696
  },
@@ -2742,6 +2743,10 @@ function reviewsEveryAgentFileWrite(mode) {
2742
2743
  const level = levelOf(mode);
2743
2744
  return level === "strict" || level === "block-all";
2744
2745
  }
2746
+ function holdsSendsWithoutDaemon(mode) {
2747
+ const level = levelOf(mode);
2748
+ return level === "strict" || level === "block-all";
2749
+ }
2745
2750
  function isBlockAll(mode) {
2746
2751
  return levelOf(mode) === "block-all";
2747
2752
  }
@@ -3111,7 +3116,7 @@ var PRODUCT_CHECKS = [
3111
3116
  group: "commands",
3112
3117
  owasp: "ASI10",
3113
3118
  title: "node9 disarmed from the shell",
3114
- catches: "a node9 command that clears a session flag, trusts a destination, pauses the gate or weakens a shield, run by the agent",
3119
+ catches: "the agent stopping or killing the node9 daemon, stopping its service, uninstalling node9, changing files in ~/.node9, or running a node9 command that clears a session flag, trusts a destination, pauses the gate or weakens a shield",
3115
3120
  values: ALL,
3116
3121
  defaultValue: "review",
3117
3122
  legacy: ["review-node9-disarm"]
@@ -5200,6 +5205,95 @@ function protectedLiteral(code, isProtected) {
5200
5205
  }
5201
5206
  return null;
5202
5207
  }
5208
+ var READ_CALL = {
5209
+ python: String.raw`(?:\b(?:io|codecs)\.)?\bopen|\b(?:dotenv_values|load_dotenv|get_key|read_file|loadtxt|read_csv)`,
5210
+ node: String.raw`\b(?:readFileSync|readFile|createReadStream|readTextFile(?:Sync)?|readFileStr|openSync|file)`,
5211
+ perl: String.raw`\b(?:open|sysopen|read_file|slurp)`,
5212
+ ruby: String.raw`\b(?:File|IO)\.(?:read|binread|readlines|foreach|open)|\bDotenv\.(?:load|parse|overload)`,
5213
+ php: String.raw`\b(?:file_get_contents|fopen|file|readfile|parse_ini_file|highlight_file|show_source)`
5214
+ };
5215
+ var ARG = String.raw`(?:(?:(?:my|our|local)\s+)?[\w.$]+(?:\s*\(\s*\))?|'[^'\n]{0,8}'|"[^"\n]{0,8}")\s*,\s*`;
5216
+ var WRAP = String.raw`(?:(?:new\s+)?[\w.$]+\s*\(\s*(?:${ARG}){0,3}){0,3}`;
5217
+ var STR_PREFIX = String.raw`[rRbBuUfF]{0,2}`;
5218
+ var WRITE_MODE_LITERAL = String.raw`['"](?=[rbtU+]*w|(?![^'"]*\+)[rbtU]*[ax])[rwaxbtU+]{1,4}['"]`;
5219
+ var WRITE_MODE = String.raw`\s*,\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL}`;
5220
+ var WRITE_MODE_AFTER = new RegExp(`^(?:\\s*\\)){0,3}${WRITE_MODE}`);
5221
+ var PERL_WRITE_BEFORE = /['"]\s*(?:\+?[>|]|>>)\s*['"]\s*,\s*$/;
5222
+ var readCallBefore = (language) => new RegExp(
5223
+ String.raw`(?:${READ_CALL[language]})(?![\w$])\s*\(?\s*(?:${ARG}){0,3}${WRAP}${STR_PREFIX}$`
5224
+ );
5225
+ var READ_BEFORE = {
5226
+ python: readCallBefore("python"),
5227
+ node: readCallBefore("node"),
5228
+ perl: readCallBefore("perl"),
5229
+ ruby: readCallBefore("ruby"),
5230
+ php: readCallBefore("php")
5231
+ };
5232
+ var READ_AFTER = {
5233
+ python: new RegExp(
5234
+ String.raw`^\s*\)\s*\.\s*(?:read_text|read_bytes|open)\s*\((?!\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL})`
5235
+ )
5236
+ };
5237
+ var ASSIGNED = new RegExp(String.raw`([$\w]+)\s*=\s*${WRAP}${STR_PREFIX}$`);
5238
+ var openedName = (language) => new RegExp(
5239
+ String.raw`(?:${READ_CALL[language]})(?![\w$])\s*\(?\s*(?:${ARG}){0,3}${WRAP}([$\w]+)(?!${WRITE_MODE})\s*[),]` + (language === "python" ? String.raw`|\bPath\s*\(\s*([$\w]+)\s*\)\s*\.\s*(?:read_text|read_bytes|open)\s*\(` : ""),
5240
+ "g"
5241
+ );
5242
+ var OPENED_NAME = {
5243
+ python: openedName("python"),
5244
+ node: openedName("node"),
5245
+ perl: openedName("perl"),
5246
+ ruby: openedName("ruby"),
5247
+ php: openedName("php")
5248
+ };
5249
+ var DOTENV = {
5250
+ node: {
5251
+ load: /\brequire\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)|\bimport\s*(?:[\w${}\s,*]+\s+from\s*)?['"`]dotenv(?:\/config)?['"`]|\bimport\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)/,
5252
+ values: /\.parsed\b|[(,]\s*(?:require\s*\(\s*['"`]dotenv['"`]\s*\)|dotenv)\s*\.\s*config\s*\(/,
5253
+ env: /\b(?:process|Deno|Bun)\s*\.\s*env\b/,
5254
+ literalPath: /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*['"`]/
5255
+ },
5256
+ python: {
5257
+ load: /\b(?:load_dotenv|dotenv_values|get_key)\s*\(/,
5258
+ values: /\b(?:dotenv_values|get_key)\s*\(/,
5259
+ env: /\b(?:environ|getenv)\b/,
5260
+ literalPath: /\b(?:load_dotenv|dotenv_values)\s*\(\s*(?:dotenv_path\s*=\s*)?[rRbBuU]?['"]/
5261
+ }
5262
+ };
5263
+ var DOTENV_PATH_OPTION = /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*$/;
5264
+ function inlineReadPaths(language, code, preload = {}) {
5265
+ const out = [];
5266
+ const before = READ_BEFORE[language];
5267
+ const after = READ_AFTER[language];
5268
+ const assigned = /* @__PURE__ */ new Map();
5269
+ for (const m of code.matchAll(STRING_LITERAL)) {
5270
+ const raw = m[2].trim();
5271
+ const value = raw.replace(/^[<+]\s*/, "");
5272
+ if (!value) continue;
5273
+ const head = code.slice(Math.max(0, m.index - 160), m.index);
5274
+ const tail = code.slice(m.index + m[0].length, m.index + m[0].length + 40);
5275
+ if (/^[>|]/.test(raw) || WRITE_MODE_AFTER.test(tail) || PERL_WRITE_BEFORE.test(head)) continue;
5276
+ if (before.test(head) || after?.test(tail) || language === "node" && DOTENV_PATH_OPTION.test(head)) {
5277
+ out.push(value);
5278
+ continue;
5279
+ }
5280
+ const name = ASSIGNED.exec(head)?.[1];
5281
+ if (name) assigned.set(name, [...assigned.get(name) ?? [], value]);
5282
+ }
5283
+ if (assigned.size > 0) {
5284
+ const opened = /* @__PURE__ */ new Set();
5285
+ for (const m of code.matchAll(OPENED_NAME[language])) opened.add(m[1] ?? m[2]);
5286
+ for (const [name, values] of assigned) if (opened.has(name)) out.push(...values);
5287
+ }
5288
+ if (language === "python" || language === "node") {
5289
+ const d = DOTENV[language];
5290
+ const readsEnv = d.env.test(code);
5291
+ const loads = /dotenv/.test(code) && d.load.test(code) && !d.literalPath.test(code);
5292
+ if ((loads || preload.dotenv) && (readsEnv || d.values.test(code))) out.push(".env");
5293
+ if (readsEnv) out.push(...preload.envFiles ?? []);
5294
+ }
5295
+ return out;
5296
+ }
5203
5297
  function amplifies(language, code) {
5204
5298
  const loop = language === "python" ? /\bwhile\s+(?:True|1)\s*:/ : language === "node" ? /\bwhile\s*\(\s*(?:true|1)\s*\)|\bfor\s*\(\s*;\s*;\s*\)|\bsetInterval\s*\(/ : /\bwhile\s*\(?\s*(?:1|true)\s*\)?|\bloop\s+do\b|\bfor\s*\(\s*;\s*;\s*\)/;
5205
5299
  const m = loop.exec(code);
@@ -6829,6 +6923,7 @@ function attachedCode(interp, flag) {
6829
6923
  if (letters === "ep" && /^[ep]*$/i.test(rest)) rest = "";
6830
6924
  return rest === "" ? null : rest;
6831
6925
  }
6926
+ var NODE_VALUE_FLAG = /^(-r|--require|--import|--loader|--experimental-loader|--env-file|--env-file-if-exists|--input-type|-C|--conditions)(?:=(.*))?$/;
6832
6927
  function inlineExecCall(stmt, pipeFed) {
6833
6928
  const cmd = stmt?.Cmd;
6834
6929
  if (!cmd || cmd.kind !== "CallExpr") return null;
@@ -6853,15 +6948,28 @@ function inlineExecCall(stmt, pipeFed) {
6853
6948
  const fromStdin = () => {
6854
6949
  if (stdinFed) {
6855
6950
  const { code, source } = stdinCodeOf(redirs);
6856
- return { interp, code: [code], source };
6951
+ return { interp, code: [code], source, preload };
6857
6952
  }
6858
6953
  return { interp, code: [null], source: "pipe" };
6859
6954
  };
6860
6955
  let positionals2 = 0;
6861
6956
  let selectedProgram = false;
6862
6957
  const codes = [];
6958
+ const preload = {};
6959
+ const nodeFamily = inlineLanguageOf(interp) === "node";
6863
6960
  for (let i = 0; i < args.length; i++) {
6864
6961
  const a = args[i];
6962
+ if (nodeFamily && !selectedProgram && codes.length === 0 && a != null) {
6963
+ const flag = NODE_VALUE_FLAG.exec(a);
6964
+ if (flag) {
6965
+ const value = flag[2] ?? args[++i];
6966
+ if (value != null) {
6967
+ if (/^--env-file/.test(flag[1])) (preload.envFiles ??= []).push(value);
6968
+ else if (/^dotenv\/config(?:\.js)?$/.test(value)) preload.dotenv = true;
6969
+ }
6970
+ continue;
6971
+ }
6972
+ }
6865
6973
  if (a == null) {
6866
6974
  if (codes.length > 0) break;
6867
6975
  positionals2++;
@@ -6898,7 +7006,12 @@ function inlineExecCall(stmt, pipeFed) {
6898
7006
  }
6899
7007
  }
6900
7008
  if (codes.length > 0) {
6901
- return { interp, code: codes, source: codes.includes(null) ? "variable" : void 0 };
7009
+ return {
7010
+ interp,
7011
+ code: codes,
7012
+ source: codes.includes(null) ? "variable" : void 0,
7013
+ preload
7014
+ };
6902
7015
  }
6903
7016
  if (positionals2 === 0 && (stdinFed || pipeFed)) {
6904
7017
  if (!/^(bash|sh|zsh)$/i.test(interp)) return fromStdin();
@@ -7917,7 +8030,7 @@ var FS_OP_CACHE_MAX = 5e3;
7917
8030
  var fsOpCache = /* @__PURE__ */ new Map();
7918
8031
  function analyzeFsOperation(command) {
7919
8032
  const normalized = normalizeCommandForPolicy(command);
7920
- if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command))
8033
+ if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized))
7921
8034
  return null;
7922
8035
  if (fsOpCache.has(command)) {
7923
8036
  const hit = fsOpCache.get(command) ?? null;
@@ -7925,7 +8038,8 @@ function analyzeFsOperation(command) {
7925
8038
  fsOpCache.set(command, hit);
7926
8039
  return hit;
7927
8040
  }
7928
- const computed = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8041
+ const direct = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8042
+ const computed = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
7929
8043
  if (fsOpCache.size >= FS_OP_CACHE_MAX) {
7930
8044
  const oldest = fsOpCache.keys().next().value;
7931
8045
  if (oldest !== void 0) fsOpCache.delete(oldest);
@@ -7935,8 +8049,8 @@ function analyzeFsOperation(command) {
7935
8049
  }
7936
8050
  var stripDotSlash = (p) => p.replace(/^\.\//, "");
7937
8051
  function isSensitiveCleanupName(p) {
7938
- const base2 = p.replace(/^.*[\\/]/, "");
7939
- return /^\.env(\.|$)/i.test(base2) || /(?:^|[\\/])\.(?:ssh|aws|gnupg|git)(?:[\\/]|$)/i.test(p) || /\.(?:pem|key|p12|pfx|crt)$/i.test(base2) || /^\.?(?:netrc|npmrc|pgpass|htpasswd)$/i.test(base2) || /^id_(?:rsa|dsa|ecdsa|ed25519)/i.test(base2) || /credential/i.test(p) || /secret/i.test(base2);
8052
+ const base3 = p.replace(/^.*[\\/]/, "");
8053
+ return /^\.env(\.|$)/i.test(base3) || /(?:^|[\\/])\.(?:ssh|aws|gnupg|git)(?:[\\/]|$)/i.test(p) || /\.(?:pem|key|p12|pfx|crt)$/i.test(base3) || /^\.?(?:netrc|npmrc|pgpass|htpasswd)$/i.test(base3) || /^id_(?:rsa|dsa|ecdsa|ed25519)/i.test(base3) || /credential/i.test(p) || /secret/i.test(base3);
7940
8054
  }
7941
8055
  function isWaivableCleanupTarget(p) {
7942
8056
  if (/^[/~]/.test(p) || /^\$/.test(p)) return false;
@@ -8735,6 +8849,26 @@ function structuralJailRead(command) {
8735
8849
  }
8736
8850
  return review;
8737
8851
  }
8852
+ var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
8853
+ var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
8854
+ function inlineCodeJailRead(command) {
8855
+ const calls = inlineExecCalls(command);
8856
+ if (calls === PARSE_FAIL) return null;
8857
+ let review = null;
8858
+ for (const call of calls) {
8859
+ const language = inlineLanguageOf(call.interp);
8860
+ if (language === null) continue;
8861
+ for (const code of call.code) {
8862
+ if (code === null) continue;
8863
+ for (const p of inlineReadPaths(language, code, call.preload)) {
8864
+ const hit = matchSensitivePath(p);
8865
+ if (hit?.verdict === "block") return hit;
8866
+ review ??= hit;
8867
+ }
8868
+ }
8869
+ }
8870
+ return review;
8871
+ }
8738
8872
  function baseWord(w) {
8739
8873
  return (w ?? "").split("/").pop()?.toLowerCase() ?? "";
8740
8874
  }
@@ -9327,6 +9461,21 @@ function hits(access, paths, directories, context) {
9327
9461
  }
9328
9462
  return false;
9329
9463
  }
9464
+ function hitsNode9Dir(access, dirs, context) {
9465
+ const home = context.homeDirs?.[0] ?? "~";
9466
+ if (access.glob) {
9467
+ const pattern = normalizeFilePath(access.glob, access.cwd ?? context.cwd, home);
9468
+ const magic = pattern.search(/[*?[{]/);
9469
+ const literal = magic < 0 ? pattern : pattern.slice(0, pattern.lastIndexOf("/", magic));
9470
+ return dirs.some((d) => within(literal, d));
9471
+ }
9472
+ const candidates = access.candidates ?? [
9473
+ normalizeFilePath(access.path, access.cwd ?? context.cwd, home)
9474
+ ];
9475
+ return candidates.some(
9476
+ (p) => dirs.some((d) => within(p, d)) || access.recursive === true && dirs.some((d) => within(d, p))
9477
+ );
9478
+ }
9330
9479
  var exempt = (p) => SYSTEM_DIRS_EXEMPT.some((d) => within(p, d));
9331
9480
  function hitsSystemDir(access, context, dirs = SYSTEM_DIRS) {
9332
9481
  const home = context.homeDirs?.[0] ?? "~";
@@ -9369,6 +9518,7 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
9369
9518
  const consider = (result) => {
9370
9519
  if (!best || RANK[result.decision] > RANK[best.decision]) best = result;
9371
9520
  };
9521
+ const node9Dirs = homes.map((home) => `${home.replace(/\/$/, "")}/.node9`);
9372
9522
  for (const access of accesses) {
9373
9523
  const mutation = access.operation !== "read";
9374
9524
  let kind;
@@ -9397,6 +9547,10 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
9397
9547
  "files.system-dirs",
9398
9548
  "review-root-home-read",
9399
9549
  "Reading the root account's home requires approval"
9550
+ ] : mutation && hitsNode9Dir(access, node9Dirs, context) ? [
9551
+ "commands.node9-disarm",
9552
+ "review-node9-disarm",
9553
+ "Changing node9's own files requires approval"
9400
9554
  ] : null;
9401
9555
  } catch {
9402
9556
  consider(incompleteFileVerdict(access.operation));
@@ -12401,9 +12555,9 @@ function validateBelgianNationalNumber(raw) {
12401
12555
  if (!/^\d{11}$/.test(d)) return false;
12402
12556
  const month = Number(d.slice(2, 4)) % 20;
12403
12557
  if (month !== 0 && !plausibleDate(String(month).padStart(2, "0"), d.slice(4, 6))) return false;
12404
- const base2 = Number(d.slice(0, 9));
12558
+ const base3 = Number(d.slice(0, 9));
12405
12559
  const check = Number(d.slice(9, 11));
12406
- return 97 - base2 % 97 === check || 97 - (2e9 + base2) % 97 === check;
12560
+ return 97 - base3 % 97 === check || 97 - (2e9 + base3) % 97 === check;
12407
12561
  }
12408
12562
  function validateCuit(raw) {
12409
12563
  const d = raw.replace(/-/g, "");
@@ -14011,9 +14165,9 @@ var GitWalk = class {
14011
14165
  const name = n.Name.Value;
14012
14166
  if (n.Append) {
14013
14167
  const prev = this.appended.has(name) ? this.appended.get(name) : resolveWordLiteral(n.Value) === null ? null : void 0;
14014
- const base2 = prev === void 0 ? recordedExpansion(name) : prev;
14168
+ const base3 = prev === void 0 ? recordedExpansion(name) : prev;
14015
14169
  const piece = resolveWordLiteral(n.Value);
14016
- this.appended.set(name, typeof base2 === "string" && piece !== null ? base2 + piece : null);
14170
+ this.appended.set(name, typeof base3 === "string" && piece !== null ? base3 + piece : null);
14017
14171
  this.treeTopVars.delete(name);
14018
14172
  return true;
14019
14173
  }
@@ -15045,9 +15199,9 @@ var INSTRUCTION_NAMES = /* @__PURE__ */ new Set([
15045
15199
  var SETTINGS_RE = /\/(?:\.claude\/settings(?:\.local)?\.json|\.gemini\/settings\.json|\.codex\/hooks\.json|\.cursor\/hooks\.json)$/i;
15046
15200
  function agentFileKind(p) {
15047
15201
  const lower2 = p.toLowerCase();
15048
- const base2 = lower2.slice(lower2.lastIndexOf("/") + 1);
15049
- if (INSTRUCTION_NAMES.has(base2)) return "instructions";
15050
- if (base2 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base2))
15202
+ const base3 = lower2.slice(lower2.lastIndexOf("/") + 1);
15203
+ if (INSTRUCTION_NAMES.has(base3)) return "instructions";
15204
+ if (base3 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base3))
15051
15205
  return "instructions";
15052
15206
  if (/\/\.cursor\/rules(?:\/|$)/.test(lower2)) return "instructions";
15053
15207
  if (/\/\.claude\/projects\/[^/]+\/memory(?:\/|$)/.test(lower2)) return "memory";
@@ -15217,7 +15371,7 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
15217
15371
  skills: "agent skill",
15218
15372
  settings: "agent settings"
15219
15373
  };
15220
- const base2 = `${kindLabel[kind]} written: ${access.path}`;
15374
+ const base3 = `${kindLabel[kind]} written: ${access.path}`;
15221
15375
  if (!signal && !every) {
15222
15376
  return {
15223
15377
  decision: "allow",
@@ -15227,14 +15381,14 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
15227
15381
  path: access.path,
15228
15382
  operation: access.operation,
15229
15383
  kind,
15230
- reason: base2,
15384
+ reason: base3,
15231
15385
  ruleDescription: "The AI writes to a file every later agent session loads as instructions.",
15232
- blockedByLabel: `Node9 Files: ${base2}`,
15386
+ blockedByLabel: `Node9 Files: ${base3}`,
15233
15387
  tier: 2
15234
15388
  };
15235
15389
  }
15236
15390
  const ruleName = signal === "content" ? "review-agent-file-content" : signal === "hooks" ? "review-agent-hooks-change" : "review-agent-file-write";
15237
- const reason = signal ? `${base2} (${detail})` : base2;
15391
+ const reason = signal ? `${base3} (${detail})` : base3;
15238
15392
  const description = signal === "content" ? "The AI writes an instruction into a file every later agent session loads: to hide something from you, to skip approvals or the guard, or to read or send a secret. It would persist past this session; confirm it is yours." : signal === "hooks" ? "The AI changes the hooks in the agent's settings. Hooks are how node9 and your other checks run before each tool call; a change here can disarm them." : "The AI writes to a file every later agent session loads as instructions (CLAUDE.md, AGENTS.md, memory, agents, commands). Confirm the change is yours.";
15239
15393
  return {
15240
15394
  decision: value === "log" ? "allow" : value,
@@ -17954,6 +18108,175 @@ function scanArgumentSecrets(args) {
17954
18108
  } : null;
17955
18109
  }
17956
18110
 
18111
+ // src/shell/node9-disarm.ts
18112
+ var RULE_NAME2 = "review-node9-disarm";
18113
+ var DESCRIPTION = "The AI wants to stop node9, remove it, or change its own files. These are your commands to run, not the agent's: with the daemon stopped the outside-content and taint checks are off.";
18114
+ var DAEMON_CMDLINES = [
18115
+ "node /usr/lib/node_modules/@node9/proxy/dist/cli.js daemon start",
18116
+ "node9 daemon start"
18117
+ ];
18118
+ var DAEMON_NAMES = ["node", "node9"];
18119
+ var KILLALL_NAMES = /* @__PURE__ */ new Set(["node", "node9", "node.exe", "node9.exe"]);
18120
+ var STOP_SYSTEMCTL = /* @__PURE__ */ new Set(["stop", "disable", "mask", "kill"]);
18121
+ var STOP_LAUNCHCTL = /* @__PURE__ */ new Set(["unload", "bootout", "remove", "stop", "kill", "disable"]);
18122
+ var PKILL_VALUE_FLAGS = /* @__PURE__ */ new Set([
18123
+ "-u",
18124
+ "-U",
18125
+ "-g",
18126
+ "-G",
18127
+ "-P",
18128
+ "-s",
18129
+ "-t",
18130
+ "-F",
18131
+ "--signal",
18132
+ "--euid",
18133
+ "--uid",
18134
+ "--pgroup",
18135
+ "--group",
18136
+ "--parent",
18137
+ "--session",
18138
+ "--terminal",
18139
+ "--pidfile",
18140
+ "--ns",
18141
+ "--nslist"
18142
+ ]);
18143
+ var NAME_PRESCREEN_RE = /node9|kill|systemctl|launchctl|daemon/i;
18144
+ function patternSelects(pattern, targets) {
18145
+ const pieces = pattern.toLowerCase().split(/[\\^$.*+?()[\]{}|]+/).filter(Boolean);
18146
+ if (pieces.length === 0) return false;
18147
+ return targets.some((t) => pieces.every((p) => t.includes(p)));
18148
+ }
18149
+ function sourceText(bytes, pos, end) {
18150
+ if (typeof pos !== "number" || typeof end !== "number" || pos < 0 || end < pos) return "";
18151
+ return new TextDecoder().decode(bytes.subarray(pos, end));
18152
+ }
18153
+ var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
18154
+ function nextOperand(words, from) {
18155
+ for (let i = from; i < words.length; i++) {
18156
+ const w = words[i];
18157
+ if (w !== null && w.startsWith("-")) continue;
18158
+ return i;
18159
+ }
18160
+ return -1;
18161
+ }
18162
+ function node9Command(words, h) {
18163
+ const head = base2(words[h]);
18164
+ if (head !== "node9" && head !== "node9.cmd" && words[h] !== "@node9/proxy") return null;
18165
+ const s = nextOperand(words, h + 1);
18166
+ const sub = s < 0 ? "" : (words[s] ?? "").toLowerCase();
18167
+ if (sub === "uninstall") return "node9 uninstall";
18168
+ if (sub !== "daemon") return null;
18169
+ const a = nextOperand(words, s + 1);
18170
+ const action = a < 0 ? "" : (words[a] ?? "").toLowerCase();
18171
+ return action === "stop" || action === "uninstall" ? `node9 daemon ${action}` : null;
18172
+ }
18173
+ var HOME_PID_FILE_RE = /(?:^|[\s"'(=`])(?:~|\$HOME|\$\{HOME\}|\/home\/[^/\s]+|\/Users\/[^/\s]+|\/root)\/\.node9\/daemon\.pid/;
18174
+ function killsDaemon(words, texts, h, daemonPid) {
18175
+ const head = base2(words[h]);
18176
+ const args = words.slice(h + 1);
18177
+ if (head === "kill") {
18178
+ for (let i = 0; i < args.length; i++) {
18179
+ const w = args[i];
18180
+ if (w === "-s" || w === "-n") {
18181
+ i++;
18182
+ continue;
18183
+ }
18184
+ if (w !== null && w.startsWith("-")) continue;
18185
+ if (w === null) {
18186
+ if (HOME_PID_FILE_RE.test(texts[h + 1 + i] ?? "")) return "kill of the pid in daemon.pid";
18187
+ continue;
18188
+ }
18189
+ if (daemonPid !== null && w === String(daemonPid)) return `kill ${w} (the node9 daemon)`;
18190
+ }
18191
+ return null;
18192
+ }
18193
+ if (head === "pkill") {
18194
+ let full = false;
18195
+ let pattern = null;
18196
+ for (let i = 0; i < args.length; i++) {
18197
+ const w = args[i];
18198
+ if (w === null) continue;
18199
+ if (PKILL_VALUE_FLAGS.has(w)) {
18200
+ i++;
18201
+ continue;
18202
+ }
18203
+ if (w === "--full") full = true;
18204
+ else if (/^-[a-zA-Z]+$/.test(w) && w.includes("f")) full = true;
18205
+ if (w.startsWith("-")) continue;
18206
+ pattern = w;
18207
+ }
18208
+ if (pattern === null) return null;
18209
+ return patternSelects(pattern, full ? DAEMON_CMDLINES : DAEMON_NAMES) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
18210
+ }
18211
+ if (head === "killall") {
18212
+ const regex = args.some((w) => w === "-r" || w === "--regexp");
18213
+ for (const w of args) {
18214
+ if (w === null || w.startsWith("-")) continue;
18215
+ if (regex ? patternSelects(w, DAEMON_NAMES) : KILLALL_NAMES.has(w.toLowerCase()))
18216
+ return `killall ${w}`;
18217
+ }
18218
+ return null;
18219
+ }
18220
+ if (head === "taskkill" || head === "taskkill.exe") {
18221
+ for (let i = 0; i < args.length - 1; i++) {
18222
+ const flag = (args[i] ?? "").toLowerCase();
18223
+ const value = (args[i + 1] ?? "").toLowerCase();
18224
+ if ((flag === "/im" || flag === "-im") && KILLALL_NAMES.has(value))
18225
+ return `taskkill /IM ${value}`;
18226
+ if ((flag === "/pid" || flag === "-pid") && daemonPid !== null && value === String(daemonPid))
18227
+ return `taskkill /PID ${value} (the node9 daemon)`;
18228
+ }
18229
+ }
18230
+ return null;
18231
+ }
18232
+ function stopsService(words, h) {
18233
+ const head = base2(words[h]);
18234
+ const args = words.slice(h + 1).map((w) => (w ?? "").toLowerCase());
18235
+ if (head === "systemctl") {
18236
+ const action = args.find((w) => STOP_SYSTEMCTL.has(w));
18237
+ if (action && args.some((w) => /^node9-daemon(\.service)?$/.test(w)))
18238
+ return `systemctl ${action} node9-daemon`;
18239
+ }
18240
+ if (head === "launchctl") {
18241
+ const action = args.find((w) => STOP_LAUNCHCTL.has(w));
18242
+ if (action && args.some((w) => w.includes("ai.node9.daemon")))
18243
+ return `launchctl ${action} ai.node9.daemon`;
18244
+ }
18245
+ return null;
18246
+ }
18247
+ function analyzeNode9Disarm(command, daemonPid = null, depth = 0) {
18248
+ if (depth > 3 || !NAME_PRESCREEN_RE.test(command.replace(/[\\'"]/g, ""))) return null;
18249
+ let shown = null;
18250
+ const bytes = new TextEncoder().encode(command);
18251
+ try {
18252
+ walkCommandScope(command, (node) => {
18253
+ if (shown !== null) return false;
18254
+ const n = node;
18255
+ if (!n || n.kind !== "CallExpr") return true;
18256
+ const words = (n.Args || []).map((a) => resolveWordLiteral(a));
18257
+ if (words.length === 0) return true;
18258
+ const texts = (n.Args || []).map((a) => sourceText(bytes, a.pos, a.end));
18259
+ const h = unwrapCommandHead(words);
18260
+ shown = node9Command(words, h) ?? killsDaemon(words, texts, h, daemonPid) ?? stopsService(words, h);
18261
+ if (shown === null) {
18262
+ const payload = literalShellPayload(words, base2(words[0]));
18263
+ if (payload) {
18264
+ const inner = analyzeNode9Disarm(payload, daemonPid, depth + 1);
18265
+ if (inner) shown = inner.reason.replace(/^node9 switched off by the agent: /, "");
18266
+ }
18267
+ }
18268
+ return true;
18269
+ });
18270
+ } catch {
18271
+ }
18272
+ if (shown === null) return null;
18273
+ return {
18274
+ ruleName: RULE_NAME2,
18275
+ reason: `node9 switched off by the agent: ${shown}`,
18276
+ description: DESCRIPTION
18277
+ };
18278
+ }
18279
+
17957
18280
  // src/policy/index.ts
17958
18281
  function catalogSettings(config) {
17959
18282
  return catalogSettingsFromConfig(config.settings, config.policy);
@@ -18062,7 +18385,15 @@ function egressPolicyVerdict(eg) {
18062
18385
  checkId: "network.unknown-host"
18063
18386
  };
18064
18387
  }
18388
+ var NOT_OVERRIDABLE_CHECKS = /* @__PURE__ */ new Set([
18389
+ "data.credential-files",
18390
+ "data.credential-files-other"
18391
+ ]);
18065
18392
  async function evaluatePolicy(config, toolName, args, context = {}, hostHooks = {}) {
18393
+ const v = await evaluatePolicyVerdict(config, toolName, args, context, hostHooks);
18394
+ return v.decision === "block" && v.checkId !== void 0 && NOT_OVERRIDABLE_CHECKS.has(v.checkId) ? { ...v, overridable: false } : v;
18395
+ }
18396
+ async function evaluatePolicyVerdict(config, toolName, args, context = {}, hostHooks = {}) {
18066
18397
  let protectedVerdict = null;
18067
18398
  const layers = inspectionLayers(config.policy);
18068
18399
  if (context.agent !== "Terminal") {
@@ -18120,7 +18451,7 @@ async function evaluatePolicy(config, toolName, args, context = {}, hostHooks =
18120
18451
  }
18121
18452
  async function evaluatePolicyCore(config, toolName, args, context = {}, hooks = {}) {
18122
18453
  const { agent, cwd, activeEnvironment } = context;
18123
- const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop } = hooks;
18454
+ const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop, daemonPid } = hooks;
18124
18455
  const settingsView = catalogSettings(config);
18125
18456
  const layers = inspectionLayers(config.policy);
18126
18457
  const cv = (id) => checkValue(settingsView, id);
@@ -18305,6 +18636,23 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
18305
18636
  else if (v && !pendingAstReview) pendingAstReview = v;
18306
18637
  }
18307
18638
  }
18639
+ if (cv("commands.node9-disarm") !== "off") {
18640
+ const finding = analyzeNode9Disarm(bashCommand, daemonPid?.() ?? null);
18641
+ if (finding) {
18642
+ const v = applyCheckValue(cv("commands.node9-disarm"), {
18643
+ decision: "review",
18644
+ blockedByLabel: `Node9 (AST): ${finding.ruleName}`,
18645
+ reason: finding.reason,
18646
+ tier: 2,
18647
+ ruleName: finding.ruleName,
18648
+ ruleDescription: finding.description,
18649
+ checkId: "commands.node9-disarm"
18650
+ });
18651
+ if (v?.logged) noteLogged(v);
18652
+ else if (v?.decision === "block") return v;
18653
+ else if (v && !pendingAstReview) pendingAstReview = v;
18654
+ }
18655
+ }
18308
18656
  }
18309
18657
  if (config.policy.smartRules.length > 0) {
18310
18658
  const rmCleanupWaiver = bashCommand !== null && isRmCreatedInCommandCleanup(bashCommand);
@@ -18896,8 +19244,8 @@ function hasRoutingNumber(text) {
18896
19244
  return false;
18897
19245
  }
18898
19246
  var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
18899
- function* validCardRuns(text, base2, exemptFractions = true) {
18900
- const re = new RegExp(base2.source, "g");
19247
+ function* validCardRuns(text, base3, exemptFractions = true) {
19248
+ const re = new RegExp(base3.source, "g");
18901
19249
  let m;
18902
19250
  while ((m = re.exec(text)) !== null) {
18903
19251
  const digits = m[0].replace(/\D/g, "");
@@ -18910,17 +19258,17 @@ function* validCardRuns(text, base2, exemptFractions = true) {
18910
19258
  }
18911
19259
  }
18912
19260
  function hasValidCard(text) {
18913
- for (const base2 of CARD_PATTERNS) {
18914
- if (!validCardRuns(text, base2).next().done) return true;
19261
+ for (const base3 of CARD_PATTERNS) {
19262
+ if (!validCardRuns(text, base3).next().done) return true;
18915
19263
  }
18916
19264
  return false;
18917
19265
  }
18918
19266
  function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
18919
19267
  let out = text;
18920
- for (const base2 of CARD_PATTERNS) {
19268
+ for (const base3 of CARD_PATTERNS) {
18921
19269
  let res = "";
18922
19270
  let last = 0;
18923
- for (const run of validCardRuns(out, base2, exemptFractions)) {
19271
+ for (const run of validCardRuns(out, base3, exemptFractions)) {
18924
19272
  res += out.slice(last, run.index) + replace(run.digits);
18925
19273
  last = run.index + run.length;
18926
19274
  }
@@ -19209,9 +19557,9 @@ function maskLeaf(value, key, depth) {
19209
19557
  const used = /* @__PURE__ */ new Set();
19210
19558
  return Object.fromEntries(
19211
19559
  Object.entries(value).map(([k, v]) => {
19212
- const base2 = maskPersonalData(k);
19213
- let name = base2;
19214
- for (let n = 2; used.has(name); n++) name = `${base2}#${n}`;
19560
+ const base3 = maskPersonalData(k);
19561
+ let name = base3;
19562
+ for (let n = 2; used.has(name); n++) name = `${base3}#${n}`;
19215
19563
  used.add(name);
19216
19564
  return [name, maskLeaf(v, k, depth + 1)];
19217
19565
  })
@@ -20259,8 +20607,8 @@ function matchCanaryArgs(args, values) {
20259
20607
 
20260
20608
  // src/scan/canonical.ts
20261
20609
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
20262
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v37";
20263
- var CANONICAL_EXTRACTOR_HASH = "2c9a0271d9c1dd57";
20610
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
20611
+ var CANONICAL_EXTRACTOR_HASH = "e07d9e5e537017ae";
20264
20612
  var DEDUPE_PREVIEW_LEN = 120;
20265
20613
  function extractCanonicalFindings(call, ctx) {
20266
20614
  const out = [];
@@ -20841,6 +21189,7 @@ var ENGINE_VERSION = "1.4.0";
20841
21189
  gitInvocations,
20842
21190
  gitRepoPath,
20843
21191
  hashDestination,
21192
+ holdsSendsWithoutDaemon,
20844
21193
  hostMatches,
20845
21194
  incompleteFileVerdict,
20846
21195
  inlineExecDescription,