@node9/policy-engine 2.54.0 → 2.55.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.d.mts CHANGED
@@ -169,6 +169,12 @@ interface FileAccess {
169
169
  recursive?: boolean;
170
170
  /** A write that adds to the file (`>>`, `tee -a`): its content stays. */
171
171
  append?: true;
172
+ /** A shell write whose whole content is literal (a heredoc, `echo`, `printf`
173
+ * redirected to the file): what the file will hold (node9Firewall#385). */
174
+ text?: string;
175
+ /** An in-place edit made only of substitutions (`sed -i 's/a/b/'`): the
176
+ * replacement texts, judged as an edit tool's new text would be. */
177
+ edits?: string[];
172
178
  /** This basename-joined candidate applies only if this operand is a directory. */
173
179
  directoryTarget?: string;
174
180
  candidates?: string[];
@@ -506,7 +512,7 @@ declare function checkValue(settings: CatalogSettings, id: string): Verdict;
506
512
  * stores this on its config so every reader sees the same answers. */
507
513
  declare function resolveCheckMap(settings: CatalogSettings): Record<string, Verdict>;
508
514
 
509
- type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies';
515
+ type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies' | 'kills-service';
510
516
 
511
517
  /**
512
518
  * The POSIX reading of a command. Kept as the single-string API every existing
@@ -2449,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
2449
2455
  * files changed, this hash must change too, and you must consciously
2450
2456
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2451
2457
  */
2452
- declare const CANONICAL_EXTRACTOR_HASH = "5ec00461a49e1858";
2458
+ declare const CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
2453
2459
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2454
2460
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2455
2461
  /**
package/dist/index.d.ts CHANGED
@@ -169,6 +169,12 @@ interface FileAccess {
169
169
  recursive?: boolean;
170
170
  /** A write that adds to the file (`>>`, `tee -a`): its content stays. */
171
171
  append?: true;
172
+ /** A shell write whose whole content is literal (a heredoc, `echo`, `printf`
173
+ * redirected to the file): what the file will hold (node9Firewall#385). */
174
+ text?: string;
175
+ /** An in-place edit made only of substitutions (`sed -i 's/a/b/'`): the
176
+ * replacement texts, judged as an edit tool's new text would be. */
177
+ edits?: string[];
172
178
  /** This basename-joined candidate applies only if this operand is a directory. */
173
179
  directoryTarget?: string;
174
180
  candidates?: string[];
@@ -506,7 +512,7 @@ declare function checkValue(settings: CatalogSettings, id: string): Verdict;
506
512
  * stores this on its config so every reader sees the same answers. */
507
513
  declare function resolveCheckMap(settings: CatalogSettings): Record<string, Verdict>;
508
514
 
509
- type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies';
515
+ type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies' | 'kills-service';
510
516
 
511
517
  /**
512
518
  * The POSIX reading of a command. Kept as the single-string API every existing
@@ -2449,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
2449
2455
  * files changed, this hash must change too, and you must consciously
2450
2456
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2451
2457
  */
2452
- declare const CANONICAL_EXTRACTOR_HASH = "5ec00461a49e1858";
2458
+ declare const CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
2453
2459
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2454
2460
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2455
2461
  /**
package/dist/index.js CHANGED
@@ -2566,6 +2566,11 @@ var CHECK_TEXT = {
2566
2566
  example: "/tmp/build-helper --serve",
2567
2567
  advice: "Keep Review. Malware often runs from /tmp."
2568
2568
  },
2569
+ "commands.system-processes": {
2570
+ plain: "The agent stops or kills a system service: sshd, dockerd, containerd, systemd, kubelet, cron, the firewall, the display server, or a database or web server (nginx, apache, mysql, postgres, redis, mongo). Directly (pkill sshd, systemctl stop docker, kill of pid 1) or through the process list (a script that finds the processes of a name and kills them). Killing a process by its number, pkill node, killall python and systemctl restart are not this check.",
2571
+ example: "ps -eo pid,cmd | grep sshd | awk '{print $1}' | xargs kill -9",
2572
+ advice: "Keep Review: a stopped service takes other people and programs down with it. Set Log on a machine where agents manage local servers all day."
2573
+ },
2569
2574
  "commands.disk-destroy": {
2570
2575
  plain: "The agent formats, overwrites or securely erases a disk or file.",
2571
2576
  example: "dd if=/dev/zero of=/dev/sda",
@@ -2762,6 +2767,7 @@ var SOFT = {
2762
2767
  "commands.sql-no-where": "log",
2763
2768
  "commands.temp-binary": "log",
2764
2769
  "commands.disk-destroy": "log",
2770
+ "commands.system-processes": "log",
2765
2771
  "commands.dangerous-word": "log",
2766
2772
  "files.system-dirs": "log",
2767
2773
  "files.shell-startup": "log",
@@ -3171,6 +3177,16 @@ var PRODUCT_CHECKS = [
3171
3177
  defaultValue: "review",
3172
3178
  legacy: ["Manual Nuclear Protection"]
3173
3179
  },
3180
+ {
3181
+ id: "commands.system-processes",
3182
+ group: "commands",
3183
+ owasp: "ASI02",
3184
+ title: "Stops a system service",
3185
+ catches: "kill, pkill, killall, systemctl stop or kill, service stop or launchctl unload aimed at a system service (sshd, dockerd, systemd, kubelet, cron, a database or web server), or a script that walks the process list for one of those names and kills what it finds",
3186
+ values: ALL,
3187
+ defaultValue: "review",
3188
+ legacy: ["Node9: System Service Stopped"]
3189
+ },
3174
3190
  {
3175
3191
  id: "commands.dangerous-word",
3176
3192
  group: "commands",
@@ -4282,12 +4298,46 @@ function wordValues(word, state) {
4282
4298
  if (!dynamic) return out.map(asWord);
4283
4299
  return out.filter((piece) => piece.value !== "").map((piece) => ({ value: piece.value, pattern: piece.pattern + "*", dynamic: true }));
4284
4300
  }
4301
+ function sedSubstitutions(script) {
4302
+ const out = [];
4303
+ for (const raw of script.split(/\r?\n|;/)) {
4304
+ const cmd = raw.trim();
4305
+ if (cmd === "") continue;
4306
+ const m = /^(?:(?:\d+|\$|\/(?:\\.|[^\\/])*\/)(?:,(?:\d+|\$|\/(?:\\.|[^\\/])*\/))?)?s(.)/.exec(
4307
+ cmd
4308
+ );
4309
+ if (!m) return null;
4310
+ const delimiter = m[1];
4311
+ if (delimiter === "\\") return null;
4312
+ const parts = [];
4313
+ let cur = "";
4314
+ let i = m[0].length;
4315
+ for (; i < cmd.length && parts.length < 2; i++) {
4316
+ const ch = cmd[i];
4317
+ if (ch === "\\" && i + 1 < cmd.length) {
4318
+ cur += ch + cmd[++i];
4319
+ continue;
4320
+ }
4321
+ if (ch === delimiter) {
4322
+ parts.push(cur);
4323
+ cur = "";
4324
+ continue;
4325
+ }
4326
+ cur += ch;
4327
+ }
4328
+ if (parts.length < 2) return null;
4329
+ if (!/^[gpiImM0-9]*$/.test(cmd.slice(i))) return null;
4330
+ out.push(parts[1].replace(/\\(.)/g, "$1"));
4331
+ }
4332
+ return out.length > 0 ? out : null;
4333
+ }
4285
4334
  function collectShellFileAccesses(command, context = {}) {
4286
4335
  const out = [];
4287
4336
  let payloads = 256;
4288
4337
  const functions = /* @__PURE__ */ new Map();
4289
4338
  const seenCalls = /* @__PURE__ */ new Set();
4290
4339
  const pipedStdin = /* @__PURE__ */ new WeakMap();
4340
+ let currentStdin = null;
4291
4341
  let callWalks2 = MAX_CALL_WALKS;
4292
4342
  const initial = {
4293
4343
  cwd: [context.cwd ?? ""],
@@ -4382,8 +4432,9 @@ function collectShellFileAccesses(command, context = {}) {
4382
4432
  }
4383
4433
  const locate = (p) => tokens.find((w) => w?.value === p) ?? { value: p };
4384
4434
  if (name === "sed") {
4385
- let inplace = false, hasScript = false, ended = false;
4435
+ let inplace = false, hasScript = false, ended = false, scriptUnknown = false;
4386
4436
  const files = [];
4437
+ const scriptParts = [];
4387
4438
  for (let i = 0; i < args.length; i++) {
4388
4439
  const token = args[i];
4389
4440
  if (!token) {
@@ -4401,7 +4452,11 @@ function collectShellFileAccesses(command, context = {}) {
4401
4452
  hasScript = true;
4402
4453
  const eq = value.indexOf("=");
4403
4454
  const script = eq < 0 ? args[++i] : { value: value.slice(eq + 1) };
4404
- if (value.startsWith("--file") && script) add("read", script, state);
4455
+ if (value.startsWith("--file")) {
4456
+ scriptUnknown = true;
4457
+ if (script) add("read", script, state);
4458
+ } else if (script?.value) scriptParts.push(script.value);
4459
+ else scriptUnknown = true;
4405
4460
  }
4406
4461
  continue;
4407
4462
  }
@@ -4416,7 +4471,11 @@ function collectShellFileAccesses(command, context = {}) {
4416
4471
  if (flag === "e" || flag === "f") {
4417
4472
  hasScript = true;
4418
4473
  const script = value.slice(j + 1) ? { value: value.slice(j + 1) } : args[++i];
4419
- if (flag === "f" && script) add("read", script, state);
4474
+ if (flag === "f") {
4475
+ scriptUnknown = true;
4476
+ if (script) add("read", script, state);
4477
+ } else if (script?.value) scriptParts.push(script.value);
4478
+ else scriptUnknown = true;
4420
4479
  break;
4421
4480
  }
4422
4481
  if (flag === "l") {
@@ -4426,10 +4485,14 @@ function collectShellFileAccesses(command, context = {}) {
4426
4485
  }
4427
4486
  continue;
4428
4487
  }
4429
- if (!hasScript) hasScript = true;
4430
- else files.push(token);
4488
+ if (!hasScript) {
4489
+ hasScript = true;
4490
+ scriptParts.push(value);
4491
+ } else files.push(token);
4431
4492
  }
4432
- for (const file of files) add(inplace ? "write" : "read", file, state);
4493
+ const edits = inplace && !scriptUnknown ? sedSubstitutions(scriptParts.join("\n")) : null;
4494
+ for (const file of files)
4495
+ add(inplace ? "write" : "read", file, state, edits ? { edits } : {});
4433
4496
  return;
4434
4497
  }
4435
4498
  if (FS_READ_TOOLS.has(name) && name !== "dd") {
@@ -4556,9 +4619,11 @@ function collectShellFileAccesses(command, context = {}) {
4556
4619
  continue;
4557
4620
  const remove = name === "rm" || name === "unlink";
4558
4621
  const append = name === "tee" && strings.some((s) => s === "--append" || /^-[^-]*a/.test(s));
4622
+ const teed = name === "tee" && !append ? currentStdin : null;
4559
4623
  add(remove ? "remove" : name === "touch" ? "create" : "write", token, state, {
4560
4624
  recursive: remove && strings.some((s) => /^-[^-]*[rR]/.test(s) || s === "--recursive"),
4561
- ...append ? { append: true } : {}
4625
+ ...append ? { append: true } : {},
4626
+ ...teed !== null ? { text: teed } : {}
4562
4627
  });
4563
4628
  }
4564
4629
  return;
@@ -4880,11 +4945,18 @@ function collectShellFileAccesses(command, context = {}) {
4880
4945
  if (stmt.Background) state = clone(state);
4881
4946
  const headWord = stmt.Cmd && stmt.Cmd.kind === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
4882
4947
  const sends = SENDING_STDIN.has(headWord);
4948
+ let produced;
4883
4949
  for (const redir of stmt.Redirs ?? []) {
4884
4950
  substitutions(redir.Word, state, depth);
4885
4951
  for (const word of wordValues(redir.Word, state)) {
4886
- if (ops().WRITES.has(redir.Op))
4887
- add("write", word, state, ops().APPENDS.has(redir.Op) ? { append: true } : {});
4952
+ if (ops().WRITES.has(redir.Op)) {
4953
+ if (ops().APPENDS.has(redir.Op)) add("write", word, state, { append: true });
4954
+ else {
4955
+ const stdout = redir.N == null || redir.N.Value === "1";
4956
+ if (stdout && produced === void 0) produced = producedText(stmt);
4957
+ add("write", word, state, stdout && produced ? { text: produced } : {});
4958
+ }
4959
+ }
4888
4960
  if (ops().READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
4889
4961
  if (redir.Op === ops().DUP_OUT && word.value && !/^\d+$/.test(word.value))
4890
4962
  add("write", word, state);
@@ -4896,6 +4968,7 @@ function collectShellFileAccesses(command, context = {}) {
4896
4968
  stdinScript(stmt, state, depth);
4897
4969
  const fedText = stdinText(stmt);
4898
4970
  if (fedText !== null) nestedPayload(xargsPayload(stmt, fedText), clone(state), depth);
4971
+ currentStdin = fedText;
4899
4972
  switch (cmd.kind) {
4900
4973
  case "CallExpr":
4901
4974
  call(cmd, state, depth);
@@ -5010,6 +5083,98 @@ function collectShellFileAccesses(command, context = {}) {
5010
5083
  return out;
5011
5084
  }
5012
5085
 
5086
+ // src/shell/services.ts
5087
+ var INFRASTRUCTURE_SERVICES = [
5088
+ "init",
5089
+ "sshd",
5090
+ "dockerd",
5091
+ "docker-proxy",
5092
+ "containerd",
5093
+ "containerd-shim",
5094
+ "docker-containerd-shim",
5095
+ "runc",
5096
+ "systemd-journald",
5097
+ "journald",
5098
+ "systemd-logind",
5099
+ "systemd-udevd",
5100
+ "udevd",
5101
+ "dbus-daemon",
5102
+ "polkitd",
5103
+ "sssd",
5104
+ "kubelet",
5105
+ "kube-apiserver",
5106
+ "crond",
5107
+ "cron",
5108
+ "atd",
5109
+ "auditd",
5110
+ "rsyslogd",
5111
+ "syslogd",
5112
+ "chronyd",
5113
+ "ntpd",
5114
+ "NetworkManager",
5115
+ "wpa_supplicant",
5116
+ "dhclient",
5117
+ "avahi-daemon",
5118
+ "firewalld",
5119
+ "ufw",
5120
+ "cupsd",
5121
+ "snapd",
5122
+ "bluetoothd",
5123
+ "Xorg",
5124
+ "Xwayland",
5125
+ "gdm",
5126
+ "sddm",
5127
+ "lightdm"
5128
+ ];
5129
+ var SERVER_SERVICES = [
5130
+ "nginx",
5131
+ "apache2",
5132
+ "httpd",
5133
+ "mysqld",
5134
+ "mariadbd",
5135
+ "postgres",
5136
+ "postgresql",
5137
+ "redis-server",
5138
+ "mongod"
5139
+ ];
5140
+ var SYSTEM_SERVICES = [...INFRASTRUCTURE_SERVICES, ...SERVER_SERVICES];
5141
+ var escape = (s) => s.replace(/[.*+?^${}()|[\]\\-]/g, "\\$&");
5142
+ var SERVICE_WORD_RE = new RegExp(
5143
+ `(?:^|[^A-Za-z0-9_.-])(${SYSTEM_SERVICES.map(escape).join("|")})(?![A-Za-z0-9_.-])`,
5144
+ "i"
5145
+ );
5146
+ var INIT_PATTERN_RE = /(?:["'*])init(?:["'*])/;
5147
+ function serviceNamedIn(text) {
5148
+ const re = new RegExp(SERVICE_WORD_RE.source, "gi");
5149
+ for (let m = re.exec(text); m; m = re.exec(text)) {
5150
+ const lower2 = m[1].toLowerCase();
5151
+ if (lower2 === "init" && !INIT_PATTERN_RE.test(text)) continue;
5152
+ return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? m[1];
5153
+ }
5154
+ return null;
5155
+ }
5156
+ var UNIT_ALIASES = {
5157
+ docker: "dockerd",
5158
+ ssh: "sshd",
5159
+ mysql: "mysqld",
5160
+ mariadb: "mariadbd",
5161
+ redis: "redis-server",
5162
+ mongodb: "mongod",
5163
+ apache: "apache2",
5164
+ rsyslog: "rsyslogd",
5165
+ "systemd-networkd": "systemd-udevd",
5166
+ dbus: "dbus-daemon",
5167
+ avahi: "avahi-daemon",
5168
+ bluetooth: "bluetoothd",
5169
+ cups: "cupsd",
5170
+ chrony: "chronyd"
5171
+ };
5172
+ function serviceOf(name) {
5173
+ const leaf = name.replace(/^.*[\\/]/, "").replace(/\.service$/, "").replace(/@.*$/, "");
5174
+ const lower2 = leaf.toLowerCase();
5175
+ return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? UNIT_ALIASES[lower2] ?? null;
5176
+ }
5177
+
5013
5178
  // src/shell/inline-code.ts
5014
5179
  var MAX_INLINE_CODE = 64 * 1024;
5015
5180
  var WHAT = {
@@ -5022,8 +5187,22 @@ var WHAT = {
5022
5187
  "builds-code": "runs code it builds at run time",
5023
5188
  permissions: "changes permissions or ownership",
5024
5189
  monitors: "captures the screen, the clipboard or the keyboard",
5025
- amplifies: "writes or sends in an endless loop"
5190
+ amplifies: "writes or sends in an endless loop",
5191
+ "kills-service": "stops a system service"
5192
+ };
5193
+ var KILL_API = {
5194
+ python: /\bos\.kill(?:pg)?\s*\(|\.(?:kill|terminate)\s*\(|\bsignal\.SIGKILL\b/,
5195
+ node: /\bprocess\.kill\s*\(|\.kill\s*\(\s*['"`]?SIG/,
5196
+ perl: /\bkill\s+(?:-?\d+|['"]?[A-Z]+['"]?)\s*,/,
5197
+ ruby: /\bProcess\.kill\b/,
5198
+ php: /\bposix_kill\s*\(/
5026
5199
  };
5200
+ function killsService(language, code) {
5201
+ const api = KILL_API[language].exec(code);
5202
+ if (!api) return null;
5203
+ const service = serviceNamedIn(code);
5204
+ return service ? `${api[0].trim()} with ${service}` : null;
5205
+ }
5027
5206
  var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
5028
5207
  var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
5029
5208
  var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
@@ -5313,6 +5492,15 @@ function judgeInlineCode(language, code, isProtected) {
5313
5492
  return { outcome: "unreadable", what: "is too long for node9 to read" };
5314
5493
  }
5315
5494
  const text = language === "python" ? resolvePythonAliases(code) : code;
5495
+ const killed = killsService(language, text);
5496
+ if (killed) {
5497
+ return {
5498
+ outcome: "dangerous",
5499
+ what: WHAT["kills-service"],
5500
+ evidence: killed.slice(0, 60),
5501
+ category: "kills-service"
5502
+ };
5503
+ }
5316
5504
  for (const [category, re] of TABLES[language]) {
5317
5505
  const m = re.exec(text);
5318
5506
  if (!m) continue;
@@ -15159,8 +15347,16 @@ function evaluateGitHooksFileAccess(args, accesses, context, settings, shell) {
15159
15347
  disarms = true;
15160
15348
  how = "removed";
15161
15349
  } else if (texts === null) {
15162
- disarms = true;
15163
- how = "overwritten";
15350
+ if (access.edits) {
15351
+ disarms = access.edits.some(editDisarms);
15352
+ how = "edited to exit";
15353
+ } else if (access.text !== void 0) {
15354
+ disarms = hookTextRunsNothing(access.text);
15355
+ how = "emptied";
15356
+ } else {
15357
+ disarms = true;
15358
+ how = "overwritten";
15359
+ }
15164
15360
  } else if (texts.whole.length > 0) {
15165
15361
  disarms = texts.whole.some(hookTextRunsNothing);
15166
15362
  how = "emptied";
@@ -17417,6 +17613,7 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
17417
17613
  "commands.sql-no-where",
17418
17614
  "commands.temp-binary",
17419
17615
  "commands.disk-destroy",
17616
+ "commands.system-processes",
17420
17617
  "commands.dangerous-word",
17421
17618
  "commands.node9-disarm",
17422
17619
  "commands.reverse-shell",
@@ -18128,6 +18325,126 @@ function scanArgumentSecrets(args) {
18128
18325
  } : null;
18129
18326
  }
18130
18327
 
18328
+ // src/shell/processes.ts
18329
+ var PRESCREEN_RE3 = /\b(?:kill|pkill|killall|systemctl|service|launchctl|xargs)\b/;
18330
+ var KILL_SIGNAL_RE = /^-(?:\d+|s|SIG[A-Z]+|[A-Z]{2,})$/;
18331
+ var SYSTEMCTL_STOP_VERBS = /* @__PURE__ */ new Set(["stop", "kill", "disable", "mask"]);
18332
+ var LAUNCHCTL_UNLOAD_VERBS = /* @__PURE__ */ new Set(["unload", "bootout", "remove"]);
18333
+ var LAUNCH_DAEMONS_RE = /(?:^|\/)(?:System\/)?Library\/LaunchDaemons\//;
18334
+ var MAX_PAYLOAD_DEPTH5 = 3;
18335
+ function shownOf2(words) {
18336
+ return words.map((w) => w ?? "$?").join(" ").slice(0, 80);
18337
+ }
18338
+ function withoutComments(command) {
18339
+ return command.split("\n").map((line) => {
18340
+ for (let i = 0; i < line.length; i++) {
18341
+ if (line[i] === "#" && (i === 0 || line[i - 1] === " " || line[i - 1] === " ")) {
18342
+ return line.slice(0, i);
18343
+ }
18344
+ }
18345
+ return line;
18346
+ }).join("\n");
18347
+ }
18348
+ function detectSystemProcessStop(command, depth = 0) {
18349
+ if (!PRESCREEN_RE3.test(command)) return null;
18350
+ const named = serviceNamedIn(withoutComments(command));
18351
+ let direct = null;
18352
+ let dynamicKill = null;
18353
+ walkCommandScope(command, (node) => {
18354
+ const n = node;
18355
+ if (direct || !n || n.kind !== "CallExpr") return true;
18356
+ const words = (n.Args || []).map((a) => resolveWordLiteral(a));
18357
+ if (words.length === 0) return true;
18358
+ if (baseWord(words[0]) === "xargs" && words.some((w) => w !== null && baseWord(w) === "kill")) {
18359
+ dynamicKill ??= shownOf2(words);
18360
+ return true;
18361
+ }
18362
+ if (depth < MAX_PAYLOAD_DEPTH5) {
18363
+ const payload = literalShellPayload(words, baseWord(words[0]));
18364
+ if (payload !== null) {
18365
+ const inner = detectSystemProcessStop(payload, depth + 1);
18366
+ if (inner) direct = inner;
18367
+ return true;
18368
+ }
18369
+ }
18370
+ const head = unwrapCommandHead(words);
18371
+ if (head >= words.length) return true;
18372
+ const name = baseWord(words[head]);
18373
+ const rest = words.slice(head + 1);
18374
+ const shown = shownOf2(words);
18375
+ const viaXargs = words.slice(0, head).some((w) => w !== null && baseWord(w) === "xargs");
18376
+ if (name === "kill") {
18377
+ const targets = [];
18378
+ for (let i = 0; i < rest.length; i++) {
18379
+ const w = rest[i];
18380
+ if (i === 0 && w !== null && KILL_SIGNAL_RE.test(w)) {
18381
+ if (w === "-s") i++;
18382
+ continue;
18383
+ }
18384
+ if (w === "--") continue;
18385
+ targets.push(w);
18386
+ }
18387
+ if (targets.some((t) => t === "1" || t === "-1")) {
18388
+ direct = { service: "init (pid 1)", how: "kills", shown };
18389
+ } else if (viaXargs || targets.some((t) => t === null)) {
18390
+ dynamicKill ??= shown;
18391
+ }
18392
+ return true;
18393
+ }
18394
+ if (name === "pkill" || name === "killall") {
18395
+ let skipValue = false;
18396
+ for (const w of rest) {
18397
+ if (skipValue) {
18398
+ skipValue = false;
18399
+ continue;
18400
+ }
18401
+ if (w !== null && w.startsWith("-")) {
18402
+ if (/^-(?:u|U|g|G|t|P|s|n|o|r|q|-signal|-uid|-user)$/.test(w)) skipValue = true;
18403
+ continue;
18404
+ }
18405
+ if (w === null) {
18406
+ dynamicKill ??= shown;
18407
+ continue;
18408
+ }
18409
+ const service = serviceOf(w) ?? serviceNamedIn(w);
18410
+ if (service) direct = { service, how: "kills", shown };
18411
+ }
18412
+ return true;
18413
+ }
18414
+ if (name === "systemctl") {
18415
+ if (rest.includes("--user")) return true;
18416
+ const verb = rest.find((w) => w !== null && !w.startsWith("-"));
18417
+ if (verb === void 0 || verb === null || !SYSTEMCTL_STOP_VERBS.has(verb)) return true;
18418
+ for (const w of rest.slice(rest.indexOf(verb) + 1)) {
18419
+ const service = w === null ? null : serviceOf(w);
18420
+ if (service) direct = { service, how: verb === "kill" ? "kills" : "stops", shown };
18421
+ }
18422
+ return true;
18423
+ }
18424
+ if (name === "service") {
18425
+ const [unit, verb] = rest;
18426
+ const service = typeof unit === "string" ? serviceOf(unit) : null;
18427
+ if (service && verb === "stop") direct = { service, how: "stops", shown };
18428
+ return true;
18429
+ }
18430
+ if (name === "launchctl") {
18431
+ const verb = rest.find((w) => w !== null && !w.startsWith("-"));
18432
+ if (verb === void 0 || verb === null || !LAUNCHCTL_UNLOAD_VERBS.has(verb)) return true;
18433
+ const daemon = rest.find((w) => w !== null && LAUNCH_DAEMONS_RE.test(w));
18434
+ if (daemon) {
18435
+ direct = { service: daemon.replace(/^.*\//, ""), how: "unloads the system daemon", shown };
18436
+ }
18437
+ return true;
18438
+ }
18439
+ return true;
18440
+ });
18441
+ if (direct) return direct;
18442
+ if (dynamicKill !== null && named) {
18443
+ return { service: named, how: "kills the processes of", shown: dynamicKill };
18444
+ }
18445
+ return null;
18446
+ }
18447
+
18131
18448
  // src/shell/node9-disarm.ts
18132
18449
  var RULE_NAME2 = "review-node9-disarm";
18133
18450
  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.";
@@ -18803,6 +19120,17 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
18803
19120
  checkId: "commands.eval-dynamic"
18804
19121
  });
18805
19122
  }
19123
+ const stopped = detectSystemProcessStop(shellCommand);
19124
+ if (stopped) {
19125
+ consider("commands.system-processes", {
19126
+ decision: "review",
19127
+ blockedByLabel: "Node9: System Service Stopped",
19128
+ reason: `The AI ${stopped.how} ${stopped.service}: ${stopped.shown}`,
19129
+ ruleDescription: "The AI stops or kills a system service (sshd, dockerd, systemd, a database or web server). Other people and programs on this machine depend on it; confirm this is intentional.",
19130
+ tier: 3,
19131
+ checkId: "commands.system-processes"
19132
+ });
19133
+ }
18806
19134
  const builtin = strictestVerdict(candidates);
18807
19135
  if (builtin) return builtin;
18808
19136
  {
@@ -20276,7 +20604,8 @@ function classifyRuleSeverity(name, verdict) {
20276
20604
  "rebase",
20277
20605
  "delete-branch",
20278
20606
  "delete-remote",
20279
- "unknown-registry"
20607
+ "unknown-registry",
20608
+ "system-processes"
20280
20609
  ];
20281
20610
  if (highPatterns.some((p) => n.includes(p))) return "high";
20282
20611
  if (verdict === "block") return "high";
@@ -20316,6 +20645,7 @@ function narrativeRuleLabel(name) {
20316
20645
  "reverse-shell": "reverse shell",
20317
20646
  "env-exfil": "environment sent out",
20318
20647
  "unknown-registry": "install from an unknown registry",
20648
+ "system-processes": "system service stopped",
20319
20649
  "agent-file-write": "agent instruction file written",
20320
20650
  "agent-file-content": "instruction written into an agent file",
20321
20651
  "agent-hooks-change": "agent hooks changed",
@@ -20628,7 +20958,7 @@ function matchCanaryArgs(args, values) {
20628
20958
  // src/scan/canonical.ts
20629
20959
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
20630
20960
  var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
20631
- var CANONICAL_EXTRACTOR_HASH = "5ec00461a49e1858";
20961
+ var CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
20632
20962
  var DEDUPE_PREVIEW_LEN = 120;
20633
20963
  function extractCanonicalFindings(call, ctx) {
20634
20964
  const out = [];
package/dist/index.mjs CHANGED
@@ -2303,6 +2303,11 @@ var CHECK_TEXT = {
2303
2303
  example: "/tmp/build-helper --serve",
2304
2304
  advice: "Keep Review. Malware often runs from /tmp."
2305
2305
  },
2306
+ "commands.system-processes": {
2307
+ plain: "The agent stops or kills a system service: sshd, dockerd, containerd, systemd, kubelet, cron, the firewall, the display server, or a database or web server (nginx, apache, mysql, postgres, redis, mongo). Directly (pkill sshd, systemctl stop docker, kill of pid 1) or through the process list (a script that finds the processes of a name and kills them). Killing a process by its number, pkill node, killall python and systemctl restart are not this check.",
2308
+ example: "ps -eo pid,cmd | grep sshd | awk '{print $1}' | xargs kill -9",
2309
+ advice: "Keep Review: a stopped service takes other people and programs down with it. Set Log on a machine where agents manage local servers all day."
2310
+ },
2306
2311
  "commands.disk-destroy": {
2307
2312
  plain: "The agent formats, overwrites or securely erases a disk or file.",
2308
2313
  example: "dd if=/dev/zero of=/dev/sda",
@@ -2499,6 +2504,7 @@ var SOFT = {
2499
2504
  "commands.sql-no-where": "log",
2500
2505
  "commands.temp-binary": "log",
2501
2506
  "commands.disk-destroy": "log",
2507
+ "commands.system-processes": "log",
2502
2508
  "commands.dangerous-word": "log",
2503
2509
  "files.system-dirs": "log",
2504
2510
  "files.shell-startup": "log",
@@ -2908,6 +2914,16 @@ var PRODUCT_CHECKS = [
2908
2914
  defaultValue: "review",
2909
2915
  legacy: ["Manual Nuclear Protection"]
2910
2916
  },
2917
+ {
2918
+ id: "commands.system-processes",
2919
+ group: "commands",
2920
+ owasp: "ASI02",
2921
+ title: "Stops a system service",
2922
+ catches: "kill, pkill, killall, systemctl stop or kill, service stop or launchctl unload aimed at a system service (sshd, dockerd, systemd, kubelet, cron, a database or web server), or a script that walks the process list for one of those names and kills what it finds",
2923
+ values: ALL,
2924
+ defaultValue: "review",
2925
+ legacy: ["Node9: System Service Stopped"]
2926
+ },
2911
2927
  {
2912
2928
  id: "commands.dangerous-word",
2913
2929
  group: "commands",
@@ -4019,12 +4035,46 @@ function wordValues(word, state) {
4019
4035
  if (!dynamic) return out.map(asWord);
4020
4036
  return out.filter((piece) => piece.value !== "").map((piece) => ({ value: piece.value, pattern: piece.pattern + "*", dynamic: true }));
4021
4037
  }
4038
+ function sedSubstitutions(script) {
4039
+ const out = [];
4040
+ for (const raw of script.split(/\r?\n|;/)) {
4041
+ const cmd = raw.trim();
4042
+ if (cmd === "") continue;
4043
+ const m = /^(?:(?:\d+|\$|\/(?:\\.|[^\\/])*\/)(?:,(?:\d+|\$|\/(?:\\.|[^\\/])*\/))?)?s(.)/.exec(
4044
+ cmd
4045
+ );
4046
+ if (!m) return null;
4047
+ const delimiter = m[1];
4048
+ if (delimiter === "\\") return null;
4049
+ const parts = [];
4050
+ let cur = "";
4051
+ let i = m[0].length;
4052
+ for (; i < cmd.length && parts.length < 2; i++) {
4053
+ const ch = cmd[i];
4054
+ if (ch === "\\" && i + 1 < cmd.length) {
4055
+ cur += ch + cmd[++i];
4056
+ continue;
4057
+ }
4058
+ if (ch === delimiter) {
4059
+ parts.push(cur);
4060
+ cur = "";
4061
+ continue;
4062
+ }
4063
+ cur += ch;
4064
+ }
4065
+ if (parts.length < 2) return null;
4066
+ if (!/^[gpiImM0-9]*$/.test(cmd.slice(i))) return null;
4067
+ out.push(parts[1].replace(/\\(.)/g, "$1"));
4068
+ }
4069
+ return out.length > 0 ? out : null;
4070
+ }
4022
4071
  function collectShellFileAccesses(command, context = {}) {
4023
4072
  const out = [];
4024
4073
  let payloads = 256;
4025
4074
  const functions = /* @__PURE__ */ new Map();
4026
4075
  const seenCalls = /* @__PURE__ */ new Set();
4027
4076
  const pipedStdin = /* @__PURE__ */ new WeakMap();
4077
+ let currentStdin = null;
4028
4078
  let callWalks2 = MAX_CALL_WALKS;
4029
4079
  const initial = {
4030
4080
  cwd: [context.cwd ?? ""],
@@ -4119,8 +4169,9 @@ function collectShellFileAccesses(command, context = {}) {
4119
4169
  }
4120
4170
  const locate = (p) => tokens.find((w) => w?.value === p) ?? { value: p };
4121
4171
  if (name === "sed") {
4122
- let inplace = false, hasScript = false, ended = false;
4172
+ let inplace = false, hasScript = false, ended = false, scriptUnknown = false;
4123
4173
  const files = [];
4174
+ const scriptParts = [];
4124
4175
  for (let i = 0; i < args.length; i++) {
4125
4176
  const token = args[i];
4126
4177
  if (!token) {
@@ -4138,7 +4189,11 @@ function collectShellFileAccesses(command, context = {}) {
4138
4189
  hasScript = true;
4139
4190
  const eq = value.indexOf("=");
4140
4191
  const script = eq < 0 ? args[++i] : { value: value.slice(eq + 1) };
4141
- if (value.startsWith("--file") && script) add("read", script, state);
4192
+ if (value.startsWith("--file")) {
4193
+ scriptUnknown = true;
4194
+ if (script) add("read", script, state);
4195
+ } else if (script?.value) scriptParts.push(script.value);
4196
+ else scriptUnknown = true;
4142
4197
  }
4143
4198
  continue;
4144
4199
  }
@@ -4153,7 +4208,11 @@ function collectShellFileAccesses(command, context = {}) {
4153
4208
  if (flag === "e" || flag === "f") {
4154
4209
  hasScript = true;
4155
4210
  const script = value.slice(j + 1) ? { value: value.slice(j + 1) } : args[++i];
4156
- if (flag === "f" && script) add("read", script, state);
4211
+ if (flag === "f") {
4212
+ scriptUnknown = true;
4213
+ if (script) add("read", script, state);
4214
+ } else if (script?.value) scriptParts.push(script.value);
4215
+ else scriptUnknown = true;
4157
4216
  break;
4158
4217
  }
4159
4218
  if (flag === "l") {
@@ -4163,10 +4222,14 @@ function collectShellFileAccesses(command, context = {}) {
4163
4222
  }
4164
4223
  continue;
4165
4224
  }
4166
- if (!hasScript) hasScript = true;
4167
- else files.push(token);
4225
+ if (!hasScript) {
4226
+ hasScript = true;
4227
+ scriptParts.push(value);
4228
+ } else files.push(token);
4168
4229
  }
4169
- for (const file of files) add(inplace ? "write" : "read", file, state);
4230
+ const edits = inplace && !scriptUnknown ? sedSubstitutions(scriptParts.join("\n")) : null;
4231
+ for (const file of files)
4232
+ add(inplace ? "write" : "read", file, state, edits ? { edits } : {});
4170
4233
  return;
4171
4234
  }
4172
4235
  if (FS_READ_TOOLS.has(name) && name !== "dd") {
@@ -4293,9 +4356,11 @@ function collectShellFileAccesses(command, context = {}) {
4293
4356
  continue;
4294
4357
  const remove = name === "rm" || name === "unlink";
4295
4358
  const append = name === "tee" && strings.some((s) => s === "--append" || /^-[^-]*a/.test(s));
4359
+ const teed = name === "tee" && !append ? currentStdin : null;
4296
4360
  add(remove ? "remove" : name === "touch" ? "create" : "write", token, state, {
4297
4361
  recursive: remove && strings.some((s) => /^-[^-]*[rR]/.test(s) || s === "--recursive"),
4298
- ...append ? { append: true } : {}
4362
+ ...append ? { append: true } : {},
4363
+ ...teed !== null ? { text: teed } : {}
4299
4364
  });
4300
4365
  }
4301
4366
  return;
@@ -4617,11 +4682,18 @@ function collectShellFileAccesses(command, context = {}) {
4617
4682
  if (stmt.Background) state = clone(state);
4618
4683
  const headWord = stmt.Cmd && stmt.Cmd.kind === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
4619
4684
  const sends = SENDING_STDIN.has(headWord);
4685
+ let produced;
4620
4686
  for (const redir of stmt.Redirs ?? []) {
4621
4687
  substitutions(redir.Word, state, depth);
4622
4688
  for (const word of wordValues(redir.Word, state)) {
4623
- if (ops().WRITES.has(redir.Op))
4624
- add("write", word, state, ops().APPENDS.has(redir.Op) ? { append: true } : {});
4689
+ if (ops().WRITES.has(redir.Op)) {
4690
+ if (ops().APPENDS.has(redir.Op)) add("write", word, state, { append: true });
4691
+ else {
4692
+ const stdout = redir.N == null || redir.N.Value === "1";
4693
+ if (stdout && produced === void 0) produced = producedText(stmt);
4694
+ add("write", word, state, stdout && produced ? { text: produced } : {});
4695
+ }
4696
+ }
4625
4697
  if (ops().READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
4626
4698
  if (redir.Op === ops().DUP_OUT && word.value && !/^\d+$/.test(word.value))
4627
4699
  add("write", word, state);
@@ -4633,6 +4705,7 @@ function collectShellFileAccesses(command, context = {}) {
4633
4705
  stdinScript(stmt, state, depth);
4634
4706
  const fedText = stdinText(stmt);
4635
4707
  if (fedText !== null) nestedPayload(xargsPayload(stmt, fedText), clone(state), depth);
4708
+ currentStdin = fedText;
4636
4709
  switch (cmd.kind) {
4637
4710
  case "CallExpr":
4638
4711
  call(cmd, state, depth);
@@ -4747,6 +4820,98 @@ function collectShellFileAccesses(command, context = {}) {
4747
4820
  return out;
4748
4821
  }
4749
4822
 
4823
+ // src/shell/services.ts
4824
+ var INFRASTRUCTURE_SERVICES = [
4825
+ "init",
4826
+ "sshd",
4827
+ "dockerd",
4828
+ "docker-proxy",
4829
+ "containerd",
4830
+ "containerd-shim",
4831
+ "docker-containerd-shim",
4832
+ "runc",
4833
+ "systemd-journald",
4834
+ "journald",
4835
+ "systemd-logind",
4836
+ "systemd-udevd",
4837
+ "udevd",
4838
+ "dbus-daemon",
4839
+ "polkitd",
4840
+ "sssd",
4841
+ "kubelet",
4842
+ "kube-apiserver",
4843
+ "crond",
4844
+ "cron",
4845
+ "atd",
4846
+ "auditd",
4847
+ "rsyslogd",
4848
+ "syslogd",
4849
+ "chronyd",
4850
+ "ntpd",
4851
+ "NetworkManager",
4852
+ "wpa_supplicant",
4853
+ "dhclient",
4854
+ "avahi-daemon",
4855
+ "firewalld",
4856
+ "ufw",
4857
+ "cupsd",
4858
+ "snapd",
4859
+ "bluetoothd",
4860
+ "Xorg",
4861
+ "Xwayland",
4862
+ "gdm",
4863
+ "sddm",
4864
+ "lightdm"
4865
+ ];
4866
+ var SERVER_SERVICES = [
4867
+ "nginx",
4868
+ "apache2",
4869
+ "httpd",
4870
+ "mysqld",
4871
+ "mariadbd",
4872
+ "postgres",
4873
+ "postgresql",
4874
+ "redis-server",
4875
+ "mongod"
4876
+ ];
4877
+ var SYSTEM_SERVICES = [...INFRASTRUCTURE_SERVICES, ...SERVER_SERVICES];
4878
+ var escape = (s) => s.replace(/[.*+?^${}()|[\]\\-]/g, "\\$&");
4879
+ var SERVICE_WORD_RE = new RegExp(
4880
+ `(?:^|[^A-Za-z0-9_.-])(${SYSTEM_SERVICES.map(escape).join("|")})(?![A-Za-z0-9_.-])`,
4881
+ "i"
4882
+ );
4883
+ var INIT_PATTERN_RE = /(?:["'*])init(?:["'*])/;
4884
+ function serviceNamedIn(text) {
4885
+ const re = new RegExp(SERVICE_WORD_RE.source, "gi");
4886
+ for (let m = re.exec(text); m; m = re.exec(text)) {
4887
+ const lower2 = m[1].toLowerCase();
4888
+ if (lower2 === "init" && !INIT_PATTERN_RE.test(text)) continue;
4889
+ return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? m[1];
4890
+ }
4891
+ return null;
4892
+ }
4893
+ var UNIT_ALIASES = {
4894
+ docker: "dockerd",
4895
+ ssh: "sshd",
4896
+ mysql: "mysqld",
4897
+ mariadb: "mariadbd",
4898
+ redis: "redis-server",
4899
+ mongodb: "mongod",
4900
+ apache: "apache2",
4901
+ rsyslog: "rsyslogd",
4902
+ "systemd-networkd": "systemd-udevd",
4903
+ dbus: "dbus-daemon",
4904
+ avahi: "avahi-daemon",
4905
+ bluetooth: "bluetoothd",
4906
+ cups: "cupsd",
4907
+ chrony: "chronyd"
4908
+ };
4909
+ function serviceOf(name) {
4910
+ const leaf = name.replace(/^.*[\\/]/, "").replace(/\.service$/, "").replace(/@.*$/, "");
4911
+ const lower2 = leaf.toLowerCase();
4912
+ return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? UNIT_ALIASES[lower2] ?? null;
4913
+ }
4914
+
4750
4915
  // src/shell/inline-code.ts
4751
4916
  var MAX_INLINE_CODE = 64 * 1024;
4752
4917
  var WHAT = {
@@ -4759,8 +4924,22 @@ var WHAT = {
4759
4924
  "builds-code": "runs code it builds at run time",
4760
4925
  permissions: "changes permissions or ownership",
4761
4926
  monitors: "captures the screen, the clipboard or the keyboard",
4762
- amplifies: "writes or sends in an endless loop"
4927
+ amplifies: "writes or sends in an endless loop",
4928
+ "kills-service": "stops a system service"
4929
+ };
4930
+ var KILL_API = {
4931
+ python: /\bos\.kill(?:pg)?\s*\(|\.(?:kill|terminate)\s*\(|\bsignal\.SIGKILL\b/,
4932
+ node: /\bprocess\.kill\s*\(|\.kill\s*\(\s*['"`]?SIG/,
4933
+ perl: /\bkill\s+(?:-?\d+|['"]?[A-Z]+['"]?)\s*,/,
4934
+ ruby: /\bProcess\.kill\b/,
4935
+ php: /\bposix_kill\s*\(/
4763
4936
  };
4937
+ function killsService(language, code) {
4938
+ const api = KILL_API[language].exec(code);
4939
+ if (!api) return null;
4940
+ const service = serviceNamedIn(code);
4941
+ return service ? `${api[0].trim()} with ${service}` : null;
4942
+ }
4764
4943
  var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
4765
4944
  var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
4766
4945
  var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
@@ -5050,6 +5229,15 @@ function judgeInlineCode(language, code, isProtected) {
5050
5229
  return { outcome: "unreadable", what: "is too long for node9 to read" };
5051
5230
  }
5052
5231
  const text = language === "python" ? resolvePythonAliases(code) : code;
5232
+ const killed = killsService(language, text);
5233
+ if (killed) {
5234
+ return {
5235
+ outcome: "dangerous",
5236
+ what: WHAT["kills-service"],
5237
+ evidence: killed.slice(0, 60),
5238
+ category: "kills-service"
5239
+ };
5240
+ }
5053
5241
  for (const [category, re] of TABLES[language]) {
5054
5242
  const m = re.exec(text);
5055
5243
  if (!m) continue;
@@ -14896,8 +15084,16 @@ function evaluateGitHooksFileAccess(args, accesses, context, settings, shell) {
14896
15084
  disarms = true;
14897
15085
  how = "removed";
14898
15086
  } else if (texts === null) {
14899
- disarms = true;
14900
- how = "overwritten";
15087
+ if (access.edits) {
15088
+ disarms = access.edits.some(editDisarms);
15089
+ how = "edited to exit";
15090
+ } else if (access.text !== void 0) {
15091
+ disarms = hookTextRunsNothing(access.text);
15092
+ how = "emptied";
15093
+ } else {
15094
+ disarms = true;
15095
+ how = "overwritten";
15096
+ }
14901
15097
  } else if (texts.whole.length > 0) {
14902
15098
  disarms = texts.whole.some(hookTextRunsNothing);
14903
15099
  how = "emptied";
@@ -17154,6 +17350,7 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
17154
17350
  "commands.sql-no-where",
17155
17351
  "commands.temp-binary",
17156
17352
  "commands.disk-destroy",
17353
+ "commands.system-processes",
17157
17354
  "commands.dangerous-word",
17158
17355
  "commands.node9-disarm",
17159
17356
  "commands.reverse-shell",
@@ -17865,6 +18062,126 @@ function scanArgumentSecrets(args) {
17865
18062
  } : null;
17866
18063
  }
17867
18064
 
18065
+ // src/shell/processes.ts
18066
+ var PRESCREEN_RE3 = /\b(?:kill|pkill|killall|systemctl|service|launchctl|xargs)\b/;
18067
+ var KILL_SIGNAL_RE = /^-(?:\d+|s|SIG[A-Z]+|[A-Z]{2,})$/;
18068
+ var SYSTEMCTL_STOP_VERBS = /* @__PURE__ */ new Set(["stop", "kill", "disable", "mask"]);
18069
+ var LAUNCHCTL_UNLOAD_VERBS = /* @__PURE__ */ new Set(["unload", "bootout", "remove"]);
18070
+ var LAUNCH_DAEMONS_RE = /(?:^|\/)(?:System\/)?Library\/LaunchDaemons\//;
18071
+ var MAX_PAYLOAD_DEPTH5 = 3;
18072
+ function shownOf2(words) {
18073
+ return words.map((w) => w ?? "$?").join(" ").slice(0, 80);
18074
+ }
18075
+ function withoutComments(command) {
18076
+ return command.split("\n").map((line) => {
18077
+ for (let i = 0; i < line.length; i++) {
18078
+ if (line[i] === "#" && (i === 0 || line[i - 1] === " " || line[i - 1] === " ")) {
18079
+ return line.slice(0, i);
18080
+ }
18081
+ }
18082
+ return line;
18083
+ }).join("\n");
18084
+ }
18085
+ function detectSystemProcessStop(command, depth = 0) {
18086
+ if (!PRESCREEN_RE3.test(command)) return null;
18087
+ const named = serviceNamedIn(withoutComments(command));
18088
+ let direct = null;
18089
+ let dynamicKill = null;
18090
+ walkCommandScope(command, (node) => {
18091
+ const n = node;
18092
+ if (direct || !n || n.kind !== "CallExpr") return true;
18093
+ const words = (n.Args || []).map((a) => resolveWordLiteral(a));
18094
+ if (words.length === 0) return true;
18095
+ if (baseWord(words[0]) === "xargs" && words.some((w) => w !== null && baseWord(w) === "kill")) {
18096
+ dynamicKill ??= shownOf2(words);
18097
+ return true;
18098
+ }
18099
+ if (depth < MAX_PAYLOAD_DEPTH5) {
18100
+ const payload = literalShellPayload(words, baseWord(words[0]));
18101
+ if (payload !== null) {
18102
+ const inner = detectSystemProcessStop(payload, depth + 1);
18103
+ if (inner) direct = inner;
18104
+ return true;
18105
+ }
18106
+ }
18107
+ const head = unwrapCommandHead(words);
18108
+ if (head >= words.length) return true;
18109
+ const name = baseWord(words[head]);
18110
+ const rest = words.slice(head + 1);
18111
+ const shown = shownOf2(words);
18112
+ const viaXargs = words.slice(0, head).some((w) => w !== null && baseWord(w) === "xargs");
18113
+ if (name === "kill") {
18114
+ const targets = [];
18115
+ for (let i = 0; i < rest.length; i++) {
18116
+ const w = rest[i];
18117
+ if (i === 0 && w !== null && KILL_SIGNAL_RE.test(w)) {
18118
+ if (w === "-s") i++;
18119
+ continue;
18120
+ }
18121
+ if (w === "--") continue;
18122
+ targets.push(w);
18123
+ }
18124
+ if (targets.some((t) => t === "1" || t === "-1")) {
18125
+ direct = { service: "init (pid 1)", how: "kills", shown };
18126
+ } else if (viaXargs || targets.some((t) => t === null)) {
18127
+ dynamicKill ??= shown;
18128
+ }
18129
+ return true;
18130
+ }
18131
+ if (name === "pkill" || name === "killall") {
18132
+ let skipValue = false;
18133
+ for (const w of rest) {
18134
+ if (skipValue) {
18135
+ skipValue = false;
18136
+ continue;
18137
+ }
18138
+ if (w !== null && w.startsWith("-")) {
18139
+ if (/^-(?:u|U|g|G|t|P|s|n|o|r|q|-signal|-uid|-user)$/.test(w)) skipValue = true;
18140
+ continue;
18141
+ }
18142
+ if (w === null) {
18143
+ dynamicKill ??= shown;
18144
+ continue;
18145
+ }
18146
+ const service = serviceOf(w) ?? serviceNamedIn(w);
18147
+ if (service) direct = { service, how: "kills", shown };
18148
+ }
18149
+ return true;
18150
+ }
18151
+ if (name === "systemctl") {
18152
+ if (rest.includes("--user")) return true;
18153
+ const verb = rest.find((w) => w !== null && !w.startsWith("-"));
18154
+ if (verb === void 0 || verb === null || !SYSTEMCTL_STOP_VERBS.has(verb)) return true;
18155
+ for (const w of rest.slice(rest.indexOf(verb) + 1)) {
18156
+ const service = w === null ? null : serviceOf(w);
18157
+ if (service) direct = { service, how: verb === "kill" ? "kills" : "stops", shown };
18158
+ }
18159
+ return true;
18160
+ }
18161
+ if (name === "service") {
18162
+ const [unit, verb] = rest;
18163
+ const service = typeof unit === "string" ? serviceOf(unit) : null;
18164
+ if (service && verb === "stop") direct = { service, how: "stops", shown };
18165
+ return true;
18166
+ }
18167
+ if (name === "launchctl") {
18168
+ const verb = rest.find((w) => w !== null && !w.startsWith("-"));
18169
+ if (verb === void 0 || verb === null || !LAUNCHCTL_UNLOAD_VERBS.has(verb)) return true;
18170
+ const daemon = rest.find((w) => w !== null && LAUNCH_DAEMONS_RE.test(w));
18171
+ if (daemon) {
18172
+ direct = { service: daemon.replace(/^.*\//, ""), how: "unloads the system daemon", shown };
18173
+ }
18174
+ return true;
18175
+ }
18176
+ return true;
18177
+ });
18178
+ if (direct) return direct;
18179
+ if (dynamicKill !== null && named) {
18180
+ return { service: named, how: "kills the processes of", shown: dynamicKill };
18181
+ }
18182
+ return null;
18183
+ }
18184
+
17868
18185
  // src/shell/node9-disarm.ts
17869
18186
  var RULE_NAME2 = "review-node9-disarm";
17870
18187
  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.";
@@ -18540,6 +18857,17 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
18540
18857
  checkId: "commands.eval-dynamic"
18541
18858
  });
18542
18859
  }
18860
+ const stopped = detectSystemProcessStop(shellCommand);
18861
+ if (stopped) {
18862
+ consider("commands.system-processes", {
18863
+ decision: "review",
18864
+ blockedByLabel: "Node9: System Service Stopped",
18865
+ reason: `The AI ${stopped.how} ${stopped.service}: ${stopped.shown}`,
18866
+ ruleDescription: "The AI stops or kills a system service (sshd, dockerd, systemd, a database or web server). Other people and programs on this machine depend on it; confirm this is intentional.",
18867
+ tier: 3,
18868
+ checkId: "commands.system-processes"
18869
+ });
18870
+ }
18543
18871
  const builtin = strictestVerdict(candidates);
18544
18872
  if (builtin) return builtin;
18545
18873
  {
@@ -20013,7 +20341,8 @@ function classifyRuleSeverity(name, verdict) {
20013
20341
  "rebase",
20014
20342
  "delete-branch",
20015
20343
  "delete-remote",
20016
- "unknown-registry"
20344
+ "unknown-registry",
20345
+ "system-processes"
20017
20346
  ];
20018
20347
  if (highPatterns.some((p) => n.includes(p))) return "high";
20019
20348
  if (verdict === "block") return "high";
@@ -20053,6 +20382,7 @@ function narrativeRuleLabel(name) {
20053
20382
  "reverse-shell": "reverse shell",
20054
20383
  "env-exfil": "environment sent out",
20055
20384
  "unknown-registry": "install from an unknown registry",
20385
+ "system-processes": "system service stopped",
20056
20386
  "agent-file-write": "agent instruction file written",
20057
20387
  "agent-file-content": "instruction written into an agent file",
20058
20388
  "agent-hooks-change": "agent hooks changed",
@@ -20365,7 +20695,7 @@ function matchCanaryArgs(args, values) {
20365
20695
  // src/scan/canonical.ts
20366
20696
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
20367
20697
  var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
20368
- var CANONICAL_EXTRACTOR_HASH = "5ec00461a49e1858";
20698
+ var CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
20369
20699
  var DEDUPE_PREVIEW_LEN = 120;
20370
20700
  function extractCanonicalFindings(call, ctx) {
20371
20701
  const out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/policy-engine",
3
- "version": "2.54.0",
3
+ "version": "2.55.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",