@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.mjs CHANGED
@@ -2122,15 +2122,15 @@ function ssrfExemptMatches(entries, normalized) {
2122
2122
  continue;
2123
2123
  }
2124
2124
  if (!target) continue;
2125
- const base2 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2125
+ const base3 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2126
2126
  const prefixText = entry.slice(slash + 1);
2127
2127
  const prefix = /^\d+$/.test(prefixText) ? Number(prefixText) : NaN;
2128
- if (!base2 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2128
+ if (!base3 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2129
2129
  // differ, so `0.0.0.0/0` does not release `::1`.
2130
- base2.length !== target.length || prefix > base2.length) {
2130
+ base3.length !== target.length || prefix > base3.length) {
2131
2131
  continue;
2132
2132
  }
2133
- if (base2.slice(0, prefix) === target.slice(0, prefix)) return true;
2133
+ if (base3.slice(0, prefix) === target.slice(0, prefix)) return true;
2134
2134
  }
2135
2135
  return false;
2136
2136
  }
@@ -2427,7 +2427,7 @@ var CHECK_TEXT = {
2427
2427
  advice: "Fixed at Review for now."
2428
2428
  },
2429
2429
  "commands.node9-disarm": {
2430
- 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.",
2430
+ 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.",
2431
2431
  example: "After reading a web page, the agent runs node9 session-exposure clear --all",
2432
2432
  advice: "Keep Review: these are your commands to run. Block if the agent should never touch node9."
2433
2433
  },
@@ -2480,6 +2480,10 @@ function reviewsEveryAgentFileWrite(mode) {
2480
2480
  const level = levelOf(mode);
2481
2481
  return level === "strict" || level === "block-all";
2482
2482
  }
2483
+ function holdsSendsWithoutDaemon(mode) {
2484
+ const level = levelOf(mode);
2485
+ return level === "strict" || level === "block-all";
2486
+ }
2483
2487
  function isBlockAll(mode) {
2484
2488
  return levelOf(mode) === "block-all";
2485
2489
  }
@@ -2849,7 +2853,7 @@ var PRODUCT_CHECKS = [
2849
2853
  group: "commands",
2850
2854
  owasp: "ASI10",
2851
2855
  title: "node9 disarmed from the shell",
2852
- catches: "a node9 command that clears a session flag, trusts a destination, pauses the gate or weakens a shield, run by the agent",
2856
+ 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",
2853
2857
  values: ALL,
2854
2858
  defaultValue: "review",
2855
2859
  legacy: ["review-node9-disarm"]
@@ -4938,6 +4942,95 @@ function protectedLiteral(code, isProtected) {
4938
4942
  }
4939
4943
  return null;
4940
4944
  }
