@node9/policy-engine 2.54.1 → 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
@@ -512,7 +512,7 @@ declare function checkValue(settings: CatalogSettings, id: string): Verdict;
512
512
  * stores this on its config so every reader sees the same answers. */
513
513
  declare function resolveCheckMap(settings: CatalogSettings): Record<string, Verdict>;
514
514
 
515
- 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';
516
516
 
517
517
  /**
518
518
  * The POSIX reading of a command. Kept as the single-string API every existing
@@ -2455,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
2455
2455
  * files changed, this hash must change too, and you must consciously
2456
2456
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2457
2457
  */
2458
- declare const CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
2458
+ declare const CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
2459
2459
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2460
2460
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2461
2461
  /**
package/dist/index.d.ts CHANGED
@@ -512,7 +512,7 @@ declare function checkValue(settings: CatalogSettings, id: string): Verdict;
512
512
  * stores this on its config so every reader sees the same answers. */
513
513
  declare function resolveCheckMap(settings: CatalogSettings): Record<string, Verdict>;
514
514
 
515
- 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';
516
516
 
517
517
  /**
518
518
  * The POSIX reading of a command. Kept as the single-string API every existing
@@ -2455,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
2455
2455
  * files changed, this hash must change too, and you must consciously
2456
2456
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2457
2457
  */
2458
- declare const CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
2458
+ declare const CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
2459
2459
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2460
2460
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2461
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",
@@ -5067,6 +5083,98 @@ function collectShellFileAccesses(command, context = {}) {
5067
5083
  return out;
5068
5084
  }
5069
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
+
5070
5178
  // src/shell/inline-code.ts
5071
5179
  var MAX_INLINE_CODE = 64 * 1024;
5072
5180
  var WHAT = {
@@ -5079,8 +5187,22 @@ var WHAT = {
5079
5187
  "builds-code": "runs code it builds at run time",
5080
5188
  permissions: "changes permissions or ownership",
5081
5189
  monitors: "captures the screen, the clipboard or the keyboard",
5082
- 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*\(/
5083
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
+ }
5084
5206
  var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
5085
5207
  var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
5086
5208
  var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
@@ -5370,6 +5492,15 @@ function judgeInlineCode(language, code, isProtected) {
5370
5492
  return { outcome: "unreadable", what: "is too long for node9 to read" };
5371
5493
  }
5372
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
+ }
5373
5504
  for (const [category, re] of TABLES[language]) {
5374
5505
  const m = re.exec(text);
5375
5506
  if (!m) continue;
@@ -17482,6 +17613,7 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
17482
17613
  "commands.sql-no-where",
17483
17614
  "commands.temp-binary",
17484
17615
  "commands.disk-destroy",
17616
+ "commands.system-processes",
17485
17617
  "commands.dangerous-word",
17486
17618
  "commands.node9-disarm",
17487
17619
  "commands.reverse-shell",
@@ -18193,6 +18325,126 @@ function scanArgumentSecrets(args) {
18193
18325
  } : null;
18194
18326
  }
18195
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
+
18196
18448
  // src/shell/node9-disarm.ts
18197
18449
  var RULE_NAME2 = "review-node9-disarm";
18198
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.";
@@ -18868,6 +19120,17 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
18868
19120
  checkId: "commands.eval-dynamic"
18869
19121
  });
18870
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
+ }
18871
19134
  const builtin = strictestVerdict(candidates);
18872
19135
  if (builtin) return builtin;
