@node9/policy-engine 2.65.7 → 2.65.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -79,12 +79,14 @@ __export(src_exports, {
79
79
  PATTERN_VERB_NAMES: () => PATTERN_VERB_NAMES,
80
80
  POSTURE_CATEGORY_OWASP: () => POSTURE_CATEGORY_OWASP,
81
81
  PRIVILEGE_ESCALATION_RE: () => PRIVILEGE_ESCALATION_RE,
82
+ PUBLIC_SSH_NAME_SOURCE: () => PUBLIC_SSH_NAME_SOURCE,
82
83
  REALTIME_PII_PATTERNS: () => REALTIME_PII_PATTERNS,
83
84
  REPLACED_SHIELDS: () => REPLACED_SHIELDS,
84
85
  SCAN_REPO_RULES_WITHOUT_RISK: () => SCAN_REPO_RULES_WITHOUT_RISK,
85
86
  SCAN_SIGNAL_WEIGHTS: () => SCAN_SIGNAL_WEIGHTS,
86
87
  SENSITIVE_PATH_RE: () => SENSITIVE_PATH_RE,
87
88
  SENSITIVE_PATH_REGEXES: () => SENSITIVE_PATH_REGEXES,
89
+ SHELL_INTERPRETERS: () => SHELL_INTERPRETERS,
88
90
  SSRF_MAX_HOST: () => SSRF_MAX_HOST,
89
91
  STARTUP_NAMES: () => STARTUP_NAMES,
90
92
  SYSTEM_AUTH_DIRS: () => SYSTEM_AUTH_DIRS,
@@ -185,6 +187,7 @@ __export(src_exports, {
185
187
  isPrivateHost: () => isPrivateHost,
186
188
  isProtectedHomePath: () => isProtectedHomePath,
187
189
  isPublicRegistryHost: () => isPublicRegistryHost,
190
+ isPublicSshMaterial: () => isPublicSshMaterial,
188
191
  isRecordOnly: () => isRecordOnly,
189
192
  isShellShapedTool: () => isShellShapedTool,
190
193
  isShieldVerdict: () => isShieldVerdict,
@@ -942,13 +945,27 @@ var project_jail_default = {
942
945
  {
943
946
  field: "file_path",
944
947
  op: "matches",
945
- value: "([\\/\\\\]\\.ssh([\\/\\\\]|$)|^\\.ssh[\\/\\\\])",
948
+ value: "([\\/\\\\]\\.ssh(?:$|[\\/\\\\](?!(?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$))|^\\.ssh[\\/\\\\](?!(?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$))",
946
949
  flags: "i"
947
950
  }
948
951
  ],
949
952
  verdict: "block",
950
953
  reason: "Reading SSH private keys is blocked by project-jail shield"
951
954
  },
955
+ {
956
+ name: "shield:project-jail:block-write-ssh-trust-files",
957
+ tool: "!(read|read_file|grep|grep_search)",
958
+ conditions: [
959
+ {
960
+ field: "file_path",
961
+ op: "matches",
962
+ value: "(?:^|[\\/\\\\])\\.ssh[\\/\\\\](?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$",
963
+ flags: "i"
964
+ }
965
+ ],
966
+ verdict: "block",
967
+ reason: "Changing SSH keys and trusted hosts is blocked by project-jail shield"
968
+ },
952
969
  {
953
970
  name: "shield:project-jail:block-read-aws-any-tool",
954
971
  tool: "*",
@@ -2389,15 +2406,15 @@ function ssrfExemptMatches(entries, normalized) {
2389
2406
  continue;
2390
2407
  }
2391
2408
  if (!target) continue;
2392
- const base3 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2409
+ const base4 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2393
2410
  const prefixText = entry.slice(slash + 1);
2394
2411
  const prefix = /^\d+$/.test(prefixText) ? Number(prefixText) : NaN;
2395
- if (!base3 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2412
+ if (!base4 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2396
2413
  // differ, so `0.0.0.0/0` does not release `::1`.
2397
- base3.length !== target.length || prefix > base3.length) {
2414
+ base4.length !== target.length || prefix > base4.length) {
2398
2415
  continue;
2399
2416
  }
2400
- if (base3.slice(0, prefix) === target.slice(0, prefix)) return true;
2417
+ if (base4.slice(0, prefix) === target.slice(0, prefix)) return true;
2401
2418
  }
2402
2419
  return false;
2403
2420
  }
@@ -3678,7 +3695,7 @@ var LEGACY_TO_ID = new Map(
3678
3695
  function ssrfCheckId(tier) {
3679
3696
  return isStrictGatedTier(tier) ? "network.internal-addresses" : "network.metadata";
3680
3697
  }
3681
- var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:block-read-(ssh|aws|env)(-any-tool)?$/;
3698
+ var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:(?:block-read-(ssh|aws|env)(-any-tool)?|block-write-ssh-trust-files)$/;
3682
3699
  var OVERRIDE_PREFIX = "Override block rule:";
3683
3700
  var LABEL_WRAPPERS = ["Smart Rule:", "Node9 (AST):", "project-jail (AST):"];
3684
3701
  function ruleNameInLabel(s) {
@@ -4196,6 +4213,14 @@ function normalizeFilePath(p, cwd = "", home = "~") {
4196
4213
  }
4197
4214
  return (rooted ? "/" : "") + parts.join("/");
4198
4215
  }
4216
+ var PUBLIC_SSH_NAME_SOURCE = String.raw`(?:known_hosts(?:\.old)?|authorized_keys2?|[^\\/]+\.pub)`;
4217
+ var PUBLIC_SSH_PATH_RE = new RegExp(
4218
+ String.raw`(?:^|[\\/])\.ssh[\\/]${PUBLIC_SSH_NAME_SOURCE}$`,
4219
+ "i"
4220
+ );
4221
+ function isPublicSshMaterial(p) {
4222
+ return PUBLIC_SSH_PATH_RE.test(p);
4223
+ }
4199
4224
 
4200
4225
  // src/shell/index.ts
4201
4226
  var import_picomatch = __toESM(require("picomatch"));
@@ -4430,7 +4455,7 @@ function sedSubstitutions(script) {
4430
4455
  }
4431
4456
  return out.length > 0 ? out : null;
4432
4457
  }
4433
- function collectShellFileAccesses(command, context = {}) {
4458
+ function collectShellFileAccesses(command, context = {}, report) {
4434
4459
  const out = [];
4435
4460
  let payloads = 256;
4436
4461
  const functions = /* @__PURE__ */ new Map();
@@ -4456,7 +4481,11 @@ function collectShellFileAccesses(command, context = {}) {
4456
4481
  });
4457
4482
  }
4458
4483
  function nestedPayload(payload, state, depth) {
4459
- if (payload === null || depth >= MAX_PAYLOAD_DEPTH || payloads-- <= 0) return;
4484
+ if (payload === null) return;
4485
+ if (depth >= MAX_PAYLOAD_DEPTH || payloads-- <= 0) {
4486
+ if (report) report.exhausted = true;
4487
+ return;
4488
+ }
4460
4489
  const f = parseShared(payload);
4461
4490
  if (typeof f !== "symbol") statements(f.Stmts ?? [], state, depth + 1);
4462
4491
  }
@@ -4494,7 +4523,8 @@ function collectShellFileAccesses(command, context = {}) {
4494
4523
  }
4495
4524
  function fromWords(tokens, state, nested, depth) {
4496
4525
  const words = tokens.map((w) => w && !w.dynamic ? w.value : null);
4497
- const head = unwrapCommandHead(words, true);
4526
+ let head = unwrapCommandHead(words, true);
4527
+ if (base(words[head]) === "builtin" && ["cd", "pushd"].includes(base(words[head + 1]))) head++;
4498
4528
  const name = base(words[head]);
4499
4529
  if (name === "find") {
4500
4530
  findActions2(tokens, words, head, state, nested, depth);
@@ -4671,7 +4701,8 @@ function collectShellFileAccesses(command, context = {}) {
4671
4701
  if (!target) return;
4672
4702
  const targetSpelling = target.value || target.pattern;
4673
4703
  for (const source of operands2) {
4674
- if (name === "mv") add("remove", source, state, { recursive: true, followFinal: false });
4704
+ if (name === "mv")
4705
+ add("remove", source, state, { recursive: true, followFinal: false, copy: true });
4675
4706
  else if (name !== "ln" && !linkOnly)
4676
4707
  add("read", source, state, { recursive, followFinal: !preserveSourceLink, copy: true });
4677
4708
  if (!noDirectory)
@@ -5035,8 +5066,107 @@ function collectShellFileAccesses(command, context = {}) {
5035
5066
  }
5036
5067
  return null;
5037
5068
  }
5069
+ function heredocScript(word) {
5070
+ let text = "";
5071
+ for (const part of word?.Parts ?? []) {
5072
+ if (part?.kind === "Lit") {
5073
+ text += part.Value ?? "";
5074
+ continue;
5075
+ }
5076
+ text += resolveWordLiteral({ Parts: [part] }) ?? "$N9_UNRESOLVED";
5077
+ }
5078
+ return text;
5079
+ }
5080
+ function stdinScriptText(stmt) {
5081
+ for (const redir of stmt?.Redirs ?? []) {
5082
+ if (redir.Hdoc) return heredocScript(redir.Hdoc);
5083
+ if (redir.Op === ops().HERE_STRING) return resolveWordLiteral(redir.Word);
5084
+ }
5085
+ return null;
5086
+ }
5087
+ function printfText(stmt) {
5088
+ const cmd = stmt?.Cmd;
5089
+ if (!cmd || cmd.kind !== "CallExpr") return null;
5090
+ const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
5091
+ if (words.some((w) => w === null)) return null;
5092
+ const head = unwrapCommandHead(words);
5093
+ if (base(words[head]) !== "printf") return null;
5094
+ const rest = words.slice(head + 1);
5095
+ if (rest[0] === "--") rest.shift();
5096
+ if (rest.length === 0 || rest[0].startsWith("-")) return null;
5097
+ const [format, ...args] = rest;
5098
+ const directive = /%(?:%|[-+ #0]*(?:\d+|\*)?(?:\.(?:\d+|\*))?[a-zA-Z])/g;
5099
+ let text = "";
5100
+ let next = 0;
5101
+ for (let round = 0; round < 64; round++) {
5102
+ let used = false;
5103
+ text += format.replace(directive, (d) => {
5104
+ if (d === "%%") return "%";
5105
+ used = true;
5106
+ return args[next++] ?? "";
5107
+ });
5108
+ if (!used || next >= args.length) break;
5109
+ }
5110
+ return text;
5111
+ }
5112
+ function soleStatement(stmt) {
5113
+ let cur = stmt;
5114
+ for (let i = 0; i < 8; i++) {
5115
+ const cmd = cur?.Cmd;
5116
+ if (!cmd || cmd.kind !== "Subshell" && cmd.kind !== "Block") break;
5117
+ if ((cur.Redirs ?? []).length > 0 || (cmd.Stmts ?? []).length !== 1) break;
5118
+ cur = cmd.Stmts[0];
5119
+ }
5120
+ return cur;
5121
+ }
5122
+ function passesStdinThrough(stmt, depth = 0) {
5123
+ const cmd = stmt?.Cmd;
5124
+ if (cmd && (cmd.kind === "Subshell" || cmd.kind === "Block"))
5125
+ return depth <= 4 && (stmt.Redirs ?? []).length === 0 && (cmd.Stmts ?? []).some((inner) => passesStdinThrough(inner, depth + 1));
5126
+ if (!cmd || cmd.kind !== "CallExpr") return false;
5127
+ const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
5128
+ const head = unwrapCommandHead(words);
5129
+ const name = base(words[head]);
5130
+ const rest = words.slice(head + 1);
5131
+ if (name === "tee") return true;
5132
+ return name === "cat" && rest.every((w) => w === "-" || w !== null && /^-[A-Za-z]+$/.test(w));
5133
+ }
5134
+ function producedScripts(stmt, depth = 0) {
5135
+ const cmd = stmt?.Cmd;
5136
+ if (!cmd) return [];
5137
+ if (cmd.kind === "Subshell" || cmd.kind === "Block") {
5138
+ if (depth > 4 || (stmt.Redirs ?? []).length > 0) return [];
5139
+ const first = [];
5140
+ const last = [];
5141
+ for (const inner of cmd.Stmts ?? []) {
5142
+ const readings = producedScripts(inner, depth + 1);
5143
+ if (readings.length === 0) continue;
5144
+ first.push(readings[0]);
5145
+ last.push(readings[readings.length - 1]);
5146
+ }
5147
+ if (first.length === 0) return [];
5148
+ const a = first.join("\n");
5149
+ const b = last.join("\n");
5150
+ return a === b ? [a] : [a, b];
5151
+ }
5152
+ if (cmd.kind !== "CallExpr") return [];
5153
+ const words = (cmd.Args ?? []).map((w) => resolveWordLiteral(w));
5154
+ if (words.length === 1 && base(words[0]) === "cat") {
5155
+ const text2 = stdinScriptText(stmt);
5156
+ return text2 === null ? [] : [text2];
5157
+ }
5158
+ const formatted = printfText(stmt);
5159
+ if (formatted !== null) return [decodeAnsiC(formatted)];
5160
+ const text = producedText(stmt);
5161
+ if (text === null) return [];
5162
+ if (!text.includes("\\")) return [text];
5163
+ const head = unwrapCommandHead(words);
5164
+ const decodes = words.slice(head + 1).some((w) => w !== null && /^-[neE]+$/.test(w) && w.includes("e"));
5165
+ const decoded = decodeAnsiC(text);
5166
+ return decodes || decoded === text ? [decoded] : [text, decoded];
5167
+ }
5038
5168
  function stdinScript(stmt, state, depth) {
5039
- if (readsScriptFromStdin(stmt)) nestedPayload(stdinText(stmt), clone(state), depth);
5169
+ if (readsScriptFromStdin(stmt)) nestedPayload(stdinScriptText(stmt), clone(state), depth);
5040
5170
  }
5041
5171
  function statement(stmt, state, depth) {
5042
5172
  if (!stmt || depth > MAX_DEPTH) return;
@@ -5091,18 +5221,23 @@ function collectShellFileAccesses(command, context = {}) {
5091
5221
  }
5092
5222
  const seen = clone(state);
5093
5223
  let pureAnd = true;
5224
+ let flowing = [];
5094
5225
  segments2.forEach(({ op, part }, i) => {
5095
5226
  if (op === ops().AND || op === ops().OR) {
5096
5227
  if (i > 0 && op === ops().AND && pureAnd && state.onSuccess)
5097
5228
  state.cwd = state.onSuccess;
5098
5229
  if (i > 0 && op === ops().OR) merge(state, seen);
5230
+ flowing = [];
5099
5231
  statement(part, state, depth + 1);
5100
5232
  } else {
5101
5233
  const fed = i > 0 ? producedText(segments2[i - 1].part) : null;
5102
5234
  if (fed !== null) pipedStdin.set(part, fed);
5103
5235
  statement(part, clone(state), depth + 1);
5104
- if (i > 0 && readsScriptFromStdin(part))
5105
- nestedPayload(producedText(segments2[i - 1].part), clone(state), depth);
5236
+ const incoming = i > 0 ? flowing : [];
5237
+ if (i > 0 && readsScriptFromStdin(soleStatement(part)))
5238
+ for (const script of incoming) nestedPayload(script, clone(state), depth);
5239
+ const own = producedScripts(part);
5240
+ flowing = [...passesStdinThrough(part) ? incoming : [], ...own].slice(0, 4);
5106
5241
  if (fed !== null) nestedPayload(xargsPayload(part, fed), clone(state), depth);
5107
5242
  }
5108
5243
  if (i > 0 && op !== ops().AND) pureAnd = false;
@@ -5182,6 +5317,140 @@ function collectShellFileAccesses(command, context = {}) {
5182
5317
  return out;
5183
5318
  }
5184
5319
 
5320
+ // src/shell/dotenv-cli.ts
5321
+ var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
5322
+ var FILE_FLAGS = /* @__PURE__ */ new Set(["-f", "--file", "-e", "--env-file"]);
5323
+ var VALUE_FLAGS = /* @__PURE__ */ new Set([
5324
+ "-q",
5325
+ "--quote",
5326
+ "-v",
5327
+ "--env",
5328
+ "-fk",
5329
+ "--env-keys-file",
5330
+ "--convention",
5331
+ "--log-level"
5332
+ ]);
5333
+ var QUIET_SUBCOMMANDS = /* @__PURE__ */ new Set([
5334
+ "set",
5335
+ "unset",
5336
+ "encrypt",
5337
+ "ls",
5338
+ "help",
5339
+ "version",
5340
+ "rotate",
5341
+ "genexample",
5342
+ "gitignore",
5343
+ "prebuild",
5344
+ "precommit",
5345
+ "keypair",
5346
+ "ext"
5347
+ ]);
5348
+ function filesAfter(words, from, files) {
5349
+ for (let j = from; j < words.length; j++) {
5350
+ const w = words[j];
5351
+ if (w === null) continue;
5352
+ if (FILE_FLAGS.has(w)) {
5353
+ if (words[j + 1] !== void 0) files.push(words[j + 1]);
5354
+ j++;
5355
+ continue;
5356
+ }
5357
+ const joined = /^(?:--file|--env-file)=(.*)$/.exec(w);
5358
+ if (joined) files.push(joined[1]);
5359
+ }
5360
+ }
5361
+ function dotenvArgsStart(words, head) {
5362
+ const name = base2(words[head]);
5363
+ if (name === "dotenv" || name === "dotenv-cli" || name === "dotenvx") return head + 1;
5364
+ if (name === "bundle" && words[head + 1] === "exec" && base2(words[head + 2]) === "dotenv")
5365
+ return head + 3;
5366
+ if (/^(?:python[\d.]*|py)$/.test(name)) {
5367
+ for (let i = head + 1; i < words.length; i++) {
5368
+ const w = words[i];
5369
+ if (w === null || !w.startsWith("-")) return -1;
5370
+ if (w === "-m") return words[i + 1] === "dotenv" ? i + 2 : -1;
5371
+ if (w === "-c") return -1;
5372
+ }
5373
+ }
5374
+ return -1;
5375
+ }
5376
+ function readDotenvCli(words, head) {
5377
+ const start = dotenvArgsStart(words, head);
5378
+ if (start < 0) return null;
5379
+ const files = [];
5380
+ let print = false;
5381
+ let sawRun = false;
5382
+ let inner = -1;
5383
+ let i = start;
5384
+ while (i < words.length) {
5385
+ const w = words[i];
5386
+ if (w === null) {
5387
+ inner = i;
5388
+ break;
5389
+ }
5390
+ if (w === "--") {
5391
+ inner = i + 1;
5392
+ break;
5393
+ }
5394
+ if (FILE_FLAGS.has(w)) {
5395
+ const value = words[i + 1];
5396
+ if (!(w === "-e" && (value === "true" || value === "false")) && value !== void 0)
5397
+ files.push(value);
5398
+ i += 2;
5399
+ continue;
5400
+ }
5401
+ const joined = /^(?:--file|--env-file)=(.*)$/.exec(w);
5402
+ if (joined) {
5403
+ files.push(joined[1]);
5404
+ i++;
5405
+ continue;
5406
+ }
5407
+ if (w === "-p" || w === "--print") {
5408
+ print = true;
5409
+ i += 2;
5410
+ continue;
5411
+ }
5412
+ if (VALUE_FLAGS.has(w)) {
5413
+ i += 2;
5414
+ continue;
5415
+ }
5416
+ if (w === "-c" || w === "--cascade") {
5417
+ const value = words[i + 1];
5418
+ const after = words[i + 2];
5419
+ const takes = typeof value === "string" && !value.startsWith("-") && typeof after === "string" && after.startsWith("-");
5420
+ i += takes ? 2 : 1;
5421
+ continue;
5422
+ }
5423
+ if (w.startsWith("-")) {
5424
+ i++;
5425
+ continue;
5426
+ }
5427
+ if (!sawRun) {
5428
+ if (w === "list" || w === "get") {
5429
+ print = true;
5430
+ filesAfter(words, i + 1, files);
5431
+ break;
5432
+ }
5433
+ if (w === "run") {
5434
+ sawRun = true;
5435
+ i++;
5436
+ continue;
5437
+ }
5438
+ if (w === "decrypt") {
5439
+ print = words.slice(i + 1).some((x) => x === "--stdout");
5440
+ filesAfter(words, i + 1, files);
5441
+ break;
5442
+ }
5443
+ if (QUIET_SUBCOMMANDS.has(w)) return null;
5444
+ }
5445
+ inner = i;
5446
+ break;
5447
+ }
5448
+ const loaded = files.length > 0 ? files : [".env"];
5449
+ if (print) return { files: loaded, mode: "print", inner: -1 };
5450
+ if (inner >= 0 && inner < words.length) return { files: loaded, mode: "run", inner };
5451
+ return null;
5452
+ }
5453
+
5185
5454
  // src/shell/services.ts
5186
5455
  var INFRASTRUCTURE_SERVICES = [
5187
5456
  "init",
@@ -5541,8 +5810,19 @@ var DOTENV = {
5541
5810
  values: /\b(?:dotenv_values|get_key)\s*\(/,
5542
5811
  env: /\b(?:environ|getenv)\b/,
5543
5812
  literalPath: /\b(?:load_dotenv|dotenv_values)\s*\(\s*(?:dotenv_path\s*=\s*)?[rRbBuU]?['"]/
5813
+ },
5814
+ // Ruby's dotenv gem (node9Firewall#443): `require "dotenv/load"` loads on
5815
+ // require; `require "dotenv"` alone does not, it needs Dotenv.load.
5816
+ ruby: {
5817
+ load: /\brequire\s*\(?\s*['"]dotenv\/load['"]|\bDotenv\s*\.\s*(?:load|overload|parse)\b/,
5818
+ values: /\bDotenv\s*\.\s*parse\b/,
5819
+ env: /\bENV\b/,
5820
+ literalPath: /\bDotenv\s*\.\s*(?:load|overload|parse)\s*\(?\s*['"]/
5544
5821
  }
5545
5822
  };
5823
+ function inlineReadsEnvironment(language, code) {
5824
+ return language === "python" || language === "node" || language === "ruby" ? DOTENV[language].env.test(code) : false;
5825
+ }
5546
5826
  var DOTENV_PATH_OPTION = /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*$/;
5547
5827
  function inlineReadPaths(language, code, preload = {}) {
5548
5828
  const out = [];
@@ -5568,7 +5848,7 @@ function inlineReadPaths(language, code, preload = {}) {
5568
5848
  for (const m of code.matchAll(OPENED_NAME[language])) opened.add(m[1] ?? m[2]);
5569
5849
  for (const [name, values] of assigned) if (opened.has(name)) out.push(...values);
5570
5850
  }
5571
- if (language === "python" || language === "node") {
5851
+ if (language === "python" || language === "node" || language === "ruby") {
5572
5852
  const d = DOTENV[language];
5573
5853
  const readsEnv = d.env.test(code);
5574
5854
  const loads = /dotenv/.test(code) && d.load.test(code) && !d.literalPath.test(code);
@@ -6847,7 +7127,12 @@ var SENSITIVE_PATH_RULES = [
6847
7127
  {
6848
7128
  rule: "shield:project-jail:block-read-ssh",
6849
7129
  reason: "Reading SSH private keys is blocked by project-jail shield",
6850
- match: (p) => /([\\/]\.ssh[\\/]|^\.ssh[\\/]|^(?:[~/]|[A-Za-z]:).*[\\/]\.ssh$)/i.test(p)
7130
+ // Public material is not a key (JAIL-16): `known_hosts`, `authorized_keys`
7131
+ // and `*.pub` are readable. Because the exemption lives in the rule itself,
7132
+ // the copy tier sees `x.pub` as a destination OUTSIDE the jail, so
7133
+ // `cp ~/.ssh/id_rsa ~/.ssh/x.pub` is a reviewed copy, not a quiet rename
7134
+ // followed by an allowed read.
7135
+ match: (p) => /([\\/]\.ssh[\\/]|^\.ssh[\\/]|^(?:[~/]|[A-Za-z]:).*[\\/]\.ssh$)/i.test(p) && !isPublicSshMaterial(p)
6851
7136
  },
6852
7137
  {
6853
7138
  rule: "shield:project-jail:block-read-aws",
@@ -7216,6 +7501,7 @@ function attachedCode(interp, flag) {
7216
7501
  return rest === "" ? null : rest;
7217
7502
  }
7218
7503
  var NODE_VALUE_FLAG = /^(-r|--require|--import|--loader|--experimental-loader|--env-file|--env-file-if-exists|--input-type|-C|--conditions)(?:=(.*))?$/;
7504
+ var RUBY_VALUE_FLAG = /^-([rI])(.*)$/;
7219
7505
  function inlineExecCall(stmt, pipeFed) {
7220
7506
  const cmd = stmt?.Cmd;
7221
7507
  if (!cmd || cmd.kind !== "CallExpr") return null;
@@ -7249,6 +7535,7 @@ function inlineExecCall(stmt, pipeFed) {
7249
7535
  const codes = [];
7250
7536
  const preload = {};
7251
7537
  const nodeFamily = inlineLanguageOf(interp) === "node";
7538
+ const rubyFamily = inlineLanguageOf(interp) === "ruby";
7252
7539
  for (let i = 0; i < args.length; i++) {
7253
7540
  const a = args[i];
7254
7541
  if (nodeFamily && !selectedProgram && codes.length === 0 && a != null) {
@@ -7258,10 +7545,21 @@ function inlineExecCall(stmt, pipeFed) {
7258
7545
  if (value != null) {
7259
7546
  if (/^--env-file/.test(flag[1])) (preload.envFiles ??= []).push(value);
7260
7547
  else if (/^dotenv\/config(?:\.js)?$/.test(value)) preload.dotenv = true;
7548
+ } else if (/^--env-file/.test(flag[1])) {
7549
+ preload.unknownEnvFile = true;
7261
7550
  }
7262
7551
  continue;
7263
7552
  }
7264
7553
  }
7554
+ if (rubyFamily && !selectedProgram && codes.length === 0 && a != null) {
7555
+ const flag = RUBY_VALUE_FLAG.exec(a);
7556
+ if (flag) {
7557
+ const value = flag[2] !== "" ? flag[2] : args[++i];
7558
+ if (flag[1] === "r" && value != null && /^dotenv\/load(?:\.rb)?$/.test(value))
7559
+ preload.dotenv = true;
7560
+ continue;
7561
+ }
7562
+ }
7265
7563
  if (a == null) {
7266
7564
  if (codes.length > 0) break;
7267
7565
  positionals2++;
@@ -7600,7 +7898,7 @@ var NET_BINARIES = /* @__PURE__ */ new Set([
7600
7898
  "netcat",
7601
7899
  "rsync"
7602
7900
  ]);
7603
- var VALUE_FLAGS = {
7901
+ var VALUE_FLAGS2 = {
7604
7902
  // rsync 3.2.7, its own --help: every flag whose operand could be mistaken for
7605
7903
  // a host. `-e ssh` is the one that matters most (`ssh` is not the destination).
7606
7904
  rsync: /* @__PURE__ */ new Set([
@@ -8170,7 +8468,7 @@ function parseDestHost(token) {
8170
8468
  return null;
8171
8469
  }
8172
8470
  function destTokensForBinary(binary, args) {
8173
- const valueFlags = VALUE_FLAGS[binary] ?? /* @__PURE__ */ new Set();
8471
+ const valueFlags = VALUE_FLAGS2[binary] ?? /* @__PURE__ */ new Set();
8174
8472
  const positionals2 = [];
8175
8473
  const urlFlagValues = [];
8176
8474
  for (let i = 0; i < args.length; i++) {
@@ -8322,7 +8620,9 @@ var FS_OP_CACHE_MAX = 5e3;
8322
8620
  var fsOpCache = /* @__PURE__ */ new Map();
8323
8621
  function analyzeFsOperation(command) {
8324
8622
  const normalized = normalizeCommandForPolicy(command);
8325
- if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized))
8623
+ const stdinShell = feedsShellStdin(command) || feedsShellStdin(normalized);
8624
+ const dotenvCli = DOTENV_CLI_PRESCREEN_RE.test(command) || DOTENV_CLI_PRESCREEN_RE.test(normalized);
8625
+ if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized) && !stdinShell && !dotenvCli)
8326
8626
  return null;
8327
8627
  if (fsOpCache.has(command)) {
8328
8628
  const hit = fsOpCache.get(command) ?? null;
@@ -8330,8 +8630,11 @@ function analyzeFsOperation(command) {
8330
8630
  fsOpCache.set(command, hit);
8331
8631
  return hit;
8332
8632
  }
8333
- const direct = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8334
- const computed = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
8633
+ const changesDir = CHANGES_DIR_RE.test(command) || CHANGES_DIR_RE.test(normalized);
8634
+ const own = analyzeFsOperationImpl(command);
8635
+ const direct = (stdinShell || changesDir) && own?.verdict !== "block" ? stricter(own, structuralJailRead(command)) : own ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8636
+ const withInline = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command, changesDir));
8637
+ const computed = withInline?.verdict === "block" || !dotenvCli ? withInline : stricter(withInline, dotenvCliJailRead(command));
8335
8638
  if (fsOpCache.size >= FS_OP_CACHE_MAX) {
8336
8639
  const oldest = fsOpCache.keys().next().value;
8337
8640
  if (oldest !== void 0) fsOpCache.delete(oldest);
@@ -8341,8 +8644,8 @@ function analyzeFsOperation(command) {
8341
8644
  }
8342
8645
  var stripDotSlash = (p) => p.replace(/^\.\//, "");
8343
8646
  function isSensitiveCleanupName(p) {
8344
- const base3 = p.replace(/^.*[\\/]/, "");
8345
- 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);
8647
+ const base4 = p.replace(/^.*[\\/]/, "");
8648
+ return /^\.env(\.|$)/i.test(base4) || /(?:^|[\\/])\.(?:ssh|aws|gnupg|git)(?:[\\/]|$)/i.test(p) || /\.(?:pem|key|p12|pfx|crt)$/i.test(base4) || /^\.?(?:netrc|npmrc|pgpass|htpasswd)$/i.test(base4) || /^id_(?:rsa|dsa|ecdsa|ed25519)/i.test(base4) || /credential/i.test(p) || /secret/i.test(base4);
8346
8649
  }
8347
8650
  function isWaivableCleanupTarget(p) {
8348
8651
  if (/^[/~]/.test(p) || /^\$/.test(p)) return false;
@@ -8797,6 +9100,12 @@ function matchSensitivePath(p) {
8797
9100
  return null;
8798
9101
  }
8799
9102
  var INDIRECT_SHAPE_RE = /\b(?:for|while|until|find|xargs|set|source)\b|\$\{?PWD\b|[*?[]|(?:^|[;&|(\s])\.\s/;
9103
+ var STDIN_SHELL_WORD_RE = new RegExp(
9104
+ `(?:^|[\\s;&|(/\\\\])(?:${[...SHELL_INTERPRETERS].map((name) => name.replace(/[.*+?^\${}()|[\]\\]/g, "\\$&")).join("|")})(?=$|[\\s;&|)<])`,
9105
+ "i"
9106
+ );
9107
+ var feedsShellStdin = (command) => /\||<</.test(command) && STDIN_SHELL_WORD_RE.test(command);
9108
+ var CHANGES_DIR_RE = /(?:^|[\s;&|({'"`])(?:cd|pushd)\s/;
8800
9109
  var SOURCES_FILE_RE = /(?:^|[;&|(\s])(?:source|\.)\s/;
8801
9110
  function printsEnvironment(words) {
8802
9111
  const [name, ...rest] = words;
@@ -9069,8 +9378,17 @@ function analyzeUnknownCredentialReads(command) {
9069
9378
  }
9070
9379
  return !hit;
9071
9380
  });
9072
- return hit ? {
9073
- reason: "Files are read by names a listing produces when the command runs, and the listing can include credential files"
9381
+ if (hit)
9382
+ return {
9383
+ reason: "Files are read by names a listing produces when the command runs, and the listing can include credential files"
9384
+ };
9385
+ let unknownEnvFile = false;
9386
+ try {
9387
+ unknownEnvFile = readsUnknownEnvFile(command) || dotenvCliReads(command).unknown;
9388
+ } catch {
9389
+ }
9390
+ return unknownEnvFile ? {
9391
+ reason: "An environment file is loaded and its values are shown, and its name is not known until the command runs: it can be a credential file"
9074
9392
  } : null;
9075
9393
  }
9076
9394
  var JAILED_GLOB_NAMES = [
@@ -9096,6 +9414,7 @@ function matchSensitiveGlob(glob, dotGlob) {
9096
9414
  }
9097
9415
  });
9098
9416
  glob = parts.join("/");
9417
+ if (isPublicSshMaterial(glob)) return null;
9099
9418
  const first = parts.findIndex((seg) => GLOB_META.test(seg));
9100
9419
  if (first < 0) return matchSensitivePath(glob);
9101
9420
  const prefix = parts.slice(0, first).join("/");
@@ -9120,10 +9439,17 @@ function matchSensitiveGlob(glob, dotGlob) {
9120
9439
  }
9121
9440
  return null;
9122
9441
  }
9442
+ function underEnteredDir(a, name) {
9443
+ const dir = a.cwd ?? "";
9444
+ if (!dir || /^(?:[/\\~$]|[A-Za-z]:)/.test(name)) return name;
9445
+ const rest = name.replace(/^(?:\.\/)+/, "");
9446
+ return `${dir.replace(/[/\\]+$/, "")}/${rest}`;
9447
+ }
9123
9448
  function structuralJailRead(command) {
9124
9449
  let accesses;
9450
+ const report = { exhausted: false };
9125
9451
  try {
9126
- accesses = collectShellFileAccesses(command);
9452
+ accesses = collectShellFileAccesses(command, {}, report);
9127
9453
  } catch {
9128
9454
  return null;
9129
9455
  }
@@ -9132,35 +9458,148 @@ function structuralJailRead(command) {
9132
9458
  const sourcedHit = sourcedAndPrinted(command);
9133
9459
  if (sourcedHit?.verdict === "block") return sourcedHit;
9134
9460
  let review = sourcedHit;
9461
+ let relativeCopy = null;
9135
9462
  for (const a of accesses) {
9136
- if (a.operation !== "read" || a.listing || a.recursive || a.copy) continue;
9463
+ if (a.copy && !a.listing && (a.operation === "read" || a.operation === "remove")) {
9464
+ const entered = underEnteredDir(a, a.path);
9465
+ if (entered !== a.path) relativeCopy ??= copyVerdictOf(matchSensitivePath(entered));
9466
+ continue;
9467
+ }
9468
+ if (a.operation !== "read" || a.listing || a.recursive) continue;
9137
9469
  const glob = a.glob ?? (GLOB_META.test(a.path) ? a.path : void 0);
9138
- const hit = glob ? matchSensitiveGlob(glob, !!a.dotGlob) : matchSensitivePath(a.path);
9470
+ const hit = glob ? matchSensitiveGlob(underEnteredDir(a, glob), !!a.dotGlob) : matchSensitivePath(underEnteredDir(a, a.path));
9139
9471
  if (hit?.verdict === "block") return hit;
9140
9472
  review ??= hit;
9141
9473
  }
9142
- return review;
9474
+ review = stricter(review, relativeCopy);
9475
+ return report.exhausted ? stricter(review, UNANALYSABLE_NESTING) : review;
9143
9476
  }
9144
9477
  var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
9145
9478
  var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
9146
- function inlineCodeJailRead(command) {
9479
+ function inlineCodeJailRead(command, changesDir = false) {
9147
9480
  const calls = inlineExecCalls(command);
9148
9481
  if (calls === PARSE_FAIL) return null;
9149
9482
  let review = null;
9483
+ let entered = null;
9484
+ const dirs = () => entered ??= changesDir ? enteredDirs(command) : [];
9150
9485
  for (const call of calls) {
9151
9486
  const language = inlineLanguageOf(call.interp);
9152
9487
  if (language === null) continue;
9153
9488
  for (const code of call.code) {
9154
9489
  if (code === null) continue;
9155
9490
  for (const p of inlineReadPaths(language, code, call.preload)) {
9156
- const hit = matchSensitivePath(p);
9157
- if (hit?.verdict === "block") return hit;
9158
- review ??= hit;
9491
+ const relative = !/^(?:[/\\~$]|[A-Za-z]:)/.test(p);
9492
+ const spellings = relative ? [p, ...dirs().map((d) => `${d}/${p}`)] : [p];
9493
+ for (const spelling of spellings) {
9494
+ const hit = matchSensitivePath(spelling);
9495
+ if (hit?.verdict === "block") return hit;
9496
+ review ??= hit;
9497
+ }
9159
9498
  }
9160
9499
  }
9161
9500
  }
9162
9501
  return review;
9163
9502
  }
9503
+ var MAX_ENTERED_DIRS = 16;
9504
+ function enteredDirs(command, depth = 0, out = []) {
9505
+ if (depth > 3) return out;
9506
+ try {
9507
+ walkCommandScope(command, (node) => {
9508
+ const n = node;
9509
+ if (!n || n.kind !== "CallExpr" || out.length >= MAX_ENTERED_DIRS) return true;
9510
+ const words = callWords(n);
9511
+ if (words.length === 0) return true;
9512
+ let head = unwrapCommandHead(words);
9513
+ if (baseWord(words[head]) === "builtin") head++;
9514
+ const name = baseWord(words[head]);
9515
+ if (name !== "cd" && name !== "pushd") {
9516
+ const payload = literalShellPayload(words, baseWord(words[0]));
9517
+ if (payload !== null) enteredDirs(payload, depth + 1, out);
9518
+ return true;
9519
+ }
9520
+ const target = words.slice(head + 1).find((w) => w === null || !w.startsWith("-"));
9521
+ if (!target) return true;
9522
+ const dir = target.replace(/[/\\]+$/, "");
9523
+ const rooted = /^(?:[/\\~]|[A-Za-z]:)/.test(dir);
9524
+ for (const d of rooted ? [dir] : [dir, ...out.map((prev) => `${prev}/${dir}`)])
9525
+ if (out.length < MAX_ENTERED_DIRS && !out.includes(d)) out.push(d);
9526
+ return true;
9527
+ });
9528
+ } catch {
9529
+ }
9530
+ return out;
9531
+ }
9532
+ var DOTENV_CLI_PRESCREEN_RE = /\bdotenvx?\b/i;
9533
+ var MAX_DOTENV_PAYLOAD_DEPTH = 3;
9534
+ function dotenvCliReads(command, depth = 0) {
9535
+ const out = { paths: [], unknown: false };
9536
+ if (depth > MAX_DOTENV_PAYLOAD_DEPTH || !DOTENV_CLI_PRESCREEN_RE.test(command)) return out;
9537
+ const bytes = new TextEncoder().encode(command);
9538
+ const sourceOf = (from, to) => typeof from === "number" && typeof to === "number" && from >= 0 && to > from ? new TextDecoder().decode(bytes.subarray(from, to)) : "";
9539
+ walkCommandScope(command, (node) => {
9540
+ const n = node;
9541
+ if (!n || n.kind !== "CallExpr") return true;
9542
+ const args = n.Args || [];
9543
+ const words = args.map((a) => resolveWordLiteral(a));
9544
+ if (words.length === 0) return true;
9545
+ const call = readDotenvCli(words, unwrapCommandHead(words));
9546
+ if (!call) {
9547
+ const payload = literalShellPayload(words, baseWord(words[0]));
9548
+ if (payload !== null) {
9549
+ const inner = dotenvCliReads(payload, depth + 1);
9550
+ out.paths.push(...inner.paths);
9551
+ out.unknown ||= inner.unknown;
9552
+ }
9553
+ return true;
9554
+ }
9555
+ let shown = call.mode === "print";
9556
+ if (!shown) {
9557
+ const inner = words.slice(call.inner);
9558
+ const literal = (ws) => ws.length > 0 && ws.every((w) => w !== null);
9559
+ const plain = inner.slice(unwrapCommandHead(inner));
9560
+ shown = literal(inner) && printsEnvironment(inner) || literal(plain) && printsEnvironment(plain);
9561
+ const payload = shown ? null : literalShellPayload(inner, baseWord(inner[0]));
9562
+ if (payload !== null && sourcedAndPrinted(`. .env
9563
+ ${payload}`) !== null) shown = true;
9564
+ if (!shown) {
9565
+ const text = sourceOf(args[call.inner]?.pos, args[args.length - 1]?.end);
9566
+ const calls = text ? inlineExecCalls(text) : [];
9567
+ if (calls !== PARSE_FAIL)
9568
+ shown = calls.some((c) => {
9569
+ const language = inlineLanguageOf(c.interp);
9570
+ return language !== null && c.code.some((code) => code !== null && inlineReadsEnvironment(language, code));
9571
+ });
9572
+ }
9573
+ }
9574
+ if (!shown) return true;
9575
+ for (const file of call.files) {
9576
+ if (file === null) out.unknown = true;
9577
+ else out.paths.push(file);
9578
+ }
9579
+ return true;
9580
+ });
9581
+ return out;
9582
+ }
9583
+ function dotenvCliJailRead(command) {
9584
+ let result = null;
9585
+ try {
9586
+ for (const p of dotenvCliReads(command).paths) {
9587
+ result = stricter(result, matchSensitivePath(p));
9588
+ if (result?.verdict === "block") break;
9589
+ }
9590
+ } catch {
9591
+ }
9592
+ return result;
9593
+ }
9594
+ function readsUnknownEnvFile(command) {
9595
+ if (!/--env-file/.test(command)) return false;
9596
+ const calls = inlineExecCalls(command);
9597
+ if (calls === PARSE_FAIL) return false;
9598
+ return calls.some((c) => {
9599
+ const language = inlineLanguageOf(c.interp);
9600
+ return c.preload?.unknownEnvFile === true && language !== null && c.code.some((code) => code !== null && inlineReadsEnvironment(language, code));
9601
+ });
9602
+ }
9164
9603
  function baseWord(w) {
9165
9604
  return (w ?? "").split("/").pop()?.toLowerCase() ?? "";
9166
9605
  }
@@ -12300,6 +12739,120 @@ function secretViews(text, budget) {
12300
12739
  return out;
12301
12740
  }
12302
12741
 
12742
+ // src/dlp/placeholder.ts
12743
+ var TEMPLATE_RE = /\$\{|\{\{|%\{|<[^<>\s]{1,80}>/;
12744
+ var RUN_RE = /(.)\1{7}/;
12745
+ var DOMINANT_SHARE = 0.6;
12746
+ var DOC_WORDS = ["example", "sample", "fake", "dummy", "placeholder", "changeme", "redacted"];
12747
+ var STANDALONE_WORDS = /* @__PURE__ */ new Set([...DOC_WORDS, "your", "here", "insert", "replace"]);
12748
+ var DOC_EDGE_RE = new RegExp(
12749
+ `^(?:${DOC_WORDS.join("|")})|(?:${DOC_WORDS.join("|")})(?:[_-]?(?:key|token|secret))?$`
12750
+ );
12751
+ var VOCABULARY = [
12752
+ ...DOC_WORDS,
12753
+ "your",
12754
+ "here",
12755
+ "insert",
12756
+ "replace",
12757
+ "put",
12758
+ "change",
12759
+ "goes",
12760
+ "with",
12761
+ "this",
12762
+ "please",
12763
+ "real",
12764
+ "actual",
12765
+ "me",
12766
+ "my",
12767
+ "the",
12768
+ "an",
12769
+ "key",
12770
+ "token",
12771
+ "secret",
12772
+ "password",
12773
+ "passwd",
12774
+ "api",
12775
+ "apikey",
12776
+ "access",
12777
+ "auth",
12778
+ "test",
12779
+ "value",
12780
+ "xxx"
12781
+ ];
12782
+ var VOCABULARY_SET = new Set(VOCABULARY);
12783
+ var MAX_COMPOSED_SEGMENT = 48;
12784
+ function madeOfVocabulary(segment) {
12785
+ if (VOCABULARY_SET.has(segment)) return true;
12786
+ if (segment.length > MAX_COMPOSED_SEGMENT) return false;
12787
+ const reachable = new Array(segment.length + 1).fill(false);
12788
+ reachable[0] = true;
12789
+ for (let i = 0; i < segment.length; i++) {
12790
+ if (!reachable[i]) continue;
12791
+ for (const word of VOCABULARY) {
12792
+ if (segment.startsWith(word, i)) reachable[i + word.length] = true;
12793
+ }
12794
+ }
12795
+ return reachable[segment.length];
12796
+ }
12797
+ var isUpper = (c) => c >= 65 && c <= 90;
12798
+ var isLower = (c) => c >= 97 && c <= 122;
12799
+ function alphabeticSegments(token) {
12800
+ const segments2 = [];
12801
+ let start = -1;
12802
+ const close = (end) => {
12803
+ if (start >= 0) segments2.push(token.slice(start, end).toLowerCase());
12804
+ start = -1;
12805
+ };
12806
+ for (let i = 0; i < token.length; i++) {
12807
+ const c = token.charCodeAt(i);
12808
+ if (!isUpper(c) && !isLower(c)) {
12809
+ close(i);
12810
+ continue;
12811
+ }
12812
+ if (start >= 0 && isUpper(c)) {
12813
+ const prev = token.charCodeAt(i - 1);
12814
+ const next = i + 1 < token.length ? token.charCodeAt(i + 1) : 0;
12815
+ if (isLower(prev) || isUpper(prev) && isLower(next)) close(i);
12816
+ }
12817
+ if (start < 0) start = i;
12818
+ }
12819
+ close(token.length);
12820
+ return segments2;
12821
+ }
12822
+ function dominatedByOneChar(s) {
12823
+ if (s.length < 4) return false;
12824
+ const counts = /* @__PURE__ */ new Map();
12825
+ let top = 0;
12826
+ for (const ch of s) {
12827
+ const n = (counts.get(ch) ?? 0) + 1;
12828
+ counts.set(ch, n);
12829
+ if (n > top) top = n;
12830
+ }
12831
+ return top / s.length >= DOMINANT_SHARE;
12832
+ }
12833
+ var MAX_PHRASE_LENGTH = 160;
12834
+ function builtFromVocabulary(token) {
12835
+ if (token.length > MAX_PHRASE_LENGTH) return false;
12836
+ const segments2 = alphabeticSegments(token);
12837
+ if (segments2.length === 0 || !segments2.every(madeOfVocabulary)) return false;
12838
+ const letters = token.replace(/[^A-Za-z]/g, "").length;
12839
+ const alphanumerics = token.replace(/[^A-Za-z0-9]/g, "").length;
12840
+ return letters * 2 >= alphanumerics;
12841
+ }
12842
+ var PHRASE_RE = /^[a-z]{1,20}(?:[-_.][a-z]{1,20}){2,}$/;
12843
+ function isPhrase(secret) {
12844
+ return PHRASE_RE.test(secret);
12845
+ }
12846
+ function isPlaceholder(secret) {
12847
+ if (secret.length === 0) return false;
12848
+ if (TEMPLATE_RE.test(secret)) return true;
12849
+ if (RUN_RE.test(secret) || dominatedByOneChar(secret)) return true;
12850
+ const lower2 = secret.toLowerCase();
12851
+ if (lower2.split(/[^a-z0-9]+/).some((part) => STANDALONE_WORDS.has(part))) return true;
12852
+ if (DOC_EDGE_RE.test(lower2)) return true;
12853
+ return builtFromVocabulary(secret);
12854
+ }
12855
+
12303
12856
  // src/scan/checksums.ts
12304
12857
  var import_crypto = require("crypto");
12305
12858
  function validateLuhn(digits) {
@@ -12422,12 +12975,19 @@ var IBAN_LENGTH = {
12422
12975
  YE: 30
12423
12976
  };
12424
12977
  var IBAN_BBAN_SHAPE = {
12978
+ // AD, AE, BA, EE: the registered countries whose code is two hex letters
12979
+ // and that had no shape here, so a hex id with that prefix and a lucky
12980
+ // mod-97 read as an IBAN (node9Firewall#369).
12981
+ AD: /^\d{8}[A-Z0-9]{12}$/,
12982
+ AE: /^\d{19}$/,
12425
12983
  AT: /^\d{16}$/,
12984
+ BA: /^\d{16}$/,
12426
12985
  BE: /^\d{12}$/,
12427
12986
  CH: /^\d{5}[A-Z0-9]{12}$/,
12428
12987
  CZ: /^\d{20}$/,
12429
12988
  DE: /^\d{18}$/,
12430
12989
  DK: /^\d{14}$/,
12990
+ EE: /^\d{16}$/,
12431
12991
  ES: /^\d{20}$/,
12432
12992
  FI: /^\d{14}$/,
12433
12993
  FR: /^\d{10}[A-Z0-9]{11}\d{2}$/,
@@ -12847,9 +13407,9 @@ function validateBelgianNationalNumber(raw) {
12847
13407
  if (!/^\d{11}$/.test(d)) return false;
12848
13408
  const month = Number(d.slice(2, 4)) % 20;
12849
13409
  if (month !== 0 && !plausibleDate(String(month).padStart(2, "0"), d.slice(4, 6))) return false;
12850
- const base3 = Number(d.slice(0, 9));
13410
+ const base4 = Number(d.slice(0, 9));
12851
13411
  const check = Number(d.slice(9, 11));
12852
- return 97 - base3 % 97 === check || 97 - (2e9 + base3) % 97 === check;
13412
+ return 97 - base4 % 97 === check || 97 - (2e9 + base4) % 97 === check;
12853
13413
  }
12854
13414
  function validateCuit(raw) {
12855
13415
  const d = raw.replace(/-/g, "");
@@ -12976,32 +13536,6 @@ function shannonEntropy(s) {
12976
13536
  }
12977
13537
  return h;
12978
13538
  }
12979
- var DLP_STOPWORDS = [
12980
- "example",
12981
- "placeholder",
12982
- "changeme",
12983
- "your_key",
12984
- "your_token",
12985
- "your_secret",
12986
- "replace_me",
12987
- "insert_key",
12988
- "put_your",
12989
- "fake",
12990
- "dummy",
12991
- "sample",
12992
- "xxxxxxxx",
12993
- "aaaaaa",
12994
- "bbbbbb",
12995
- "00000000",
12996
- "${",
12997
- "{{",
12998
- "%{",
12999
- "<your",
13000
- "test_key",
13001
- "test_token",
13002
- "your",
13003
- "here"
13004
- ];
13005
13539
  function capturedValue(raw, pattern) {
13006
13540
  const m = raw.match(pattern);
13007
13541
  return m?.[1] ?? null;
@@ -13034,8 +13568,7 @@ function rejectedByStructuredValidator(value) {
13034
13568
  }
13035
13569
  function looksGenerated(value, minLength, minEntropy, lettersOnlyAllowed = false) {
13036
13570
  if (value.length < minLength) return false;
13037
- const lower2 = value.toLowerCase();
13038
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw))) return false;
13571
+ if (isPlaceholder(value)) return false;
13039
13572
  if (REFERENCE_VALUE_RE.test(value)) return false;
13040
13573
  if (!lettersOnlyAllowed && IDENTIFIER_VALUE_RE.test(value)) return false;
13041
13574
  if (EMAIL_VALUE_RE.test(value)) return false;
@@ -13186,9 +13719,7 @@ var SQL_PASSWORD_VALUE_RE = /['"]([^'"\s]{8,128})['"]$/;
13186
13719
  function validateSqlPassword(raw) {
13187
13720
  const value = capturedValue(raw, SQL_PASSWORD_VALUE_RE);
13188
13721
  if (value === null) return false;
13189
- const lower2 = value.toLowerCase();
13190
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || REFERENCE_VALUE_RE.test(value))
13191
- return false;
13722
+ if (isPlaceholder(value) || REFERENCE_VALUE_RE.test(value)) return false;
13192
13723
  if (/^[a-z]+$/i.test(value) && value.length < 12) return false;
13193
13724
  return shannonEntropy(value) >= 2.5 && !hasSequentialRun(value);
13194
13725
  }
@@ -13223,8 +13754,7 @@ function validateBasicCredential(raw, before = "") {
13223
13754
  if (!pair) return false;
13224
13755
  const password = pair[2];
13225
13756
  if (!/[0-9]/.test(password) || !/[A-Za-z]/.test(password)) return false;
13226
- const lower2 = password.toLowerCase();
13227
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || hasSequentialRun(password)) return false;
13757
+ if (isPlaceholder(password) || hasSequentialRun(password)) return false;
13228
13758
  return shannonEntropy(password) >= 3;
13229
13759
  }
13230
13760
  function headerPairIsCredential(text) {
@@ -13242,7 +13772,7 @@ function validateDropboxSecret(raw) {
13242
13772
  const value = capturedValue(raw, DROPBOX_SECRET_RE);
13243
13773
  if (value === null || value !== value.toLowerCase()) return false;
13244
13774
  if (!/[0-9]/.test(value) || !/[a-z]/.test(value)) return false;
13245
- if (DLP_STOPWORDS.some((sw) => value.includes(sw)) || hasSequentialRun(value)) return false;
13775
+ if (isPlaceholder(value) || hasSequentialRun(value)) return false;
13246
13776
  return shannonEntropy(value) >= 3;
13247
13777
  }
13248
13778
  var OTP_CAPTURE_RE = /["']([A-Z2-7]{16,128}=*)["']$/i;
@@ -13250,8 +13780,7 @@ var DB_URL_PASSWORD_RE = /:\/\/[^:/\s@]*:([^@\s]{4,})@/;
13250
13780
  function validateDbConnectionString(raw) {
13251
13781
  const password = capturedValue(raw, DB_URL_PASSWORD_RE);
13252
13782
  if (password === null) return false;
13253
- const lower2 = password.toLowerCase();
13254
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw))) return false;
13783
+ if (isPlaceholder(password)) return false;
13255
13784
  return shannonEntropy(raw) >= 3;
13256
13785
  }
13257
13786
  function validateOtpSecret(raw) {
@@ -13464,8 +13993,9 @@ var DLP_PATTERNS = [
13464
13993
  // ── NPM ───────────────────────────────────────────────────────────────────
13465
13994
  {
13466
13995
  name: "NPM Auth Token",
13467
- regex: /_authToken\s*=\s*[A-Za-z0-9_-]{20,}/,
13996
+ regex: /_authToken\s*=\s*([A-Za-z0-9_-]{20,})/,
13468
13997
  severity: "block",
13998
+ secretGroup: 1,
13469
13999
  keywords: ["_authtoken"]
13470
14000
  },
13471
14001
  // ── JWT ───────────────────────────────────────────────────────────────────
@@ -13582,7 +14112,11 @@ var DLP_PATTERNS = [
13582
14112
  // ── PyPI ──────────────────────────────────────────────────────────────────
13583
14113
  {
13584
14114
  name: "PyPI Upload Token",
13585
- regex: /\bpypi-[A-Za-z0-9_-]{50,}\b/,
14115
+ // A PyPI token is a macaroon whose base64 body always starts with the
14116
+ // same bytes: `pypi-AgEIcHlwaS5vcmc` (pypi.org), `pypi-AgENdGVzdC5weXBp`
14117
+ // (test.pypi.org). Without the `AgE` anchor any `pypi-<long-slug>` in a
14118
+ // URL matched (node9Firewall#374).
14119
+ regex: /\bpypi-AgE[A-Za-z0-9_-]{50,}\b/,
13586
14120
  severity: "block",
13587
14121
  keywords: ["pypi-"],
13588
14122
  minEntropy: 3
@@ -13591,11 +14125,12 @@ var DLP_PATTERNS = [
13591
14125
  // contextBoost: promoted to block when assigned (e.g. AUTH_TOKEN=Bearer eyJ...)
13592
14126
  {
13593
14127
  name: "Bearer Token",
13594
- regex: /Bearer\s+[a-zA-Z0-9\-._~+/]{20,}=*/i,
14128
+ regex: /Bearer\s+([a-zA-Z0-9\-._~+/]{20,})=*/i,
13595
14129
  severity: "review",
13596
14130
  keywords: ["bearer"],
13597
14131
  contextBoost: true,
13598
- minEntropy: 3
14132
+ minEntropy: 3,
14133
+ secretGroup: 1
13599
14134
  },
13600
14135
  // ── HTTP Basic credential ─────────────────────────────────────────────────
13601
14136
  // `Authorization: Basic <base64 of user:password>`, or the bare scheme in a
@@ -13665,8 +14200,9 @@ var DLP_PATTERNS = [
13665
14200
  // ── Cloudinary ────────────────────────────────────────────────────────────
13666
14201
  {
13667
14202
  name: "Cloudinary URL",
13668
- regex: /\bcloudinary:\/\/[0-9]+:[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+/,
14203
+ regex: /\bcloudinary:\/\/[0-9]+:([a-zA-Z0-9_-]+)@[a-zA-Z0-9_-]+/,
13669
14204
  severity: "block",
14205
+ secretGroup: 1,
13670
14206
  keywords: ["cloudinary://"]
13671
14207
  },
13672
14208
  // ── Airtable ──────────────────────────────────────────────────────────────
@@ -13930,6 +14466,7 @@ var SENSITIVE_PATH_PATTERNS = [
13930
14466
  ];
13931
14467
  function matchSensitivePath2(resolvedPath, originalPath, options = {}) {
13932
14468
  const normalised = resolvedPath.replace(/\\/g, "/");
14469
+ if (options.readOnly && isPublicSshMaterial(normalised)) return null;
13933
14470
  if (!options.systemAccessHandled && isLegacySystemPath(normalised))
13934
14471
  return sensitivePathMatch(originalPath);
13935
14472
  for (const pattern of SENSITIVE_PATH_PATTERNS) {
@@ -13964,6 +14501,16 @@ function assertBuiltinPatternsAreSafe() {
13964
14501
  );
13965
14502
  }
13966
14503
  }
14504
+ for (const p of DLP_PATTERNS) {
14505
+ const groups = (new RegExp(`${p.regex.source}|`).exec("")?.length ?? 1) - 1;
14506
+ for (const index of [p.secretGroup, p.redactGroup]) {
14507
+ if (index !== void 0 && (index < 1 || index > groups)) {
14508
+ throw new Error(
14509
+ `[node9 engine] Builtin DLP pattern '${p.name}' names group ${index} of ${groups}`
14510
+ );
14511
+ }
14512
+ }
14513
+ }
13967
14514
  for (const re of SENSITIVE_PATH_PATTERNS) {
13968
14515
  if (!(0, import_safe_regex22.default)(re.source)) {
13969
14516
  throw new Error(
@@ -13995,7 +14542,8 @@ var DLP_SCAN_LIMITS = {
13995
14542
  /** Max nesting depth walked; anything deeper is NOT scanned. */
13996
14543
  maxDepth: MAX_DEPTH2
13997
14544
  };
13998
- function suppressed(pattern, raw, before = "") {
14545
+ function suppressed(pattern, m, before = "") {
14546
+ const raw = m[0];
13999
14547
  if (pattern.validate) {
14000
14548
  let ok;
14001
14549
  try {
@@ -14005,8 +14553,14 @@ function suppressed(pattern, raw, before = "") {
14005
14553
  }
14006
14554
  return !ok;
14007
14555
  }
14008
- if (DLP_STOPWORDS.some((sw) => raw.toLowerCase().includes(sw))) return true;
14009
- if (pattern.minEntropy !== void 0 && shannonEntropy(raw) < pattern.minEntropy) return true;
14556
+ const group = pattern.secretGroup !== void 0 ? m[pattern.secretGroup] : void 0;
14557
+ const secret = typeof group === "string" && group.length > 0 ? group : raw;
14558
+ if (isPlaceholder(secret) || isPhrase(secret)) return true;
14559
+ const lower2 = secret.toLowerCase();
14560
+ const prefix = pattern.keywords?.find((kw) => lower2.startsWith(kw.toLowerCase()));
14561
+ const body = prefix ? secret.slice(prefix.length) : "";
14562
+ if (prefix && (isPlaceholder(body) || isPhrase(body))) return true;
14563
+ if (pattern.minEntropy !== void 0 && shannonEntropy(secret) < pattern.minEntropy) return true;
14010
14564
  return false;
14011
14565
  }
14012
14566
  function firstAcceptedMatch(pattern, text) {
@@ -14018,7 +14572,7 @@ function firstAcceptedMatch(pattern, text) {
14018
14572
  re.lastIndex = m.index + 1;
14019
14573
  continue;
14020
14574
  }
14021
- if (!suppressed(pattern, m[0], text.slice(Math.max(0, m.index - 64), m.index))) return m[0];
14575
+ if (!suppressed(pattern, m, text.slice(Math.max(0, m.index - 64), m.index))) return m[0];
14022
14576
  }
14023
14577
  return null;
14024
14578
  }
@@ -14184,7 +14738,7 @@ function redactText(text) {
14184
14738
  continue;
14185
14739
  }
14186
14740
  result = result.replace(globalRegex, (match, ...rest) => {
14187
- if (suppressed(pattern, match)) return match;
14741
+ if (suppressed(pattern, [match, ...rest])) return match;
14188
14742
  if (!found.includes(pattern.name)) found.push(pattern.name);
14189
14743
  const marker = `[node9-redacted:${pattern.name}]`;
14190
14744
  const group = pattern.redactGroup !== void 0 && typeof rest[pattern.redactGroup - 1] === "string" ? rest[pattern.redactGroup - 1] : void 0;
@@ -14535,9 +15089,9 @@ var GitWalk = class {
14535
15089
  const name = n.Name.Value;
14536
15090
  if (n.Append) {
14537
15091
  const prev = this.appended.has(name) ? this.appended.get(name) : resolveWordLiteral(n.Value) === null ? null : void 0;
14538
- const base3 = prev === void 0 ? recordedExpansion(name) : prev;
15092
+ const base4 = prev === void 0 ? recordedExpansion(name) : prev;
14539
15093
  const piece = resolveWordLiteral(n.Value);
14540
- this.appended.set(name, typeof base3 === "string" && piece !== null ? base3 + piece : null);
15094
+ this.appended.set(name, typeof base4 === "string" && piece !== null ? base4 + piece : null);
14541
15095
  this.treeTopVars.delete(name);
14542
15096
  return true;
14543
15097
  }
@@ -15577,9 +16131,9 @@ var INSTRUCTION_NAMES = /* @__PURE__ */ new Set([
15577
16131
  var SETTINGS_RE = /\/(?:\.claude\/settings(?:\.local)?\.json|\.gemini\/settings\.json|\.codex\/hooks\.json|\.cursor\/hooks\.json)$/i;
15578
16132
  function agentFileKind(p) {
15579
16133
  const lower2 = p.toLowerCase();
15580
- const base3 = lower2.slice(lower2.lastIndexOf("/") + 1);
15581
- if (INSTRUCTION_NAMES.has(base3)) return "instructions";
15582
- if (base3 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base3))
16134
+ const base4 = lower2.slice(lower2.lastIndexOf("/") + 1);
16135
+ if (INSTRUCTION_NAMES.has(base4)) return "instructions";
16136
+ if (base4 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base4))
15583
16137
  return "instructions";
15584
16138
  if (/\/\.cursor\/rules(?:\/|$)/.test(lower2)) return "instructions";
15585
16139
  if (/\/\.claude\/projects\/[^/]+\/memory(?:\/|$)/.test(lower2)) return "memory";
@@ -15749,7 +16303,7 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
15749
16303
  skills: "agent skill",
15750
16304
  settings: "agent settings"
15751
16305
  };
15752
- const base3 = `${kindLabel[kind]} written: ${access.path}`;
16306
+ const base4 = `${kindLabel[kind]} written: ${access.path}`;
15753
16307
  if (!signal && !every) {
15754
16308
  return {
15755
16309
  decision: "allow",
@@ -15759,14 +16313,14 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
15759
16313
  path: access.path,
15760
16314
  operation: access.operation,
15761
16315
  kind,
15762
- reason: base3,
16316
+ reason: base4,
15763
16317
  ruleDescription: "The AI writes to a file every later agent session loads as instructions.",
15764
- blockedByLabel: `Node9 Files: ${base3}`,
16318
+ blockedByLabel: `Node9 Files: ${base4}`,
15765
16319
  tier: 2
15766
16320
  };
15767
16321
  }
15768
16322
  const ruleName = signal === "content" ? "review-agent-file-content" : signal === "hooks" ? "review-agent-hooks-change" : "review-agent-file-write";
15769
- const reason = signal ? `${base3} (${detail})` : base3;
16323
+ const reason = signal ? `${base4} (${detail})` : base4;
15770
16324
  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.";
15771
16325
  return {
15772
16326
  decision: value === "log" ? "allow" : value,
@@ -18033,6 +18587,7 @@ var SENSITIVE_PATTERNS = [
18033
18587
  // generic credentials files
18034
18588
  ];
18035
18589
  function isSensitivePath(p) {
18590
+ if (isPublicSshMaterial(p)) return false;
18036
18591
  return isPasswordHashPath(p) || SENSITIVE_PATTERNS.some((re) => re.test(p));
18037
18592
  }
18038
18593
  function splitOnPipe(cmd) {
@@ -18676,7 +19231,9 @@ var DAEMON_CMDLINES = [
18676
19231
  "node9 daemon start"
18677
19232
  ];
18678
19233
  var DAEMON_NAMES = ["node", "node9"];
18679
- var KILLALL_NAMES = /* @__PURE__ */ new Set(["node", "node9", "node.exe", "node9.exe"]);
19234
+ var KILLALL_NAMES = /* @__PURE__ */ new Set(["node9", "node9.exe"]);
19235
+ var ORDINARY_NODE_CMDLINES = ["node server.js"];
19236
+ var ORDINARY_NODE_NAMES = ["node"];
18680
19237
  var STOP_SYSTEMCTL = /* @__PURE__ */ new Set(["stop", "disable", "mask", "kill"]);
18681
19238
  var STOP_LAUNCHCTL = /* @__PURE__ */ new Set(["unload", "bootout", "remove", "stop", "kill", "disable"]);
18682
19239
  var PKILL_VALUE_FLAGS = /* @__PURE__ */ new Set([
@@ -18706,11 +19263,16 @@ function patternSelects(pattern, targets) {
18706
19263
  if (pieces.length === 0) return false;
18707
19264
  return targets.some((t) => pieces.every((p) => t.includes(p)));
18708
19265
  }
19266
+ function aimedAtDaemon(pattern, full) {
19267
+ return pattern.split("|").some(
19268
+ (alternative) => patternSelects(alternative, full ? DAEMON_CMDLINES : DAEMON_NAMES) && !patternSelects(alternative, full ? ORDINARY_NODE_CMDLINES : ORDINARY_NODE_NAMES)
19269
+ );
19270
+ }
18709
19271
  function sourceText(bytes, pos, end) {
18710
19272
  if (typeof pos !== "number" || typeof end !== "number" || pos < 0 || end < pos) return "";
18711
19273
  return new TextDecoder().decode(bytes.subarray(pos, end));
18712
19274
  }
18713
- var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
19275
+ var base3 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
18714
19276
  function nextOperand(words, from) {
18715
19277
  for (let i = from; i < words.length; i++) {
18716
19278
  const w = words[i];
@@ -18720,7 +19282,7 @@ function nextOperand(words, from) {
18720
19282
  return -1;
18721
19283
  }
18722
19284
  function node9Command(words, h) {
18723
- const head = base2(words[h]);
19285
+ const head = base3(words[h]);
18724
19286
  if (head !== "node9" && head !== "node9.cmd" && words[h] !== "@node9/proxy") return null;
18725
19287
  const s = nextOperand(words, h + 1);
18726
19288
  const sub = s < 0 ? "" : (words[s] ?? "").toLowerCase();
@@ -18732,7 +19294,7 @@ function node9Command(words, h) {
18732
19294
  }
18733
19295
  var HOME_PID_FILE_RE = /(?:^|[\s"'(=`])(?:~|\$HOME|\$\{HOME\}|\/home\/[^/\s]+|\/Users\/[^/\s]+|\/root)\/\.node9\/daemon\.pid/;
18734
19296
  function killsDaemon(words, texts, h, daemonPid) {
18735
- const head = base2(words[h]);
19297
+ const head = base3(words[h]);
18736
19298
  const args = words.slice(h + 1);
18737
19299
  if (head === "kill") {
18738
19300
  for (let i = 0; i < args.length; i++) {
@@ -18766,13 +19328,13 @@ function killsDaemon(words, texts, h, daemonPid) {
18766
19328
  pattern = w;
18767
19329
  }
18768
19330
  if (pattern === null) return null;
18769
- return patternSelects(pattern, full ? DAEMON_CMDLINES : DAEMON_NAMES) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
19331
+ return aimedAtDaemon(pattern, full) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
18770
19332
  }
18771
19333
  if (head === "killall") {
18772
19334
  const regex = args.some((w) => w === "-r" || w === "--regexp");
18773
19335
  for (const w of args) {
18774
19336
  if (w === null || w.startsWith("-")) continue;
18775
- if (regex ? patternSelects(w, DAEMON_NAMES) : KILLALL_NAMES.has(w.toLowerCase()))
19337
+ if (regex ? aimedAtDaemon(w, false) : KILLALL_NAMES.has(w.toLowerCase()))
18776
19338
  return `killall ${w}`;
18777
19339
  }
18778
19340
  return null;
@@ -18790,7 +19352,7 @@ function killsDaemon(words, texts, h, daemonPid) {
18790
19352
  return null;
18791
19353
  }
18792
19354
  function stopsService(words, h) {
18793
- const head = base2(words[h]);
19355
+ const head = base3(words[h]);
18794
19356
  const args = words.slice(h + 1).map((w) => (w ?? "").toLowerCase());
18795
19357
  if (head === "systemctl") {
18796
19358
  const action = args.find((w) => STOP_SYSTEMCTL.has(w));
@@ -18819,7 +19381,7 @@ function analyzeNode9Disarm(command, daemonPid = null, depth = 0) {
18819
19381
  const h = unwrapCommandHead(words);
18820
19382
  shown = node9Command(words, h) ?? killsDaemon(words, texts, h, daemonPid) ?? stopsService(words, h);
18821
19383
  if (shown === null) {
18822
- const payload = literalShellPayload(words, base2(words[0]));
19384
+ const payload = literalShellPayload(words, base3(words[0]));
18823
19385
  if (payload) {
18824
19386
  const inner = analyzeNode9Disarm(payload, daemonPid, depth + 1);
18825
19387
  if (inner) shown = inner.reason.replace(/^node9 switched off by the agent: /, "");
@@ -19514,7 +20076,15 @@ var MAX_DESTINATIONS = 200;
19514
20076
  var MAX_SCAN_CHARS = 1e5;
19515
20077
  var EMAIL_RE = /[\p{L}\p{N}._%+-]+@[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?(?:\.[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?)*\.\p{L}{2,}/gu;
19516
20078
  var URL_RE = /\b(?:[a-z][a-z0-9+.-]*:\/\/|www\.)[^\s<>"'`){}]+/gi;
19517
- var IBAN_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/g;
20079
+ var IBAN_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/gi;
20080
+ var ACCOUNT_SHAPE_RE = /^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/;
20081
+ function accountOf(written) {
20082
+ if (written !== written.toUpperCase()) return null;
20083
+ const groups = written.split(/[ -]+/);
20084
+ const printed = groups.length > 1 && groups.slice(0, -1).every((g) => g.length === 4);
20085
+ const compact = printed ? groups.join("") : groups[0];
20086
+ return ACCOUNT_SHAPE_RE.test(compact) ? compact : null;
20087
+ }
19518
20088
  var RECIPIENT_KEYS = /* @__PURE__ */ new Set([
19519
20089
  "to",
19520
20090
  "cc",
@@ -19559,11 +20129,28 @@ function hostOfUrl(value) {
19559
20129
  return null;
19560
20130
  }
19561
20131
  }
20132
+ function ibanOf(written) {
20133
+ const compact = written.replace(/[ -]/g, "").toUpperCase();
20134
+ if (!validateIban(compact)) return null;
20135
+ const length = IBAN_LENGTH[compact.slice(0, 2)];
20136
+ const iban = compact.slice(0, length);
20137
+ if (written === written.toUpperCase()) return iban;
20138
+ let at = 0;
20139
+ for (const group of written.split(/[ -]+/)) {
20140
+ at += group.length;
20141
+ if (at === length) return iban;
20142
+ if (at > length) break;
20143
+ }
20144
+ return null;
20145
+ }
19562
20146
  function addIbans(text, out) {
19563
- for (const m of text.toUpperCase().matchAll(IBAN_RE)) {
19564
- const compact = m[0].replace(/[ -]/g, "");
19565
- if (validateIban(compact)) out.add(`iban:${compact}`);
19566
- else if (/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(compact)) out.add(`account:${compact}`);
20147
+ for (const m of text.matchAll(IBAN_RE)) {
20148
+ const iban = ibanOf(m[0]);
20149
+ if (iban) out.add(`iban:${iban}`);
20150
+ else {
20151
+ const account = accountOf(m[0]);
20152
+ if (account) out.add(`account:${account}`);
20153
+ }
19567
20154
  if (out.size >= MAX_DESTINATIONS) return;
19568
20155
  }
19569
20156
  }
@@ -19611,8 +20198,8 @@ function walk2(value, key, out, depth) {
19611
20198
  s.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").replace(/^\/\//, "").split(/[/?#]/)[0].replace(/:\d+$/, "")
19612
20199
  );
19613
20200
  if (h && (h.includes(":") || /\.\p{L}{2,}$/u.test(h))) out.add(`host:${h}`);
19614
- const acct = s.replace(/[ .-]/g, "").toUpperCase();
19615
- if (/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(acct) && !validateIban(acct))
20201
+ const acct = s.replace(/[ .-]/g, "");
20202
+ if (acct === acct.toUpperCase() && ACCOUNT_SHAPE_RE.test(acct) && !validateIban(acct))
19616
20203
  out.add(`account:${acct}`);
19617
20204
  }
19618
20205
  return;
@@ -19815,8 +20402,8 @@ function hasRoutingNumber(text) {
19815
20402
  return false;
19816
20403
  }
19817
20404
  var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
19818
- function* validCardRuns(text, base3, exemptFractions = true) {
19819
- const re = new RegExp(base3.source, "g");
20405
+ function* validCardRuns(text, base4, exemptFractions = true) {
20406
+ const re = new RegExp(base4.source, "g");
19820
20407
  let m;
19821
20408
  while ((m = re.exec(text)) !== null) {
19822
20409
  const digits = m[0].replace(/\D/g, "");
@@ -19829,17 +20416,17 @@ function* validCardRuns(text, base3, exemptFractions = true) {
19829
20416
  }
19830
20417
  }
19831
20418
  function hasValidCard(text) {
19832
- for (const base3 of CARD_PATTERNS) {
19833
- if (!validCardRuns(text, base3).next().done) return true;
20419
+ for (const base4 of CARD_PATTERNS) {
20420
+ if (!validCardRuns(text, base4).next().done) return true;
19834
20421
  }
19835
20422
  return false;
19836
20423
  }
19837
20424
  function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
19838
20425
  let out = text;
19839
- for (const base3 of CARD_PATTERNS) {
20426
+ for (const base4 of CARD_PATTERNS) {
19840
20427
  let res = "";
19841
20428
  let last = 0;
19842
- for (const run of validCardRuns(out, base3, exemptFractions)) {
20429
+ for (const run of validCardRuns(out, base4, exemptFractions)) {
19843
20430
  res += out.slice(last, run.index) + replace(run.digits);
19844
20431
  last = run.index + run.length;
19845
20432
  }
@@ -20128,9 +20715,9 @@ function maskLeaf(value, key, depth) {
20128
20715
  const used = /* @__PURE__ */ new Set();
20129
20716
  return Object.fromEntries(
20130
20717
  Object.entries(value).map(([k, v]) => {
20131
- const base3 = maskPersonalData(k);
20132
- let name = base3;
20133
- for (let n = 2; used.has(name); n++) name = `${base3}#${n}`;
20718
+ const base4 = maskPersonalData(k);
20719
+ let name = base4;
20720
+ for (let n = 2; used.has(name); n++) name = `${base4}#${n}`;
20134
20721
  used.add(name);
20135
20722
  return [name, maskLeaf(v, k, depth + 1)];
20136
20723
  })
@@ -20372,7 +20959,7 @@ function classifyCall(head, args, prefixes, env, state, out) {
20372
20959
  }
20373
20960
  case "scp":
20374
20961
  case "rsync": {
20375
- const pos = positionals(args, VALUE_FLAGS[head] ?? /* @__PURE__ */ new Set()).filter(
20962
+ const pos = positionals(args, VALUE_FLAGS2[head] ?? /* @__PURE__ */ new Set()).filter(
20376
20963
  (p) => p !== null
20377
20964
  );
20378
20965
  if (pos.length < 2) return;
@@ -20994,7 +21581,7 @@ function summarizeBlast(result, opts = {}) {
20994
21581
  // src/scan/destructive-regex.ts
20995
21582
  var DESTRUCTIVE_OP_RE = /\brm\s+-[rRf]+\b|\bDROP\s+(TABLE|DATABASE|COLLECTION|SCHEMA)\b|\bTRUNCATE\s+TABLE\b|\bgit\s+push\s+(--force|-f)\b|\bFLUSHALL\b|\bFLUSHDB\b|\bkubectl\s+delete\b|\bhelm\s+uninstall\b/i;
20996
21583
  var PRIVILEGE_ESCALATION_RE = /\bchmod\s+(0?777|\+x)\b|\bchown\s+root\b/i;
20997
- var SENSITIVE_PATH_RE = /[\\/]\.aws(?:[\\/]|$)|^\.aws[\\/]|[\\/]\.ssh(?:[\\/]|$)|^\.ssh[\\/]|(?:^|[\\/])\.env(?![\w-])(?:[\w.-]*\.local$|(?!\.(?:example|sample|template)\b)(?!\.test$)[\w.-]*$)|\.config\/gcloud\/credentials\.db\b|\.docker\/config\.json\b|\.netrc\b|\.npmrc\b|\.node9\/credentials\.json\b/i;
21584
+ var SENSITIVE_PATH_RE = /[\\/]\.aws(?:[\\/]|$)|^\.aws[\\/]|[\\/]\.ssh(?:$|[\\/](?!(?:known_hosts(?:\.old)?|authorized_keys2?|[^\\/]+\.pub)$))|^\.ssh[\\/](?!(?:known_hosts(?:\.old)?|authorized_keys2?|[^\\/]+\.pub)$)|(?:^|[\\/])\.env(?![\w-])(?:[\w.-]*\.local$|(?!\.(?:example|sample|template)\b)(?!\.test$)[\w.-]*$)|\.config\/gcloud\/credentials\.db\b|\.docker\/config\.json\b|\.netrc\b|\.npmrc\b|\.node9\/credentials\.json\b/i;
20998
21585
  var FILE_TOOLS = /* @__PURE__ */ new Set([
20999
21586
  "read",
21000
21587
  "read_file",
@@ -21197,8 +21784,8 @@ function matchCanaryArgs(args, values) {
21197
21784
 
21198
21785
  // src/scan/canonical.ts
21199
21786
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
21200
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
21201
- var CANONICAL_EXTRACTOR_HASH = "1c4a57ad24e7c8c3";
21787
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v41";
21788
+ var CANONICAL_EXTRACTOR_HASH = "dbde5e7f06f3738a";
21202
21789
  var DEDUPE_PREVIEW_LEN = 120;
21203
21790
  function extractCanonicalFindings(call, ctx) {
21204
21791
  const out = [];
@@ -21701,12 +22288,14 @@ var ENGINE_VERSION = "1.4.0";
21701
22288
  PATTERN_VERB_NAMES,
21702
22289
  POSTURE_CATEGORY_OWASP,
21703
22290
  PRIVILEGE_ESCALATION_RE,
22291
+ PUBLIC_SSH_NAME_SOURCE,
21704
22292
  REALTIME_PII_PATTERNS,
21705
22293
  REPLACED_SHIELDS,
21706
22294
  SCAN_REPO_RULES_WITHOUT_RISK,
21707
22295
  SCAN_SIGNAL_WEIGHTS,
21708
22296
  SENSITIVE_PATH_RE,
21709
22297
  SENSITIVE_PATH_REGEXES,
22298
+ SHELL_INTERPRETERS,
21710
22299
  SSRF_MAX_HOST,
21711
22300
  STARTUP_NAMES,
21712
22301
  SYSTEM_AUTH_DIRS,
@@ -21807,6 +22396,7 @@ var ENGINE_VERSION = "1.4.0";
21807
22396
  isPrivateHost,
21808
22397
  isProtectedHomePath,
21809
22398
  isPublicRegistryHost,
22399
+ isPublicSshMaterial,
21810
22400
  isRecordOnly,
21811
22401
  isShellShapedTool,
21812
22402
  isShieldVerdict,