4945
+ var READ_CALL = {
4946
+ python: String.raw`(?:\b(?:io|codecs)\.)?\bopen|\b(?:dotenv_values|load_dotenv|get_key|read_file|loadtxt|read_csv)`,
4947
+ node: String.raw`\b(?:readFileSync|readFile|createReadStream|readTextFile(?:Sync)?|readFileStr|openSync|file)`,
4948
+ perl: String.raw`\b(?:open|sysopen|read_file|slurp)`,
4949
+ ruby: String.raw`\b(?:File|IO)\.(?:read|binread|readlines|foreach|open)|\bDotenv\.(?:load|parse|overload)`,
4950
+ php: String.raw`\b(?:file_get_contents|fopen|file|readfile|parse_ini_file|highlight_file|show_source)`
4951
+ };
4952
+ var ARG = String.raw`(?:(?:(?:my|our|local)\s+)?[\w.$]+(?:\s*\(\s*\))?|'[^'\n]{0,8}'|"[^"\n]{0,8}")\s*,\s*`;
4953
+ var WRAP = String.raw`(?:(?:new\s+)?[\w.$]+\s*\(\s*(?:${ARG}){0,3}){0,3}`;
4954
+ var STR_PREFIX = String.raw`[rRbBuUfF]{0,2}`;
4955
+ var WRITE_MODE_LITERAL = String.raw`['"](?=[rbtU+]*w|(?![^'"]*\+)[rbtU]*[ax])[rwaxbtU+]{1,4}['"]`;
4956
+ var WRITE_MODE = String.raw`\s*,\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL}`;
4957
+ var WRITE_MODE_AFTER = new RegExp(`^(?:\\s*\\)){0,3}${WRITE_MODE}`);
4958
+ var PERL_WRITE_BEFORE = /['"]\s*(?:\+?[>|]|>>)\s*['"]\s*,\s*$/;
4959
+ var readCallBefore = (language) => new RegExp(
4960
+ String.raw`(?:${READ_CALL[language]})(?![\w$])\s*\(?\s*(?:${ARG}){0,3}${WRAP}${STR_PREFIX}$`
4961
+ );
4962
+ var READ_BEFORE = {
4963
+ python: readCallBefore("python"),
4964
+ node: readCallBefore("node"),
4965
+ perl: readCallBefore("perl"),
4966
+ ruby: readCallBefore("ruby"),
4967
+ php: readCallBefore("php")
4968
+ };
4969
+ var READ_AFTER = {
4970
+ python: new RegExp(
4971
+ String.raw`^\s*\)\s*\.\s*(?:read_text|read_bytes|open)\s*\((?!\s*(?:mode\s*=\s*)?${WRITE_MODE_LITERAL})`
4972
+ )
4973
+ };
4974
+ var ASSIGNED = new RegExp(String.raw`([$\w]+)\s*=\s*${WRAP}${STR_PREFIX}$`);
4975
+ var openedName = (language) => new RegExp(
4976
+ 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*\(` : ""),
4977
+ "g"
4978
+ );
4979
+ var OPENED_NAME = {
4980
+ python: openedName("python"),
4981
+ node: openedName("node"),
4982
+ perl: openedName("perl"),
4983
+ ruby: openedName("ruby"),
4984
+ php: openedName("php")
4985
+ };
4986
+ var DOTENV = {
4987
+ node: {
4988
+ load: /\brequire\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)|\bimport\s*(?:[\w${}\s,*]+\s+from\s*)?['"`]dotenv(?:\/config)?['"`]|\bimport\s*\(\s*['"`]dotenv(?:\/config)?['"`]\s*\)/,
4989
+ values: /\.parsed\b|[(,]\s*(?:require\s*\(\s*['"`]dotenv['"`]\s*\)|dotenv)\s*\.\s*config\s*\(/,
4990
+ env: /\b(?:process|Deno|Bun)\s*\.\s*env\b/,
4991
+ literalPath: /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*['"`]/
4992
+ },
4993
+ python: {
4994
+ load: /\b(?:load_dotenv|dotenv_values|get_key)\s*\(/,
4995
+ values: /\b(?:dotenv_values|get_key)\s*\(/,
4996
+ env: /\b(?:environ|getenv)\b/,
4997
+ literalPath: /\b(?:load_dotenv|dotenv_values)\s*\(\s*(?:dotenv_path\s*=\s*)?[rRbBuU]?['"]/
4998
+ }
4999
+ };
5000
+ var DOTENV_PATH_OPTION = /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*$/;
5001
+ function inlineReadPaths(language, code, preload = {}) {
5002
+ const out = [];
5003
+ const before = READ_BEFORE[language];
5004
+ const after = READ_AFTER[language];
5005
+ const assigned = /* @__PURE__ */ new Map();
5006
+ for (const m of code.matchAll(STRING_LITERAL)) {
5007
+ const raw = m[2].trim();
5008
+ const value = raw.replace(/^[<+]\s*/, "");
5009
+ if (!value) continue;
5010
+ const head = code.slice(Math.max(0, m.index - 160), m.index);
5011
+ const tail = code.slice(m.index + m[0].length, m.index + m[0].length + 40);
5012
+ if (/^[>|]/.test(raw) || WRITE_MODE_AFTER.test(tail) || PERL_WRITE_BEFORE.test(head)) continue;
5013
+ if (before.test(head) || after?.test(tail) || language === "node" && DOTENV_PATH_OPTION.test(head)) {
5014
+ out.push(value);
5015
+ continue;
5016
+ }
5017
+ const name = ASSIGNED.exec(head)?.[1];
5018
+ if (name) assigned.set(name, [...assigned.get(name) ?? [], value]);
5019
+ }
5020
+ if (assigned.size > 0) {
5021
+ const opened = /* @__PURE__ */ new Set();
5022
+ for (const m of code.matchAll(OPENED_NAME[language])) opened.add(m[1] ?? m[2]);
5023
+ for (const [name, values] of assigned) if (opened.has(name)) out.push(...values);
5024
+ }
5025
+ if (language === "python" || language === "node") {
5026
+ const d = DOTENV[language];
5027
+ const readsEnv = d.env.test(code);
5028
+ const loads = /dotenv/.test(code) && d.load.test(code) && !d.literalPath.test(code);
5029
+ if ((loads || preload.dotenv) && (readsEnv || d.values.test(code))) out.push(".env");
5030
+ if (readsEnv) out.push(...preload.envFiles ?? []);
5031
+ }
5032
+ return out;
5033
+ }
4941
5034
  function amplifies(language, code) {
4942
5035
  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*\)/;
4943
5036
  const m = loop.exec(code);
@@ -6567,6 +6660,7 @@ function attachedCode(interp, flag) {
6567
6660
  if (letters === "ep" && /^[ep]*$/i.test(rest)) rest = "";
6568
6661
  return rest === "" ? null : rest;
6569
6662
  }
6663
+ var NODE_VALUE_FLAG = /^(-r|--require|--import|--loader|--experimental-loader|--env-file|--env-file-if-exists|--input-type|-C|--conditions)(?:=(.*))?$/;
6570
6664
  function inlineExecCall(stmt, pipeFed) {
6571
6665
  const cmd = stmt?.Cmd;
6572
6666
  if (!cmd || cmd.kind !== "CallExpr") return null;
@@ -6591,15 +6685,28 @@ function inlineExecCall(stmt, pipeFed) {
6591
6685
  const fromStdin = () => {
6592
6686
  if (stdinFed) {
6593
6687
  const { code, source } = stdinCodeOf(redirs);
6594
- return { interp, code: [code], source };
6688
+ return { interp, code: [code], source, preload };
6595
6689
  }
6596
6690
  return { interp, code: [null], source: "pipe" };
6597
6691
  };
6598
6692
  let positionals2 = 0;
6599
6693
  let selectedProgram = false;
6600
6694
  const codes = [];
6695
+ const preload = {};
6696
+ const nodeFamily = inlineLanguageOf(interp) === "node";
6601
6697
  for (let i = 0; i < args.length; i++) {
6602
6698
  const a = args[i];
6699
+ if (nodeFamily && !selectedProgram && codes.length === 0 && a != null) {
6700
+ const flag = NODE_VALUE_FLAG.exec(a);
6701
+ if (flag) {
6702
+ const value = flag[2] ?? args[++i];
6703
+ if (value != null) {
6704
+ if (/^--env-file/.test(flag[1])) (preload.envFiles ??= []).push(value);
6705
+ else if (/^dotenv\/config(?:\.js)?$/.test(value)) preload.dotenv = true;
6706
+ }
6707
+ continue;
6708
+ }
6709
+ }
6603
6710
  if (a == null) {
6604
6711
  if (codes.length > 0) break;
6605
6712
  positionals2++;
@@ -6636,7 +6743,12 @@ function inlineExecCall(stmt, pipeFed) {
6636
6743
  }
6637
6744
  }
6638
6745
  if (codes.length > 0) {
6639
- return { interp, code: codes, source: codes.includes(null) ? "variable" : void 0 };
6746
+ return {
6747
+ interp,
6748
+ code: codes,
6749
+ source: codes.includes(null) ? "variable" : void 0,
6750
+ preload
6751
+ };
6640
6752
  }
6641
6753
  if (positionals2 === 0 && (stdinFed || pipeFed)) {
6642
6754
  if (!/^(bash|sh|zsh)$/i.test(interp)) return fromStdin();
@@ -7655,7 +7767,7 @@ var FS_OP_CACHE_MAX = 5e3;
7655
7767
  var fsOpCache = /* @__PURE__ */ new Map();
7656
7768
  function analyzeFsOperation(command) {
7657
7769
  const normalized = normalizeCommandForPolicy(command);
7658
- if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command))
7770
+ if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized))
7659
7771
  return null;
7660
7772
  if (fsOpCache.has(command)) {
7661
7773
  const hit = fsOpCache.get(command) ?? null;
@@ -7663,7 +7775,8 @@ function analyzeFsOperation(command) {
7663
7775
  fsOpCache.set(command, hit);
7664
7776
  return hit;
7665
7777
  }
7666
- const computed = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
7778
+ const direct = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
7779
+ const computed = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
7667
7780
  if (fsOpCache.size >= FS_OP_CACHE_MAX) {
7668
7781
  const oldest = fsOpCache.keys().next().value;
7669
7782
  if (oldest !== void 0) fsOpCache.delete(oldest);
@@ -7673,8 +7786,8 @@ function analyzeFsOperation(command) {
7673
7786
  }
7674
7787
  var stripDotSlash = (p) => p.replace(/^\.\//, "");
7675
7788
  function isSensitiveCleanupName(p) {
7676
- const base2 = p.replace(/^.*[\\/]/, "");
7677
- 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);
7789
+ const base3 = p.replace(/^.*[\\/]/, "");
7790
+ 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);
7678
7791
  }
7679
7792
  function isWaivableCleanupTarget(p) {
7680
7793
  if (/^[/~]/.test(p) || /^\$/.test(p)) return false;
@@ -8473,6 +8586,26 @@ function structuralJailRead(command) {
8473
8586
  }
8474
8587
  return review;
8475
8588
  }
8589
+ var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
8590
+ var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
8591
+ function inlineCodeJailRead(command) {
8592
+ const calls = inlineExecCalls(command);
8593
+ if (calls === PARSE_FAIL) return null;
8594
+ let review = null;
8595
+ for (const call of calls) {
8596
+ const language = inlineLanguageOf(call.interp);
8597
+ if (language === null) continue;
8598
+ for (const code of call.code) {
8599
+ if (code === null) continue;
8600
+ for (const p of inlineReadPaths(language, code, call.preload)) {
8601
+ const hit = matchSensitivePath(p);
8602
+ if (hit?.verdict === "block") return hit;
8603
+ review ??= hit;
8604
+ }
8605
+ }
8606
+ }
8607
+ return review;
8608
+ }
8476
8609
  function baseWord(w) {
8477
8610
  return (w ?? "").split("/").pop()?.toLowerCase() ?? "";
8478
8611
  }
@@ -9065,6 +9198,21 @@ function hits(access, paths, directories, context) {
9065
9198
  }
9066
9199
  return false;
9067
9200
  }
9201
+ function hitsNode9Dir(access, dirs, context) {
9202
+ const home = context.homeDirs?.[0] ?? "~";
9203
+ if (access.glob) {
9204
+ const pattern = normalizeFilePath(access.glob, access.cwd ?? context.cwd, home);
9205
+ const magic = pattern.search(/[*?[{]/);
9206
+ const literal = magic < 0 ? pattern : pattern.slice(0, pattern.lastIndexOf("/", magic));
9207
+ return dirs.some((d) => within(literal, d));
9208
+ }
9209
+ const candidates = access.candidates ?? [
9210
+ normalizeFilePath(access.path, access.cwd ?? context.cwd, home)
9211
+ ];
9212
+ return candidates.some(
9213
+ (p) => dirs.some((d) => within(p, d)) || access.recursive === true && dirs.some((d) => within(d, p))
9214
+ );
9215
+ }
9068
9216
  var exempt = (p) => SYSTEM_DIRS_EXEMPT.some((d) => within(p, d));
9069
9217
  function hitsSystemDir(access, context, dirs = SYSTEM_DIRS) {
9070
9218
  const home = context.homeDirs?.[0] ?? "~";
@@ -9107,6 +9255,7 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
9107
9255
  const consider = (result) => {
9108
9256
  if (!best || RANK[result.decision] > RANK[best.decision]) best = result;
9109
9257
  };
9258
+ const node9Dirs = homes.map((home) => `${home.replace(/\/$/, "")}/.node9`);
9110
9259
  for (const access of accesses) {
9111
9260
  const mutation = access.operation !== "read";
9112
9261
  let kind;
@@ -9135,6 +9284,10 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
9135
9284
  "files.system-dirs",
9136
9285
  "review-root-home-read",
9137
9286
  "Reading the root account's home requires approval"
9287
+ ] : mutation && hitsNode9Dir(access, node9Dirs, context) ? [
9288
+ "commands.node9-disarm",
9289
+ "review-node9-disarm",
9290
+ "Changing node9's own files requires approval"
9138
9291
  ] : null;
9139
9292
  } catch {
9140
9293
  consider(incompleteFileVerdict(access.operation));
@@ -12139,9 +12292,9 @@ function validateBelgianNationalNumber(raw) {
12139
12292
  if (!/^\d{11}$/.test(d)) return false;
12140
12293
  const month = Number(d.slice(2, 4)) % 20;
12141
12294
  if (month !== 0 && !plausibleDate(String(month).padStart(2, "0"), d.slice(4, 6))) return false;
12142
- const base2 = Number(d.slice(0, 9));
12295
+ const base3 = Number(d.slice(0, 9));
12143
12296
  const check = Number(d.slice(9, 11));
12144
- return 97 - base2 % 97 === check || 97 - (2e9 + base2) % 97 === check;
12297
+ return 97 - base3 % 97 === check || 97 - (2e9 + base3) % 97 === check;
12145
12298
  }
12146
12299
  function validateCuit(raw) {
12147
12300
  const d = raw.replace(/-/g, "");
@@ -13749,9 +13902,9 @@ var GitWalk = class {
13749
13902
  const name = n.Name.Value;
13750
13903
  if (n.Append) {
13751
13904
  const prev = this.appended.has(name) ? this.appended.get(name) : resolveWordLiteral(n.Value) === null ? null : void 0;
13752
- const base2 = prev === void 0 ? recordedExpansion(name) : prev;
13905
+ const base3 = prev === void 0 ? recordedExpansion(name) : prev;
13753
13906
  const piece = resolveWordLiteral(n.Value);
13754
- this.appended.set(name, typeof base2 === "string" && piece !== null ? base2 + piece : null);
13907
+ this.appended.set(name, typeof base3 === "string" && piece !== null ? base3 + piece : null);
13755
13908
  this.treeTopVars.delete(name);
13756
13909
  return true;
13757
13910
  }
@@ -14783,9 +14936,9 @@ var INSTRUCTION_NAMES = /* @__PURE__ */ new Set([
14783
14936
  var SETTINGS_RE = /\/(?:\.claude\/settings(?:\.local)?\.json|\.gemini\/settings\.json|\.codex\/hooks\.json|\.cursor\/hooks\.json)$/i;
14784
14937
  function agentFileKind(p) {
14785
14938
  const lower2 = p.toLowerCase();
14786
- const base2 = lower2.slice(lower2.lastIndexOf("/") + 1);
14787
- if (INSTRUCTION_NAMES.has(base2)) return "instructions";
14788
- if (base2 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base2))
14939
+ const base3 = lower2.slice(lower2.lastIndexOf("/") + 1);
14940
+ if (INSTRUCTION_NAMES.has(base3)) return "instructions";
14941
+ if (base3 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base3))
14789
14942
  return "instructions";
14790
14943
  if (/\/\.cursor\/rules(?:\/|$)/.test(lower2)) return "instructions";
14791
14944
  if (/\/\.claude\/projects\/[^/]+\/memory(?:\/|$)/.test(lower2)) return "memory";
@@ -14955,7 +15108,7 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
14955
15108
  skills: "agent skill",
14956
15109
  settings: "agent settings"
14957
15110
  };
14958
- const base2 = `${kindLabel[kind]} written: ${access.path}`;
15111
+ const base3 = `${kindLabel[kind]} written: ${access.path}`;
14959
15112
  if (!signal && !every) {
14960
15113
  return {
14961
15114
  decision: "allow",
@@ -14965,14 +15118,14 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
14965
15118
  path: access.path,
14966
15119
  operation: access.operation,
14967
15120
  kind,
14968
- reason: base2,
15121
+ reason: base3,
14969
15122
  ruleDescription: "The AI writes to a file every later agent session loads as instructions.",
14970
- blockedByLabel: `Node9 Files: ${base2}`,
15123
+ blockedByLabel: `Node9 Files: ${base3}`,
14971
15124
  tier: 2
14972
15125
  };
14973
15126
  }
14974
15127
  const ruleName = signal === "content" ? "review-agent-file-content" : signal === "hooks" ? "review-agent-hooks-change" : "review-agent-file-write";
14975
- const reason = signal ? `${base2} (${detail})` : base2;
15128
+ const reason = signal ? `${base3} (${detail})` : base3;
14976
15129
  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.";
14977
15130
  return {
14978
15131
  decision: value === "log" ? "allow" : value,
@@ -17692,6 +17845,175 @@ function scanArgumentSecrets(args) {
17692
17845
  } : null;
17693
17846
  }
17694
17847
 
17848
+ // src/shell/node9-disarm.ts
17849
+ var RULE_NAME2 = "review-node9-disarm";
17850
+ 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.";
17851
+ var DAEMON_CMDLINES = [
17852
+ "node /usr/lib/node_modules/@node9/proxy/dist/cli.js daemon start",
17853
+ "node9 daemon start"
17854
+ ];
17855
+ var DAEMON_NAMES = ["node", "node9"];
17856
+ var KILLALL_NAMES = /* @__PURE__ */ new Set(["node", "node9", "node.exe", "node9.exe"]);
17857
+ var STOP_SYSTEMCTL = /* @__PURE__ */ new Set(["stop", "disable", "mask", "kill"]);
17858
+ var STOP_LAUNCHCTL = /* @__PURE__ */ new Set(["unload", "bootout", "remove", "stop", "kill", "disable"]);
17859
+ var PKILL_VALUE_FLAGS = /* @__PURE__ */ new Set([
17860
+ "-u",
17861
+ "-U",
17862
+ "-g",
17863
+ "-G",
17864
+ "-P",
17865
+ "-s",
17866
+ "-t",
17867
+ "-F",
17868
+ "--signal",
17869
+ "--euid",
17870
+ "--uid",
17871
+ "--pgroup",
17872
+ "--group",
17873
+ "--parent",
17874
+ "--session",
17875
+ "--terminal",
17876
+ "--pidfile",
17877
+ "--ns",
17878
+ "--nslist"
17879
+ ]);
17880
+ var NAME_PRESCREEN_RE = /node9|kill|systemctl|launchctl|daemon/i;
17881
+ function patternSelects(pattern, targets) {
17882
+ const pieces = pattern.toLowerCase().split(/[\\^$.*+?()[\]{}|]+/).filter(Boolean);
17883
+ if (pieces.length === 0) return false;
17884
+ return targets.some((t) => pieces.every((p) => t.includes(p)));
17885
+ }
17886
+ function sourceText(bytes, pos, end) {
17887
+ if (typeof pos !== "number" || typeof end !== "number" || pos < 0 || end < pos) return "";
17888
+ return new TextDecoder().decode(bytes.subarray(pos, end));
17889
+ }
17890
+ var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
17891
+ function nextOperand(words, from) {
17892
+ for (let i = from; i < words.length; i++) {
17893
+ const w = words[i];
17894
+ if (w !== null && w.startsWith("-")) continue;
17895
+ return i;
17896
+ }
17897
+ return -1;
17898
+ }
17899
+ function node9Command(words, h) {
17900
+ const head = base2(words[h]);
17901
+ if (head !== "node9" && head !== "node9.cmd" && words[h] !== "@node9/proxy") return null;
17902
+ const s = nextOperand(words, h + 1);
17903
+ const sub = s < 0 ? "" : (words[s] ?? "").toLowerCase();
17904
+ if (sub === "uninstall") return "node9 uninstall";
17905
+ if (sub !== "daemon") return null;
17906
+ const a = nextOperand(words, s + 1);
17907
+ const action = a < 0 ? "" : (words[a] ?? "").toLowerCase();
17908
+ return action === "stop" || action === "uninstall" ? `node9 daemon ${action}` : null;
17909
+ }
17910
+ var HOME_PID_FILE_RE = /(?:^|[\s"'(=`])(?:~|\$HOME|\$\{HOME\}|\/home\/[^/\s]+|\/Users\/[^/\s]+|\/root)\/\.node9\/daemon\.pid/;
17911
+ function killsDaemon(words, texts, h, daemonPid) {
17912
+ const head = base2(words[h]);
17913
+ const args = words.slice(h + 1);
17914
+ if (head === "kill") {
17915
+ for (let i = 0; i < args.length; i++) {
17916
+ const w = args[i];
17917
+ if (w === "-s" || w === "-n") {
17918
+ i++;
17919
+ continue;
17920
+ }
17921
+ if (w !== null && w.startsWith("-")) continue;
17922
+ if (w === null) {
17923
+ if (HOME_PID_FILE_RE.test(texts[h + 1 + i] ?? "")) return "kill of the pid in daemon.pid";
17924
+ continue;
17925
+ }
17926
+ if (daemonPid !== null && w === String(daemonPid)) return `kill ${w} (the node9 daemon)`;
17927
+ }
17928
+ return null;
17929
+ }
17930
+ if (head === "pkill") {
17931
+ let full = false;
17932
+ let pattern = null;
17933
+ for (let i = 0; i < args.length; i++) {
17934
+ const w = args[i];
17935
+ if (w === null) continue;
17936
+ if (PKILL_VALUE_FLAGS.has(w)) {
17937
+ i++;
17938
+ continue;
17939
+ }
17940
+ if (w === "--full") full = true;
17941
+ else if (/^-[a-zA-Z]+$/.test(w) && w.includes("f")) full = true;
17942
+ if (w.startsWith("-")) continue;
17943
+ pattern = w;
17944
+ }
17945
+ if (pattern === null) return null;
17946
+ return patternSelects(pattern, full ? DAEMON_CMDLINES : DAEMON_NAMES) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
17947
+ }
17948
+ if (head === "killall") {
17949
+ const regex = args.some((w) => w === "-r" || w === "--regexp");
17950
+ for (const w of args) {
17951
+ if (w === null || w.startsWith("-")) continue;
17952
+ if (regex ? patternSelects(w, DAEMON_NAMES) : KILLALL_NAMES.has(w.toLowerCase()))
17953
+ return `killall ${w}`;
17954
+ }
17955
+ return null;
17956
+ }
17957
+ if (head === "taskkill" || head === "taskkill.exe") {
17958
+ for (let i = 0; i < args.length - 1; i++) {
17959
+ const flag = (args[i] ?? "").toLowerCase();
17960
+ const value = (args[i + 1] ?? "").toLowerCase();
17961
+ if ((flag === "/im" || flag === "-im") && KILLALL_NAMES.has(value))
17962
+ return `taskkill /IM ${value}`;
17963
+ if ((flag === "/pid" || flag === "-pid") && daemonPid !== null && value === String(daemonPid))
17964
+ return `taskkill /PID ${value} (the node9 daemon)`;
17965
+ }
17966
+ }
17967
+ return null;
17968
+ }
17969
+ function stopsService(words, h) {
17970
+ const head = base2(words[h]);
17971
+ const args = words.slice(h + 1).map((w) => (w ?? "").toLowerCase());
17972
+ if (head === "systemctl") {
17973
+ const action = args.find((w) => STOP_SYSTEMCTL.has(w));
17974
+ if (action && args.some((w) => /^node9-daemon(\.service)?$/.test(w)))
17975
+ return `systemctl ${action} node9-daemon`;
17976
+ }
17977
+ if (head === "launchctl") {
17978
+ const action = args.find((w) => STOP_LAUNCHCTL.has(w));
17979
+ if (action && args.some((w) => w.includes("ai.node9.daemon")))
17980
+ return `launchctl ${action} ai.node9.daemon`;
17981
+ }
17982
+ return null;
17983
+ }
17984
+ function analyzeNode9Disarm(command, daemonPid = null, depth = 0) {
17985
+ if (depth > 3 || !NAME_PRESCREEN_RE.test(command.replace(/[\\'"]/g, ""))) return null;
17986
+ let shown = null;
17987
+ const bytes = new TextEncoder().encode(command);
17988
+ try {
17989
+ walkCommandScope(command, (node) => {
17990
+ if (shown !== null) return false;
17991
+ const n = node;
17992
+ if (!n || n.kind !== "CallExpr") return true;
17993
+ const words = (n.Args || []).map((a) => resolveWordLiteral(a));
17994
+ if (words.length === 0) return true;
17995
+ const texts = (n.Args || []).map((a) => sourceText(bytes, a.pos, a.end));
17996
+ const h = unwrapCommandHead(words);
17997
+ shown = node9Command(words, h) ?? killsDaemon(words, texts, h, daemonPid) ?? stopsService(words, h);
17998
+ if (shown === null) {
17999
+ const payload = literalShellPayload(words, base2(words[0]));
18000
+ if (payload) {
18001
+ const inner = analyzeNode9Disarm(payload, daemonPid, depth + 1);
18002
+ if (inner) shown = inner.reason.replace(/^node9 switched off by the agent: /, "");
18003
+ }
18004
+ }
18005
+ return true;
18006
+ });
18007
+ } catch {
18008
+ }
18009
+ if (shown === null) return null;
18010
+ return {
18011
+ ruleName: RULE_NAME2,
18012
+ reason: `node9 switched off by the agent: ${shown}`,
18013
+ description: DESCRIPTION
18014
+ };
18015
+ }
18016
+
17695
18017
  // src/policy/index.ts
17696
18018
  function catalogSettings(config) {
17697
18019
  return catalogSettingsFromConfig(config.settings, config.policy);
@@ -17800,7 +18122,15 @@ function egressPolicyVerdict(eg) {
17800
18122
  checkId: "network.unknown-host"
17801
18123
  };
17802
18124
  }
18125
+ var NOT_OVERRIDABLE_CHECKS = /* @__PURE__ */ new Set([
18126
+ "data.credential-files",
18127
+ "data.credential-files-other"
18128
+ ]);
17803
18129
  async function evaluatePolicy(config, toolName, args, context = {}, hostHooks = {}) {
18130
+ const v = await evaluatePolicyVerdict(config, toolName, args, context, hostHooks);
18131
+ return v.decision === "block" && v.checkId !== void 0 && NOT_OVERRIDABLE_CHECKS.has(v.checkId) ? { ...v, overridable: false } : v;
18132
+ }
18133
+ async function evaluatePolicyVerdict(config, toolName, args, context = {}, hostHooks = {}) {
17804
18134
  let protectedVerdict = null;
17805
18135
  const layers = inspectionLayers(config.policy);
17806
18136
  if (context.agent !== "Terminal") {
@@ -17858,7 +18188,7 @@ async function evaluatePolicy(config, toolName, args, context = {}, hostHooks =
17858
18188
  }
17859
18189
  async function evaluatePolicyCore(config, toolName, args, context = {}, hooks = {}) {
17860
18190
  const { agent, cwd, activeEnvironment } = context;
17861
- const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop } = hooks;
18191
+ const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop, daemonPid } = hooks;
17862
18192
  const settingsView = catalogSettings(config);
17863
18193
  const layers = inspectionLayers(config.policy);
17864
18194
  const cv = (id) => checkValue(settingsView, id);
@@ -18043,6 +18373,23 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
18043
18373
  else if (v && !pendingAstReview) pendingAstReview = v;
18044
18374
  }
18045
18375
  }
18376
+ if (cv("commands.node9-disarm") !== "off") {
18377
+ const finding = analyzeNode9Disarm(bashCommand, daemonPid?.() ?? null);
18378
+ if (finding) {
18379
+ const v = applyCheckValue(cv("commands.node9-disarm"), {
18380
+ decision: "review",
18381
+ blockedByLabel: `Node9 (AST): ${finding.ruleName}`,
18382
+ reason: finding.reason,
18383
+ tier: 2,
18384
+ ruleName: finding.ruleName,
18385
+ ruleDescription: finding.description,
18386
+ checkId: "commands.node9-disarm"
18387
+ });
18388
+ if (v?.logged) noteLogged(v);
18389
+ else if (v?.decision === "block") return v;
18390
+ else if (v && !pendingAstReview) pendingAstReview = v;
18391
+ }
18392
+ }
18046
18393
  }
18047
18394
  if (config.policy.smartRules.length > 0) {
18048
18395
  const rmCleanupWaiver = bashCommand !== null && isRmCreatedInCommandCleanup(bashCommand);
@@ -18634,8 +18981,8 @@ function hasRoutingNumber(text) {
18634
18981
  return false;
18635
18982
  }
18636
18983
  var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
18637
- function* validCardRuns(text, base2, exemptFractions = true) {
18638
- const re = new RegExp(base2.source, "g");
18984
+ function* validCardRuns(text, base3, exemptFractions = true) {
18985
+ const re = new RegExp(base3.source, "g");
18639
18986
  let m;
18640
18987
  while ((m = re.exec(text)) !== null) {
18641
18988
  const digits = m[0].replace(/\D/g, "");
@@ -18648,17 +18995,17 @@ function* validCardRuns(text, base2, exemptFractions = true) {
18648
18995
  }
18649
18996
  }
18650
18997
  function hasValidCard(text) {
18651
- for (const base2 of CARD_PATTERNS) {
18652
- if (!validCardRuns(text, base2).next().done) return true;
18998
+ for (const base3 of CARD_PATTERNS) {
18999
+ if (!validCardRuns(text, base3).next().done) return true;
18653
19000
  }
18654
19001
  return false;
18655
19002
  }
18656
19003
  function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
18657
19004
  let out = text;
18658
- for (const base2 of CARD_PATTERNS) {
19005
+ for (const base3 of CARD_PATTERNS) {
18659
19006
  let res = "";
18660
19007
  let last = 0;
18661
- for (const run of validCardRuns(out, base2, exemptFractions)) {
19008
+ for (const run of validCardRuns(out, base3, exemptFractions)) {
18662
19009
  res += out.slice(last, run.index) + replace(run.digits);
18663
19010
  last = run.index + run.length;
18664
19011
  }
@@ -18947,9 +19294,9 @@ function maskLeaf(value, key, depth) {
18947
19294
  const used = /* @__PURE__ */ new Set();
18948
19295
  return Object.fromEntries(
18949
19296
  Object.entries(value).map(([k, v]) => {
18950
- const base2 = maskPersonalData(k);
18951
- let name = base2;
18952
- for (let n = 2; used.has(name); n++) name = `${base2}#${n}`;
19297
+ const base3 = maskPersonalData(k);
19298
+ let name = base3;
19299
+ for (let n = 2; used.has(name); n++) name = `${base3}#${n}`;
18953
19300
  used.add(name);
18954
19301
  return [name, maskLeaf(v, k, depth + 1)];
18955
19302
  })
@@ -19997,8 +20344,8 @@ function matchCanaryArgs(args, values) {
19997
20344
 
19998
20345
  // src/scan/canonical.ts
19999
20346
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
20000
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v37";
20001
- var CANONICAL_EXTRACTOR_HASH = "2c9a0271d9c1dd57";
20347
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
20348
+ var CANONICAL_EXTRACTOR_HASH = "e07d9e5e537017ae";
20002
20349
  var DEDUPE_PREVIEW_LEN = 120;
20003
20350
  function extractCanonicalFindings(call, ctx) {
20004
20351
  const out = [];
@@ -20578,6 +20925,7 @@ export {
20578
20925
  gitInvocations,
20579
20926
  gitRepoPath,
20580
20927
  hashDestination,
20928
+ holdsSendsWithoutDaemon,
20581
20929
  hostMatches,
20582
20930
  incompleteFileVerdict,
20583
20931
  inlineExecDescription,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/policy-engine",
3
- "version": "2.51.0",
3
+ "version": "2.53.0",
4
4
  "description": "Shared policy evaluation engine for node9 — DLP, smart rules, AST shell parsing, shields, loop detection. Pure functions, no I/O. Used by both node9-proxy and the node9 SaaS firewall.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://node9.ai",