18873
19136
  {
@@ -20341,7 +20604,8 @@ function classifyRuleSeverity(name, verdict) {
20341
20604
  "rebase",
20342
20605
  "delete-branch",
20343
20606
  "delete-remote",
20344
- "unknown-registry"
20607
+ "unknown-registry",
20608
+ "system-processes"
20345
20609
  ];
20346
20610
  if (highPatterns.some((p) => n.includes(p))) return "high";
20347
20611
  if (verdict === "block") return "high";
@@ -20381,6 +20645,7 @@ function narrativeRuleLabel(name) {
20381
20645
  "reverse-shell": "reverse shell",
20382
20646
  "env-exfil": "environment sent out",
20383
20647
  "unknown-registry": "install from an unknown registry",
20648
+ "system-processes": "system service stopped",
20384
20649
  "agent-file-write": "agent instruction file written",
20385
20650
  "agent-file-content": "instruction written into an agent file",
20386
20651
  "agent-hooks-change": "agent hooks changed",
@@ -20693,7 +20958,7 @@ function matchCanaryArgs(args, values) {
20693
20958
  // src/scan/canonical.ts
20694
20959
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
20695
20960
  var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
20696
- var CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
20961
+ var CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
20697
20962
  var DEDUPE_PREVIEW_LEN = 120;
20698
20963
  function extractCanonicalFindings(call, ctx) {
20699
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",
@@ -4804,6 +4820,98 @@ function collectShellFileAccesses(command, context = {}) {
4804
4820
  return out;
4805
4821
  }
4806
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
+
4807
4915
  // src/shell/inline-code.ts
4808
4916
  var MAX_INLINE_CODE = 64 * 1024;
4809
4917
  var WHAT = {
@@ -4816,8 +4924,22 @@ var WHAT = {
4816
4924
  "builds-code": "runs code it builds at run time",
4817
4925
  permissions: "changes permissions or ownership",
4818
4926
  monitors: "captures the screen, the clipboard or the keyboard",
4819
- 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*\(/
4820
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
+ }
4821
4943
  var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
4822
4944
  var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
4823
4945
  var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
@@ -5107,6 +5229,15 @@ function judgeInlineCode(language, code, isProtected) {
5107
5229
  return { outcome: "unreadable", what: "is too long for node9 to read" };
5108
5230
  }
5109
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
+ }
5110
5241
  for (const [category, re] of TABLES[language]) {
5111
5242
  const m = re.exec(text);
5112
5243
  if (!m) continue;
@@ -17219,6 +17350,7 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
17219
17350
  "commands.sql-no-where",
17220
17351
  "commands.temp-binary",
17221
17352
  "commands.disk-destroy",
17353
+ "commands.system-processes",
17222
17354
  "commands.dangerous-word",
17223
17355
  "commands.node9-disarm",
17224
17356
  "commands.reverse-shell",
@@ -17930,6 +18062,126 @@ function scanArgumentSecrets(args) {
17930
18062
  } : null;
17931
18063
  }
17932
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
+
17933
18185
  // src/shell/node9-disarm.ts
17934
18186
  var RULE_NAME2 = "review-node9-disarm";
17935
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.";
@@ -18605,6 +18857,17 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
18605
18857
  checkId: "commands.eval-dynamic"
18606
18858
  });
18607
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
+ }
18608
18871
  const builtin = strictestVerdict(candidates);
18609
18872
  if (builtin) return builtin;
18610
18873
  {
@@ -20078,7 +20341,8 @@ function classifyRuleSeverity(name, verdict) {
20078
20341
  "rebase",
20079
20342
  "delete-branch",
20080
20343
  "delete-remote",
20081
- "unknown-registry"
20344
+ "unknown-registry",
20345
+ "system-processes"
20082
20346
  ];
20083
20347
  if (highPatterns.some((p) => n.includes(p))) return "high";
20084
20348
  if (verdict === "block") return "high";
@@ -20118,6 +20382,7 @@ function narrativeRuleLabel(name) {
20118
20382
  "reverse-shell": "reverse shell",
20119
20383
  "env-exfil": "environment sent out",
20120
20384
  "unknown-registry": "install from an unknown registry",
20385
+ "system-processes": "system service stopped",
20121
20386
  "agent-file-write": "agent instruction file written",
20122
20387
  "agent-file-content": "instruction written into an agent file",
20123
20388
  "agent-hooks-change": "agent hooks changed",
@@ -20430,7 +20695,7 @@ function matchCanaryArgs(args, values) {
20430
20695
  // src/scan/canonical.ts
20431
20696
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
20432
20697
  var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
20433
- var CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
20698
+ var CANONICAL_EXTRACTOR_HASH = "57bb2a3e73279278";
20434
20699
  var DEDUPE_PREVIEW_LEN = 120;
20435
20700
  function extractCanonicalFindings(call, ctx) {
20436
20701
  const out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/policy-engine",
3
- "version": "2.54.1",
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",