@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.mjs CHANGED
@@ -675,13 +675,27 @@ var project_jail_default = {
675
675
  {
676
676
  field: "file_path",
677
677
  op: "matches",
678
- value: "([\\/\\\\]\\.ssh([\\/\\\\]|$)|^\\.ssh[\\/\\\\])",
678
+ value: "([\\/\\\\]\\.ssh(?:$|[\\/\\\\](?!(?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$))|^\\.ssh[\\/\\\\](?!(?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$))",
679
679
  flags: "i"
680
680
  }
681
681
  ],
682
682
  verdict: "block",
683
683
  reason: "Reading SSH private keys is blocked by project-jail shield"
684
684
  },
685
+ {
686
+ name: "shield:project-jail:block-write-ssh-trust-files",
687
+ tool: "!(read|read_file|grep|grep_search)",
688
+ conditions: [
689
+ {
690
+ field: "file_path",
691
+ op: "matches",
692
+ value: "(?:^|[\\/\\\\])\\.ssh[\\/\\\\](?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$",
693
+ flags: "i"
694
+ }
695
+ ],
696
+ verdict: "block",
697
+ reason: "Changing SSH keys and trusted hosts is blocked by project-jail shield"
698
+ },
685
699
  {
686
700
  name: "shield:project-jail:block-read-aws-any-tool",
687
701
  tool: "*",
@@ -2122,15 +2136,15 @@ function ssrfExemptMatches(entries, normalized) {
2122
2136
  continue;
2123
2137
  }
2124
2138
  if (!target) continue;
2125
- const base3 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2139
+ const base4 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
2126
2140
  const prefixText = entry.slice(slash + 1);
2127
2141
  const prefix = /^\d+$/.test(prefixText) ? Number(prefixText) : NaN;
2128
- if (!base3 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2142
+ if (!base4 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
2129
2143
  // differ, so `0.0.0.0/0` does not release `::1`.
2130
- base3.length !== target.length || prefix > base3.length) {
2144
+ base4.length !== target.length || prefix > base4.length) {
2131
2145
  continue;
2132
2146
  }
2133
- if (base3.slice(0, prefix) === target.slice(0, prefix)) return true;
2147
+ if (base4.slice(0, prefix) === target.slice(0, prefix)) return true;
2134
2148
  }
2135
2149
  return false;
2136
2150
  }
@@ -3411,7 +3425,7 @@ var LEGACY_TO_ID = new Map(
3411
3425
  function ssrfCheckId(tier) {
3412
3426
  return isStrictGatedTier(tier) ? "network.internal-addresses" : "network.metadata";
3413
3427
  }
3414
- var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:block-read-(ssh|aws|env)(-any-tool)?$/;
3428
+ var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:(?:block-read-(ssh|aws|env)(-any-tool)?|block-write-ssh-trust-files)$/;
3415
3429
  var OVERRIDE_PREFIX = "Override block rule:";
3416
3430
  var LABEL_WRAPPERS = ["Smart Rule:", "Node9 (AST):", "project-jail (AST):"];
3417
3431
  function ruleNameInLabel(s) {
@@ -3929,6 +3943,14 @@ function normalizeFilePath(p, cwd = "", home = "~") {
3929
3943
  }
3930
3944
  return (rooted ? "/" : "") + parts.join("/");
3931
3945
  }
3946
+ var PUBLIC_SSH_NAME_SOURCE = String.raw`(?:known_hosts(?:\.old)?|authorized_keys2?|[^\\/]+\.pub)`;
3947
+ var PUBLIC_SSH_PATH_RE = new RegExp(
3948
+ String.raw`(?:^|[\\/])\.ssh[\\/]${PUBLIC_SSH_NAME_SOURCE}$`,
3949
+ "i"
3950
+ );
3951
+ function isPublicSshMaterial(p) {
3952
+ return PUBLIC_SSH_PATH_RE.test(p);
3953
+ }
3932
3954
 
3933
3955
  // src/shell/index.ts
3934
3956
  import picomatch from "picomatch";
@@ -4163,7 +4185,7 @@ function sedSubstitutions(script) {
4163
4185
  }
4164
4186
  return out.length > 0 ? out : null;
4165
4187
  }
4166
- function collectShellFileAccesses(command, context = {}) {
4188
+ function collectShellFileAccesses(command, context = {}, report) {
4167
4189
  const out = [];
4168
4190
  let payloads = 256;
4169
4191
  const functions = /* @__PURE__ */ new Map();
@@ -4189,7 +4211,11 @@ function collectShellFileAccesses(command, context = {}) {
4189
4211
  });
4190
4212
  }
4191
4213
  function nestedPayload(payload, state, depth) {
4192
- if (payload === null || depth >= MAX_PAYLOAD_DEPTH || payloads-- <= 0) return;
4214
+ if (payload === null) return;
4215
+ if (depth >= MAX_PAYLOAD_DEPTH || payloads-- <= 0) {
4216
+ if (report) report.exhausted = true;
4217
+ return;
4218
+ }
4193
4219
  const f = parseShared(payload);
4194
4220
  if (typeof f !== "symbol") statements(f.Stmts ?? [], state, depth + 1);
4195
4221
  }
@@ -4227,7 +4253,8 @@ function collectShellFileAccesses(command, context = {}) {
4227
4253
  }
4228
4254
  function fromWords(tokens, state, nested, depth) {
4229
4255
  const words = tokens.map((w) => w && !w.dynamic ? w.value : null);
4230
- const head = unwrapCommandHead(words, true);
4256
+ let head = unwrapCommandHead(words, true);
4257
+ if (base(words[head]) === "builtin" && ["cd", "pushd"].includes(base(words[head + 1]))) head++;
4231
4258
  const name = base(words[head]);
4232
4259
  if (name === "find") {
4233
4260
  findActions2(tokens, words, head, state, nested, depth);
@@ -4404,7 +4431,8 @@ function collectShellFileAccesses(command, context = {}) {
4404
4431
  if (!target) return;
4405
4432
  const targetSpelling = target.value || target.pattern;
4406
4433
  for (const source of operands2) {
4407
- if (name === "mv") add("remove", source, state, { recursive: true, followFinal: false });
4434
+ if (name === "mv")
4435
+ add("remove", source, state, { recursive: true, followFinal: false, copy: true });
4408
4436
  else if (name !== "ln" && !linkOnly)
4409
4437
  add("read", source, state, { recursive, followFinal: !preserveSourceLink, copy: true });
4410
4438
  if (!noDirectory)
@@ -4768,8 +4796,107 @@ function collectShellFileAccesses(command, context = {}) {
4768
4796
  }
4769
4797
  return null;
4770
4798
  }
4799
+ function heredocScript(word) {
4800
+ let text = "";
4801
+ for (const part of word?.Parts ?? []) {
4802
+ if (part?.kind === "Lit") {
4803
+ text += part.Value ?? "";
4804
+ continue;
4805
+ }
4806
+ text += resolveWordLiteral({ Parts: [part] }) ?? "$N9_UNRESOLVED";
4807
+ }
4808
+ return text;
4809
+ }
4810
+ function stdinScriptText(stmt) {
4811
+ for (const redir of stmt?.Redirs ?? []) {
4812
+ if (redir.Hdoc) return heredocScript(redir.Hdoc);
4813
+ if (redir.Op === ops().HERE_STRING) return resolveWordLiteral(redir.Word);
4814
+ }
4815
+ return null;
4816
+ }
4817
+ function printfText(stmt) {
4818
+ const cmd = stmt?.Cmd;
4819
+ if (!cmd || cmd.kind !== "CallExpr") return null;
4820
+ const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
4821
+ if (words.some((w) => w === null)) return null;
4822
+ const head = unwrapCommandHead(words);
4823
+ if (base(words[head]) !== "printf") return null;
4824
+ const rest = words.slice(head + 1);
4825
+ if (rest[0] === "--") rest.shift();
4826
+ if (rest.length === 0 || rest[0].startsWith("-")) return null;
4827
+ const [format, ...args] = rest;
4828
+ const directive = /%(?:%|[-+ #0]*(?:\d+|\*)?(?:\.(?:\d+|\*))?[a-zA-Z])/g;
4829
+ let text = "";
4830
+ let next = 0;
4831
+ for (let round = 0; round < 64; round++) {
4832
+ let used = false;
4833
+ text += format.replace(directive, (d) => {
4834
+ if (d === "%%") return "%";
4835
+ used = true;
4836
+ return args[next++] ?? "";
4837
+ });
4838
+ if (!used || next >= args.length) break;
4839
+ }
4840
+ return text;
4841
+ }
4842
+ function soleStatement(stmt) {
4843
+ let cur = stmt;
4844
+ for (let i = 0; i < 8; i++) {
4845
+ const cmd = cur?.Cmd;
4846
+ if (!cmd || cmd.kind !== "Subshell" && cmd.kind !== "Block") break;
4847
+ if ((cur.Redirs ?? []).length > 0 || (cmd.Stmts ?? []).length !== 1) break;
4848
+ cur = cmd.Stmts[0];
4849
+ }
4850
+ return cur;
4851
+ }
4852
+ function passesStdinThrough(stmt, depth = 0) {
4853
+ const cmd = stmt?.Cmd;
4854
+ if (cmd && (cmd.kind === "Subshell" || cmd.kind === "Block"))
4855
+ return depth <= 4 && (stmt.Redirs ?? []).length === 0 && (cmd.Stmts ?? []).some((inner) => passesStdinThrough(inner, depth + 1));
4856
+ if (!cmd || cmd.kind !== "CallExpr") return false;
4857
+ const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
4858
+ const head = unwrapCommandHead(words);
4859
+ const name = base(words[head]);
4860
+ const rest = words.slice(head + 1);
4861
+ if (name === "tee") return true;
4862
+ return name === "cat" && rest.every((w) => w === "-" || w !== null && /^-[A-Za-z]+$/.test(w));
4863
+ }
4864
+ function producedScripts(stmt, depth = 0) {
4865
+ const cmd = stmt?.Cmd;
4866
+ if (!cmd) return [];
4867
+ if (cmd.kind === "Subshell" || cmd.kind === "Block") {
4868
+ if (depth > 4 || (stmt.Redirs ?? []).length > 0) return [];
4869
+ const first = [];
4870
+ const last = [];
4871
+ for (const inner of cmd.Stmts ?? []) {
4872
+ const readings = producedScripts(inner, depth + 1);
4873
+ if (readings.length === 0) continue;
4874
+ first.push(readings[0]);
4875
+ last.push(readings[readings.length - 1]);
4876
+ }
4877
+ if (first.length === 0) return [];
4878
+ const a = first.join("\n");
4879
+ const b = last.join("\n");
4880
+ return a === b ? [a] : [a, b];
4881
+ }
4882
+ if (cmd.kind !== "CallExpr") return [];
4883
+ const words = (cmd.Args ?? []).map((w) => resolveWordLiteral(w));
4884
+ if (words.length === 1 && base(words[0]) === "cat") {
4885
+ const text2 = stdinScriptText(stmt);
4886
+ return text2 === null ? [] : [text2];
4887
+ }
4888
+ const formatted = printfText(stmt);
4889
+ if (formatted !== null) return [decodeAnsiC(formatted)];
4890
+ const text = producedText(stmt);
4891
+ if (text === null) return [];
4892
+ if (!text.includes("\\")) return [text];
4893
+ const head = unwrapCommandHead(words);
4894
+ const decodes = words.slice(head + 1).some((w) => w !== null && /^-[neE]+$/.test(w) && w.includes("e"));
4895
+ const decoded = decodeAnsiC(text);
4896
+ return decodes || decoded === text ? [decoded] : [text, decoded];
4897
+ }
4771
4898
  function stdinScript(stmt, state, depth) {
4772
- if (readsScriptFromStdin(stmt)) nestedPayload(stdinText(stmt), clone(state), depth);
4899
+ if (readsScriptFromStdin(stmt)) nestedPayload(stdinScriptText(stmt), clone(state), depth);
4773
4900
  }
4774
4901
  function statement(stmt, state, depth) {
4775
4902
  if (!stmt || depth > MAX_DEPTH) return;
@@ -4824,18 +4951,23 @@ function collectShellFileAccesses(command, context = {}) {
4824
4951
  }
4825
4952
  const seen = clone(state);
4826
4953
  let pureAnd = true;
4954
+ let flowing = [];
4827
4955
  segments2.forEach(({ op, part }, i) => {
4828
4956
  if (op === ops().AND || op === ops().OR) {
4829
4957
  if (i > 0 && op === ops().AND && pureAnd && state.onSuccess)
4830
4958
  state.cwd = state.onSuccess;
4831
4959
  if (i > 0 && op === ops().OR) merge(state, seen);
4960
+ flowing = [];
4832
4961
  statement(part, state, depth + 1);
4833
4962
  } else {
4834
4963
  const fed = i > 0 ? producedText(segments2[i - 1].part) : null;
4835
4964
  if (fed !== null) pipedStdin.set(part, fed);
4836
4965
  statement(part, clone(state), depth + 1);
4837
- if (i > 0 && readsScriptFromStdin(part))
4838
- nestedPayload(producedText(segments2[i - 1].part), clone(state), depth);
4966
+ const incoming = i > 0 ? flowing : [];
4967
+ if (i > 0 && readsScriptFromStdin(soleStatement(part)))
4968
+ for (const script of incoming) nestedPayload(script, clone(state), depth);
4969
+ const own = producedScripts(part);
4970
+ flowing = [...passesStdinThrough(part) ? incoming : [], ...own].slice(0, 4);
4839
4971
  if (fed !== null) nestedPayload(xargsPayload(part, fed), clone(state), depth);
4840
4972
  }
4841
4973
  if (i > 0 && op !== ops().AND) pureAnd = false;
@@ -4915,6 +5047,140 @@ function collectShellFileAccesses(command, context = {}) {
4915
5047
  return out;
4916
5048
  }
4917
5049
 
5050
+ // src/shell/dotenv-cli.ts
5051
+ var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
5052
+ var FILE_FLAGS = /* @__PURE__ */ new Set(["-f", "--file", "-e", "--env-file"]);
5053
+ var VALUE_FLAGS = /* @__PURE__ */ new Set([
5054
+ "-q",
5055
+ "--quote",
5056
+ "-v",
5057
+ "--env",
5058
+ "-fk",
5059
+ "--env-keys-file",
5060
+ "--convention",
5061
+ "--log-level"
5062
+ ]);
5063
+ var QUIET_SUBCOMMANDS = /* @__PURE__ */ new Set([
5064
+ "set",
5065
+ "unset",
5066
+ "encrypt",
5067
+ "ls",
5068
+ "help",
5069
+ "version",
5070
+ "rotate",
5071
+ "genexample",
5072
+ "gitignore",
5073
+ "prebuild",
5074
+ "precommit",
5075
+ "keypair",
5076
+ "ext"
5077
+ ]);
5078
+ function filesAfter(words, from, files) {
5079
+ for (let j = from; j < words.length; j++) {
5080
+ const w = words[j];
5081
+ if (w === null) continue;
5082
+ if (FILE_FLAGS.has(w)) {
5083
+ if (words[j + 1] !== void 0) files.push(words[j + 1]);
5084
+ j++;
5085
+ continue;
5086
+ }
5087
+ const joined = /^(?:--file|--env-file)=(.*)$/.exec(w);
5088
+ if (joined) files.push(joined[1]);
5089
+ }
5090
+ }
5091
+ function dotenvArgsStart(words, head) {
5092
+ const name = base2(words[head]);
5093
+ if (name === "dotenv" || name === "dotenv-cli" || name === "dotenvx") return head + 1;
5094
+ if (name === "bundle" && words[head + 1] === "exec" && base2(words[head + 2]) === "dotenv")
5095
+ return head + 3;
5096
+ if (/^(?:python[\d.]*|py)$/.test(name)) {
5097
+ for (let i = head + 1; i < words.length; i++) {
5098
+ const w = words[i];
5099
+ if (w === null || !w.startsWith("-")) return -1;
5100
+ if (w === "-m") return words[i + 1] === "dotenv" ? i + 2 : -1;
5101
+ if (w === "-c") return -1;
5102
+ }
5103
+ }
5104
+ return -1;
5105
+ }
5106
+ function readDotenvCli(words, head) {
5107
+ const start = dotenvArgsStart(words, head);
5108
+ if (start < 0) return null;
5109
+ const files = [];
5110
+ let print = false;
5111
+ let sawRun = false;
5112
+ let inner = -1;
5113
+ let i = start;
5114
+ while (i < words.length) {
5115
+ const w = words[i];
5116
+ if (w === null) {
5117
+ inner = i;
5118
+ break;
5119
+ }
5120
+ if (w === "--") {
5121
+ inner = i + 1;
5122
+ break;
5123
+ }
5124
+ if (FILE_FLAGS.has(w)) {
5125
+ const value = words[i + 1];
5126
+ if (!(w === "-e" && (value === "true" || value === "false")) && value !== void 0)
5127
+ files.push(value);
5128
+ i += 2;
5129
+ continue;
5130
+ }
5131
+ const joined = /^(?:--file|--env-file)=(.*)$/.exec(w);
5132
+ if (joined) {
5133
+ files.push(joined[1]);
5134
+ i++;
5135
+ continue;
5136
+ }
5137
+ if (w === "-p" || w === "--print") {
5138
+ print = true;
5139
+ i += 2;
5140
+ continue;
5141
+ }
5142
+ if (VALUE_FLAGS.has(w)) {
5143
+ i += 2;
5144
+ continue;
5145
+ }
5146
+ if (w === "-c" || w === "--cascade") {
5147
+ const value = words[i + 1];
5148
+ const after = words[i + 2];
5149
+ const takes = typeof value === "string" && !value.startsWith("-") && typeof after === "string" && after.startsWith("-");
5150
+ i += takes ? 2 : 1;
5151
+ continue;
5152
+ }
5153
+ if (w.startsWith("-")) {
5154
+ i++;
5155
+ continue;
5156
+ }
5157
+ if (!sawRun) {
5158
+ if (w === "list" || w === "get") {
5159
+ print = true;
5160
+ filesAfter(words, i + 1, files);
5161
+ break;
5162
+ }
5163
+ if (w === "run") {
5164
+ sawRun = true;
5165
+ i++;
5166
+ continue;
5167
+ }
5168
+ if (w === "decrypt") {
5169
+ print = words.slice(i + 1).some((x) => x === "--stdout");
5170
+ filesAfter(words, i + 1, files);
5171
+ break;
5172
+ }
5173
+ if (QUIET_SUBCOMMANDS.has(w)) return null;
5174
+ }
5175
+ inner = i;
5176
+ break;
5177
+ }
5178
+ const loaded = files.length > 0 ? files : [".env"];
5179
+ if (print) return { files: loaded, mode: "print", inner: -1 };
5180
+ if (inner >= 0 && inner < words.length) return { files: loaded, mode: "run", inner };
5181
+ return null;
5182
+ }
5183
+
4918
5184
  // src/shell/services.ts
4919
5185
  var INFRASTRUCTURE_SERVICES = [
4920
5186
  "init",
@@ -5274,8 +5540,19 @@ var DOTENV = {
5274
5540
  values: /\b(?:dotenv_values|get_key)\s*\(/,
5275
5541
  env: /\b(?:environ|getenv)\b/,
5276
5542
  literalPath: /\b(?:load_dotenv|dotenv_values)\s*\(\s*(?:dotenv_path\s*=\s*)?[rRbBuU]?['"]/
5543
+ },
5544
+ // Ruby's dotenv gem (node9Firewall#443): `require "dotenv/load"` loads on
5545
+ // require; `require "dotenv"` alone does not, it needs Dotenv.load.
5546
+ ruby: {
5547
+ load: /\brequire\s*\(?\s*['"]dotenv\/load['"]|\bDotenv\s*\.\s*(?:load|overload|parse)\b/,
5548
+ values: /\bDotenv\s*\.\s*parse\b/,
5549
+ env: /\bENV\b/,
5550
+ literalPath: /\bDotenv\s*\.\s*(?:load|overload|parse)\s*\(?\s*['"]/
5277
5551
  }
5278
5552
  };
5553
+ function inlineReadsEnvironment(language, code) {
5554
+ return language === "python" || language === "node" || language === "ruby" ? DOTENV[language].env.test(code) : false;
5555
+ }
5279
5556
  var DOTENV_PATH_OPTION = /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*$/;
5280
5557
  function inlineReadPaths(language, code, preload = {}) {
5281
5558
  const out = [];
@@ -5301,7 +5578,7 @@ function inlineReadPaths(language, code, preload = {}) {
5301
5578
  for (const m of code.matchAll(OPENED_NAME[language])) opened.add(m[1] ?? m[2]);
5302
5579
  for (const [name, values] of assigned) if (opened.has(name)) out.push(...values);
5303
5580
  }
5304
- if (language === "python" || language === "node") {
5581
+ if (language === "python" || language === "node" || language === "ruby") {
5305
5582
  const d = DOTENV[language];
5306
5583
  const readsEnv = d.env.test(code);
5307
5584
  const loads = /dotenv/.test(code) && d.load.test(code) && !d.literalPath.test(code);
@@ -6580,7 +6857,12 @@ var SENSITIVE_PATH_RULES = [
6580
6857
  {
6581
6858
  rule: "shield:project-jail:block-read-ssh",
6582
6859
  reason: "Reading SSH private keys is blocked by project-jail shield",
6583
- match: (p) => /([\\/]\.ssh[\\/]|^\.ssh[\\/]|^(?:[~/]|[A-Za-z]:).*[\\/]\.ssh$)/i.test(p)
6860
+ // Public material is not a key (JAIL-16): `known_hosts`, `authorized_keys`
6861
+ // and `*.pub` are readable. Because the exemption lives in the rule itself,
6862
+ // the copy tier sees `x.pub` as a destination OUTSIDE the jail, so
6863
+ // `cp ~/.ssh/id_rsa ~/.ssh/x.pub` is a reviewed copy, not a quiet rename
6864
+ // followed by an allowed read.
6865
+ match: (p) => /([\\/]\.ssh[\\/]|^\.ssh[\\/]|^(?:[~/]|[A-Za-z]:).*[\\/]\.ssh$)/i.test(p) && !isPublicSshMaterial(p)
6584
6866
  },
6585
6867
  {
6586
6868
  rule: "shield:project-jail:block-read-aws",
@@ -6949,6 +7231,7 @@ function attachedCode(interp, flag) {
6949
7231
  return rest === "" ? null : rest;
6950
7232
  }
6951
7233
  var NODE_VALUE_FLAG = /^(-r|--require|--import|--loader|--experimental-loader|--env-file|--env-file-if-exists|--input-type|-C|--conditions)(?:=(.*))?$/;
7234
+ var RUBY_VALUE_FLAG = /^-([rI])(.*)$/;
6952
7235
  function inlineExecCall(stmt, pipeFed) {
6953
7236
  const cmd = stmt?.Cmd;
6954
7237
  if (!cmd || cmd.kind !== "CallExpr") return null;
@@ -6982,6 +7265,7 @@ function inlineExecCall(stmt, pipeFed) {
6982
7265
  const codes = [];
6983
7266
  const preload = {};
6984
7267
  const nodeFamily = inlineLanguageOf(interp) === "node";
7268
+ const rubyFamily = inlineLanguageOf(interp) === "ruby";
6985
7269
  for (let i = 0; i < args.length; i++) {
6986
7270
  const a = args[i];
6987
7271
  if (nodeFamily && !selectedProgram && codes.length === 0 && a != null) {
@@ -6991,10 +7275,21 @@ function inlineExecCall(stmt, pipeFed) {
6991
7275
  if (value != null) {
6992
7276
  if (/^--env-file/.test(flag[1])) (preload.envFiles ??= []).push(value);
6993
7277
  else if (/^dotenv\/config(?:\.js)?$/.test(value)) preload.dotenv = true;
7278
+ } else if (/^--env-file/.test(flag[1])) {
7279
+ preload.unknownEnvFile = true;
6994
7280
  }
6995
7281
  continue;
6996
7282
  }
6997
7283
  }
7284
+ if (rubyFamily && !selectedProgram && codes.length === 0 && a != null) {
7285
+ const flag = RUBY_VALUE_FLAG.exec(a);
7286
+ if (flag) {
7287
+ const value = flag[2] !== "" ? flag[2] : args[++i];
7288
+ if (flag[1] === "r" && value != null && /^dotenv\/load(?:\.rb)?$/.test(value))
7289
+ preload.dotenv = true;
7290
+ continue;
7291
+ }
7292
+ }
6998
7293
  if (a == null) {
6999
7294
  if (codes.length > 0) break;
7000
7295
  positionals2++;
@@ -7333,7 +7628,7 @@ var NET_BINARIES = /* @__PURE__ */ new Set([
7333
7628
  "netcat",
7334
7629
  "rsync"
7335
7630
  ]);
7336
- var VALUE_FLAGS = {
7631
+ var VALUE_FLAGS2 = {
7337
7632
  // rsync 3.2.7, its own --help: every flag whose operand could be mistaken for
7338
7633
  // a host. `-e ssh` is the one that matters most (`ssh` is not the destination).
7339
7634
  rsync: /* @__PURE__ */ new Set([
@@ -7903,7 +8198,7 @@ function parseDestHost(token) {
7903
8198
  return null;
7904
8199
  }
7905
8200
  function destTokensForBinary(binary, args) {
7906
- const valueFlags = VALUE_FLAGS[binary] ?? /* @__PURE__ */ new Set();
8201
+ const valueFlags = VALUE_FLAGS2[binary] ?? /* @__PURE__ */ new Set();
7907
8202
  const positionals2 = [];
7908
8203
  const urlFlagValues = [];
7909
8204
  for (let i = 0; i < args.length; i++) {
@@ -8055,7 +8350,9 @@ var FS_OP_CACHE_MAX = 5e3;
8055
8350
  var fsOpCache = /* @__PURE__ */ new Map();
8056
8351
  function analyzeFsOperation(command) {
8057
8352
  const normalized = normalizeCommandForPolicy(command);
8058
- if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized))
8353
+ const stdinShell = feedsShellStdin(command) || feedsShellStdin(normalized);
8354
+ const dotenvCli = DOTENV_CLI_PRESCREEN_RE.test(command) || DOTENV_CLI_PRESCREEN_RE.test(normalized);
8355
+ if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized) && !stdinShell && !dotenvCli)
8059
8356
  return null;
8060
8357
  if (fsOpCache.has(command)) {
8061
8358
  const hit = fsOpCache.get(command) ?? null;
@@ -8063,8 +8360,11 @@ function analyzeFsOperation(command) {
8063
8360
  fsOpCache.set(command, hit);
8064
8361
  return hit;
8065
8362
  }
8066
- const direct = analyzeFsOperationImpl(command) ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8067
- const computed = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
8363
+ const changesDir = CHANGES_DIR_RE.test(command) || CHANGES_DIR_RE.test(normalized);
8364
+ const own = analyzeFsOperationImpl(command);
8365
+ const direct = (stdinShell || changesDir) && own?.verdict !== "block" ? stricter(own, structuralJailRead(command)) : own ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8366
+ const withInline = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command, changesDir));
8367
+ const computed = withInline?.verdict === "block" || !dotenvCli ? withInline : stricter(withInline, dotenvCliJailRead(command));
8068
8368
  if (fsOpCache.size >= FS_OP_CACHE_MAX) {
8069
8369
  const oldest = fsOpCache.keys().next().value;
8070
8370
  if (oldest !== void 0) fsOpCache.delete(oldest);
@@ -8074,8 +8374,8 @@ function analyzeFsOperation(command) {
8074
8374
  }
8075
8375
  var stripDotSlash = (p) => p.replace(/^\.\//, "");
8076
8376
  function isSensitiveCleanupName(p) {
8077
- const base3 = p.replace(/^.*[\\/]/, "");
8078
- 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);
8377
+ const base4 = p.replace(/^.*[\\/]/, "");
8378
+ 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);
8079
8379
  }
8080
8380
  function isWaivableCleanupTarget(p) {
8081
8381
  if (/^[/~]/.test(p) || /^\$/.test(p)) return false;
@@ -8530,6 +8830,12 @@ function matchSensitivePath(p) {
8530
8830
  return null;
8531
8831
  }
8532
8832
  var INDIRECT_SHAPE_RE = /\b(?:for|while|until|find|xargs|set|source)\b|\$\{?PWD\b|[*?[]|(?:^|[;&|(\s])\.\s/;
8833
+ var STDIN_SHELL_WORD_RE = new RegExp(
8834
+ `(?:^|[\\s;&|(/\\\\])(?:${[...SHELL_INTERPRETERS].map((name) => name.replace(/[.*+?^\${}()|[\]\\]/g, "\\$&")).join("|")})(?=$|[\\s;&|)<])`,
8835
+ "i"
8836
+ );
8837
+ var feedsShellStdin = (command) => /\||<</.test(command) && STDIN_SHELL_WORD_RE.test(command);
8838
+ var CHANGES_DIR_RE = /(?:^|[\s;&|({'"`])(?:cd|pushd)\s/;
8533
8839
  var SOURCES_FILE_RE = /(?:^|[;&|(\s])(?:source|\.)\s/;
8534
8840
  function printsEnvironment(words) {
8535
8841
  const [name, ...rest] = words;
@@ -8802,8 +9108,17 @@ function analyzeUnknownCredentialReads(command) {
8802
9108
  }
8803
9109
  return !hit;
8804
9110
  });
8805
- return hit ? {
8806
- reason: "Files are read by names a listing produces when the command runs, and the listing can include credential files"
9111
+ if (hit)
9112
+ return {
9113
+ reason: "Files are read by names a listing produces when the command runs, and the listing can include credential files"
9114
+ };
9115
+ let unknownEnvFile = false;
9116
+ try {
9117
+ unknownEnvFile = readsUnknownEnvFile(command) || dotenvCliReads(command).unknown;
9118
+ } catch {
9119
+ }
9120
+ return unknownEnvFile ? {
9121
+ 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"
8807
9122
  } : null;
8808
9123
  }
8809
9124
  var JAILED_GLOB_NAMES = [
@@ -8829,6 +9144,7 @@ function matchSensitiveGlob(glob, dotGlob) {
8829
9144
  }
8830
9145
  });
8831
9146
  glob = parts.join("/");
9147
+ if (isPublicSshMaterial(glob)) return null;
8832
9148
  const first = parts.findIndex((seg) => GLOB_META.test(seg));
8833
9149
  if (first < 0) return matchSensitivePath(glob);
8834
9150
  const prefix = parts.slice(0, first).join("/");
@@ -8853,10 +9169,17 @@ function matchSensitiveGlob(glob, dotGlob) {
8853
9169
  }
8854
9170
  return null;
8855
9171
  }
9172
+ function underEnteredDir(a, name) {
9173
+ const dir = a.cwd ?? "";
9174
+ if (!dir || /^(?:[/\\~$]|[A-Za-z]:)/.test(name)) return name;
9175
+ const rest = name.replace(/^(?:\.\/)+/, "");
9176
+ return `${dir.replace(/[/\\]+$/, "")}/${rest}`;
9177
+ }
8856
9178
  function structuralJailRead(command) {
8857
9179
  let accesses;
9180
+ const report = { exhausted: false };
8858
9181
  try {
8859
- accesses = collectShellFileAccesses(command);
9182
+ accesses = collectShellFileAccesses(command, {}, report);
8860
9183
  } catch {
8861
9184
  return null;
8862
9185
  }
@@ -8865,35 +9188,148 @@ function structuralJailRead(command) {
8865
9188
  const sourcedHit = sourcedAndPrinted(command);
8866
9189
  if (sourcedHit?.verdict === "block") return sourcedHit;
8867
9190
  let review = sourcedHit;
9191
+ let relativeCopy = null;
8868
9192
  for (const a of accesses) {
8869
- if (a.operation !== "read" || a.listing || a.recursive || a.copy) continue;
9193
+ if (a.copy && !a.listing && (a.operation === "read" || a.operation === "remove")) {
9194
+ const entered = underEnteredDir(a, a.path);
9195
+ if (entered !== a.path) relativeCopy ??= copyVerdictOf(matchSensitivePath(entered));
9196
+ continue;
9197
+ }
9198
+ if (a.operation !== "read" || a.listing || a.recursive) continue;
8870
9199
  const glob = a.glob ?? (GLOB_META.test(a.path) ? a.path : void 0);
8871
- const hit = glob ? matchSensitiveGlob(glob, !!a.dotGlob) : matchSensitivePath(a.path);
9200
+ const hit = glob ? matchSensitiveGlob(underEnteredDir(a, glob), !!a.dotGlob) : matchSensitivePath(underEnteredDir(a, a.path));
8872
9201
  if (hit?.verdict === "block") return hit;
8873
9202
  review ??= hit;
8874
9203
  }
8875
- return review;
9204
+ review = stricter(review, relativeCopy);
9205
+ return report.exhausted ? stricter(review, UNANALYSABLE_NESTING) : review;
8876
9206
  }
8877
9207
  var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
8878
9208
  var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
8879
- function inlineCodeJailRead(command) {
9209
+ function inlineCodeJailRead(command, changesDir = false) {
8880
9210
  const calls = inlineExecCalls(command);
8881
9211
  if (calls === PARSE_FAIL) return null;
8882
9212
  let review = null;
9213
+ let entered = null;
9214
+ const dirs = () => entered ??= changesDir ? enteredDirs(command) : [];
8883
9215
  for (const call of calls) {
8884
9216
  const language = inlineLanguageOf(call.interp);
8885
9217
  if (language === null) continue;
8886
9218
  for (const code of call.code) {
8887
9219
  if (code === null) continue;
8888
9220
  for (const p of inlineReadPaths(language, code, call.preload)) {
8889
- const hit = matchSensitivePath(p);
8890
- if (hit?.verdict === "block") return hit;
8891
- review ??= hit;
9221
+ const relative = !/^(?:[/\\~$]|[A-Za-z]:)/.test(p);
9222
+ const spellings = relative ? [p, ...dirs().map((d) => `${d}/${p}`)] : [p];
9223
+ for (const spelling of spellings) {
9224
+ const hit = matchSensitivePath(spelling);
9225
+ if (hit?.verdict === "block") return hit;
9226
+ review ??= hit;
9227
+ }
8892
9228
  }
8893
9229
  }
8894
9230
  }
8895
9231
  return review;
8896
9232
  }
9233
+ var MAX_ENTERED_DIRS = 16;
9234
+ function enteredDirs(command, depth = 0, out = []) {
9235
+ if (depth > 3) return out;
9236
+ try {
9237
+ walkCommandScope(command, (node) => {
9238
+ const n = node;
9239
+ if (!n || n.kind !== "CallExpr" || out.length >= MAX_ENTERED_DIRS) return true;
9240
+ const words = callWords(n);
9241
+ if (words.length === 0) return true;
9242
+ let head = unwrapCommandHead(words);
9243
+ if (baseWord(words[head]) === "builtin") head++;
9244
+ const name = baseWord(words[head]);
9245
+ if (name !== "cd" && name !== "pushd") {
9246
+ const payload = literalShellPayload(words, baseWord(words[0]));
9247
+ if (payload !== null) enteredDirs(payload, depth + 1, out);
9248
+ return true;
9249
+ }
9250
+ const target = words.slice(head + 1).find((w) => w === null || !w.startsWith("-"));
9251
+ if (!target) return true;
9252
+ const dir = target.replace(/[/\\]+$/, "");
9253
+ const rooted = /^(?:[/\\~]|[A-Za-z]:)/.test(dir);
9254
+ for (const d of rooted ? [dir] : [dir, ...out.map((prev) => `${prev}/${dir}`)])
9255
+ if (out.length < MAX_ENTERED_DIRS && !out.includes(d)) out.push(d);
9256
+ return true;
9257
+ });
9258
+ } catch {
9259
+ }
9260
+ return out;
9261
+ }
9262
+ var DOTENV_CLI_PRESCREEN_RE = /\bdotenvx?\b/i;
9263
+ var MAX_DOTENV_PAYLOAD_DEPTH = 3;
9264
+ function dotenvCliReads(command, depth = 0) {
9265
+ const out = { paths: [], unknown: false };
9266
+ if (depth > MAX_DOTENV_PAYLOAD_DEPTH || !DOTENV_CLI_PRESCREEN_RE.test(command)) return out;
9267
+ const bytes = new TextEncoder().encode(command);
9268
+ const sourceOf = (from, to) => typeof from === "number" && typeof to === "number" && from >= 0 && to > from ? new TextDecoder().decode(bytes.subarray(from, to)) : "";
9269
+ walkCommandScope(command, (node) => {
9270
+ const n = node;
9271
+ if (!n || n.kind !== "CallExpr") return true;
9272
+ const args = n.Args || [];
9273
+ const words = args.map((a) => resolveWordLiteral(a));
9274
+ if (words.length === 0) return true;
9275
+ const call = readDotenvCli(words, unwrapCommandHead(words));
9276
+ if (!call) {
9277
+ const payload = literalShellPayload(words, baseWord(words[0]));
9278
+ if (payload !== null) {
9279
+ const inner = dotenvCliReads(payload, depth + 1);
9280
+ out.paths.push(...inner.paths);
9281
+ out.unknown ||= inner.unknown;
9282
+ }
9283
+ return true;
9284
+ }
9285
+ let shown = call.mode === "print";
9286
+ if (!shown) {
9287
+ const inner = words.slice(call.inner);
9288
+ const literal = (ws) => ws.length > 0 && ws.every((w) => w !== null);
9289
+ const plain = inner.slice(unwrapCommandHead(inner));
9290
+ shown = literal(inner) && printsEnvironment(inner) || literal(plain) && printsEnvironment(plain);
9291
+ const payload = shown ? null : literalShellPayload(inner, baseWord(inner[0]));
9292
+ if (payload !== null && sourcedAndPrinted(`. .env
9293
+ ${payload}`) !== null) shown = true;
9294
+ if (!shown) {
9295
+ const text = sourceOf(args[call.inner]?.pos, args[args.length - 1]?.end);
9296
+ const calls = text ? inlineExecCalls(text) : [];
9297
+ if (calls !== PARSE_FAIL)
9298
+ shown = calls.some((c) => {
9299
+ const language = inlineLanguageOf(c.interp);
9300
+ return language !== null && c.code.some((code) => code !== null && inlineReadsEnvironment(language, code));
9301
+ });
9302
+ }
9303
+ }
9304
+ if (!shown) return true;
9305
+ for (const file of call.files) {
9306
+ if (file === null) out.unknown = true;
9307
+ else out.paths.push(file);
9308
+ }
9309
+ return true;
9310
+ });
9311
+ return out;
9312
+ }
9313
+ function dotenvCliJailRead(command) {
9314
+ let result = null;
9315
+ try {
9316
+ for (const p of dotenvCliReads(command).paths) {
9317
+ result = stricter(result, matchSensitivePath(p));
9318
+ if (result?.verdict === "block") break;
9319
+ }
9320
+ } catch {
9321
+ }
9322
+ return result;
9323
+ }
9324
+ function readsUnknownEnvFile(command) {
9325
+ if (!/--env-file/.test(command)) return false;
9326
+ const calls = inlineExecCalls(command);
9327
+ if (calls === PARSE_FAIL) return false;
9328
+ return calls.some((c) => {
9329
+ const language = inlineLanguageOf(c.interp);
9330
+ return c.preload?.unknownEnvFile === true && language !== null && c.code.some((code) => code !== null && inlineReadsEnvironment(language, code));
9331
+ });
9332
+ }
8897
9333
  function baseWord(w) {
8898
9334
  return (w ?? "").split("/").pop()?.toLowerCase() ?? "";
8899
9335
  }
@@ -12033,6 +12469,120 @@ function secretViews(text, budget) {
12033
12469
  return out;
12034
12470
  }
12035
12471
 
12472
+ // src/dlp/placeholder.ts
12473
+ var TEMPLATE_RE = /\$\{|\{\{|%\{|<[^<>\s]{1,80}>/;
12474
+ var RUN_RE = /(.)\1{7}/;
12475
+ var DOMINANT_SHARE = 0.6;
12476
+ var DOC_WORDS = ["example", "sample", "fake", "dummy", "placeholder", "changeme", "redacted"];
12477
+ var STANDALONE_WORDS = /* @__PURE__ */ new Set([...DOC_WORDS, "your", "here", "insert", "replace"]);
12478
+ var DOC_EDGE_RE = new RegExp(
12479
+ `^(?:${DOC_WORDS.join("|")})|(?:${DOC_WORDS.join("|")})(?:[_-]?(?:key|token|secret))?$`
12480
+ );
12481
+ var VOCABULARY = [
12482
+ ...DOC_WORDS,
12483
+ "your",
12484
+ "here",
12485
+ "insert",
12486
+ "replace",
12487
+ "put",
12488
+ "change",
12489
+ "goes",
12490
+ "with",
12491
+ "this",
12492
+ "please",
12493
+ "real",
12494
+ "actual",
12495
+ "me",
12496
+ "my",
12497
+ "the",
12498
+ "an",
12499
+ "key",
12500
+ "token",
12501
+ "secret",
12502
+ "password",
12503
+ "passwd",
12504
+ "api",
12505
+ "apikey",
12506
+ "access",
12507
+ "auth",
12508
+ "test",
12509
+ "value",
12510
+ "xxx"
12511
+ ];
12512
+ var VOCABULARY_SET = new Set(VOCABULARY);
12513
+ var MAX_COMPOSED_SEGMENT = 48;
12514
+ function madeOfVocabulary(segment) {
12515
+ if (VOCABULARY_SET.has(segment)) return true;
12516
+ if (segment.length > MAX_COMPOSED_SEGMENT) return false;
12517
+ const reachable = new Array(segment.length + 1).fill(false);
12518
+ reachable[0] = true;
12519
+ for (let i = 0; i < segment.length; i++) {
12520
+ if (!reachable[i]) continue;
12521
+ for (const word of VOCABULARY) {
12522
+ if (segment.startsWith(word, i)) reachable[i + word.length] = true;
12523
+ }
12524
+ }
12525
+ return reachable[segment.length];
12526
+ }
12527
+ var isUpper = (c) => c >= 65 && c <= 90;
12528
+ var isLower = (c) => c >= 97 && c <= 122;
12529
+ function alphabeticSegments(token) {
12530
+ const segments2 = [];
12531
+ let start = -1;
12532
+ const close = (end) => {
12533
+ if (start >= 0) segments2.push(token.slice(start, end).toLowerCase());
12534
+ start = -1;
12535
+ };
12536
+ for (let i = 0; i < token.length; i++) {
12537
+ const c = token.charCodeAt(i);
12538
+ if (!isUpper(c) && !isLower(c)) {
12539
+ close(i);
12540
+ continue;
12541
+ }
12542
+ if (start >= 0 && isUpper(c)) {
12543
+ const prev = token.charCodeAt(i - 1);
12544
+ const next = i + 1 < token.length ? token.charCodeAt(i + 1) : 0;
12545
+ if (isLower(prev) || isUpper(prev) && isLower(next)) close(i);
12546
+ }
12547
+ if (start < 0) start = i;
12548
+ }
12549
+ close(token.length);
12550
+ return segments2;
12551
+ }
12552
+ function dominatedByOneChar(s) {
12553
+ if (s.length < 4) return false;
12554
+ const counts = /* @__PURE__ */ new Map();
12555
+ let top = 0;
12556
+ for (const ch of s) {
12557
+ const n = (counts.get(ch) ?? 0) + 1;
12558
+ counts.set(ch, n);
12559
+ if (n > top) top = n;
12560
+ }
12561
+ return top / s.length >= DOMINANT_SHARE;
12562
+ }
12563
+ var MAX_PHRASE_LENGTH = 160;
12564
+ function builtFromVocabulary(token) {
12565
+ if (token.length > MAX_PHRASE_LENGTH) return false;
12566
+ const segments2 = alphabeticSegments(token);
12567
+ if (segments2.length === 0 || !segments2.every(madeOfVocabulary)) return false;
12568
+ const letters = token.replace(/[^A-Za-z]/g, "").length;
12569
+ const alphanumerics = token.replace(/[^A-Za-z0-9]/g, "").length;
12570
+ return letters * 2 >= alphanumerics;
12571
+ }
12572
+ var PHRASE_RE = /^[a-z]{1,20}(?:[-_.][a-z]{1,20}){2,}$/;
12573
+ function isPhrase(secret) {
12574
+ return PHRASE_RE.test(secret);
12575
+ }
12576
+ function isPlaceholder(secret) {
12577
+ if (secret.length === 0) return false;
12578
+ if (TEMPLATE_RE.test(secret)) return true;
12579
+ if (RUN_RE.test(secret) || dominatedByOneChar(secret)) return true;
12580
+ const lower2 = secret.toLowerCase();
12581
+ if (lower2.split(/[^a-z0-9]+/).some((part) => STANDALONE_WORDS.has(part))) return true;
12582
+ if (DOC_EDGE_RE.test(lower2)) return true;
12583
+ return builtFromVocabulary(secret);
12584
+ }
12585
+
12036
12586
  // src/scan/checksums.ts
12037
12587
  import { createHash as createHash2 } from "crypto";
12038
12588
  function validateLuhn(digits) {
@@ -12155,12 +12705,19 @@ var IBAN_LENGTH = {
12155
12705
  YE: 30
12156
12706
  };
12157
12707
  var IBAN_BBAN_SHAPE = {
12708
+ // AD, AE, BA, EE: the registered countries whose code is two hex letters
12709
+ // and that had no shape here, so a hex id with that prefix and a lucky
12710
+ // mod-97 read as an IBAN (node9Firewall#369).
12711
+ AD: /^\d{8}[A-Z0-9]{12}$/,
12712
+ AE: /^\d{19}$/,
12158
12713
  AT: /^\d{16}$/,
12714
+ BA: /^\d{16}$/,
12159
12715
  BE: /^\d{12}$/,
12160
12716
  CH: /^\d{5}[A-Z0-9]{12}$/,
12161
12717
  CZ: /^\d{20}$/,
12162
12718
  DE: /^\d{18}$/,
12163
12719
  DK: /^\d{14}$/,
12720
+ EE: /^\d{16}$/,
12164
12721
  ES: /^\d{20}$/,
12165
12722
  FI: /^\d{14}$/,
12166
12723
  FR: /^\d{10}[A-Z0-9]{11}\d{2}$/,
@@ -12580,9 +13137,9 @@ function validateBelgianNationalNumber(raw) {
12580
13137
  if (!/^\d{11}$/.test(d)) return false;
12581
13138
  const month = Number(d.slice(2, 4)) % 20;
12582
13139
  if (month !== 0 && !plausibleDate(String(month).padStart(2, "0"), d.slice(4, 6))) return false;
12583
- const base3 = Number(d.slice(0, 9));
13140
+ const base4 = Number(d.slice(0, 9));
12584
13141
  const check = Number(d.slice(9, 11));
12585
- return 97 - base3 % 97 === check || 97 - (2e9 + base3) % 97 === check;
13142
+ return 97 - base4 % 97 === check || 97 - (2e9 + base4) % 97 === check;
12586
13143
  }
12587
13144
  function validateCuit(raw) {
12588
13145
  const d = raw.replace(/-/g, "");
@@ -12709,32 +13266,6 @@ function shannonEntropy(s) {
12709
13266
  }
12710
13267
  return h;
12711
13268
  }
12712
- var DLP_STOPWORDS = [
12713
- "example",
12714
- "placeholder",
12715
- "changeme",
12716
- "your_key",
12717
- "your_token",
12718
- "your_secret",
12719
- "replace_me",
12720
- "insert_key",
12721
- "put_your",
12722
- "fake",
12723
- "dummy",
12724
- "sample",
12725
- "xxxxxxxx",
12726
- "aaaaaa",
12727
- "bbbbbb",
12728
- "00000000",
12729
- "${",
12730
- "{{",
12731
- "%{",
12732
- "<your",
12733
- "test_key",
12734
- "test_token",
12735
- "your",
12736
- "here"
12737
- ];
12738
13269
  function capturedValue(raw, pattern) {
12739
13270
  const m = raw.match(pattern);
12740
13271
  return m?.[1] ?? null;
@@ -12767,8 +13298,7 @@ function rejectedByStructuredValidator(value) {
12767
13298
  }
12768
13299
  function looksGenerated(value, minLength, minEntropy, lettersOnlyAllowed = false) {
12769
13300
  if (value.length < minLength) return false;
12770
- const lower2 = value.toLowerCase();
12771
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw))) return false;
13301
+ if (isPlaceholder(value)) return false;
12772
13302
  if (REFERENCE_VALUE_RE.test(value)) return false;
12773
13303
  if (!lettersOnlyAllowed && IDENTIFIER_VALUE_RE.test(value)) return false;
12774
13304
  if (EMAIL_VALUE_RE.test(value)) return false;
@@ -12919,9 +13449,7 @@ var SQL_PASSWORD_VALUE_RE = /['"]([^'"\s]{8,128})['"]$/;
12919
13449
  function validateSqlPassword(raw) {
12920
13450
  const value = capturedValue(raw, SQL_PASSWORD_VALUE_RE);
12921
13451
  if (value === null) return false;
12922
- const lower2 = value.toLowerCase();
12923
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || REFERENCE_VALUE_RE.test(value))
12924
- return false;
13452
+ if (isPlaceholder(value) || REFERENCE_VALUE_RE.test(value)) return false;
12925
13453
  if (/^[a-z]+$/i.test(value) && value.length < 12) return false;
12926
13454
  return shannonEntropy(value) >= 2.5 && !hasSequentialRun(value);
12927
13455
  }
@@ -12956,8 +13484,7 @@ function validateBasicCredential(raw, before = "") {
12956
13484
  if (!pair) return false;
12957
13485
  const password = pair[2];
12958
13486
  if (!/[0-9]/.test(password) || !/[A-Za-z]/.test(password)) return false;
12959
- const lower2 = password.toLowerCase();
12960
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || hasSequentialRun(password)) return false;
13487
+ if (isPlaceholder(password) || hasSequentialRun(password)) return false;
12961
13488
  return shannonEntropy(password) >= 3;
12962
13489
  }
12963
13490
  function headerPairIsCredential(text) {
@@ -12975,7 +13502,7 @@ function validateDropboxSecret(raw) {
12975
13502
  const value = capturedValue(raw, DROPBOX_SECRET_RE);
12976
13503
  if (value === null || value !== value.toLowerCase()) return false;
12977
13504
  if (!/[0-9]/.test(value) || !/[a-z]/.test(value)) return false;
12978
- if (DLP_STOPWORDS.some((sw) => value.includes(sw)) || hasSequentialRun(value)) return false;
13505
+ if (isPlaceholder(value) || hasSequentialRun(value)) return false;
12979
13506
  return shannonEntropy(value) >= 3;
12980
13507
  }
12981
13508
  var OTP_CAPTURE_RE = /["']([A-Z2-7]{16,128}=*)["']$/i;
@@ -12983,8 +13510,7 @@ var DB_URL_PASSWORD_RE = /:\/\/[^:/\s@]*:([^@\s]{4,})@/;
12983
13510
  function validateDbConnectionString(raw) {
12984
13511
  const password = capturedValue(raw, DB_URL_PASSWORD_RE);
12985
13512
  if (password === null) return false;
12986
- const lower2 = password.toLowerCase();
12987
- if (DLP_STOPWORDS.some((sw) => lower2.includes(sw))) return false;
13513
+ if (isPlaceholder(password)) return false;
12988
13514
  return shannonEntropy(raw) >= 3;
12989
13515
  }
12990
13516
  function validateOtpSecret(raw) {
@@ -13197,8 +13723,9 @@ var DLP_PATTERNS = [
13197
13723
  // ── NPM ───────────────────────────────────────────────────────────────────
13198
13724
  {
13199
13725
  name: "NPM Auth Token",
13200
- regex: /_authToken\s*=\s*[A-Za-z0-9_-]{20,}/,
13726
+ regex: /_authToken\s*=\s*([A-Za-z0-9_-]{20,})/,
13201
13727
  severity: "block",
13728
+ secretGroup: 1,
13202
13729
  keywords: ["_authtoken"]
13203
13730
  },
13204
13731
  // ── JWT ───────────────────────────────────────────────────────────────────
@@ -13315,7 +13842,11 @@ var DLP_PATTERNS = [
13315
13842
  // ── PyPI ──────────────────────────────────────────────────────────────────
13316
13843
  {
13317
13844
  name: "PyPI Upload Token",
13318
- regex: /\bpypi-[A-Za-z0-9_-]{50,}\b/,
13845
+ // A PyPI token is a macaroon whose base64 body always starts with the
13846
+ // same bytes: `pypi-AgEIcHlwaS5vcmc` (pypi.org), `pypi-AgENdGVzdC5weXBp`
13847
+ // (test.pypi.org). Without the `AgE` anchor any `pypi-<long-slug>` in a
13848
+ // URL matched (node9Firewall#374).
13849
+ regex: /\bpypi-AgE[A-Za-z0-9_-]{50,}\b/,
13319
13850
  severity: "block",
13320
13851
  keywords: ["pypi-"],
13321
13852
  minEntropy: 3
@@ -13324,11 +13855,12 @@ var DLP_PATTERNS = [
13324
13855
  // contextBoost: promoted to block when assigned (e.g. AUTH_TOKEN=Bearer eyJ...)
13325
13856
  {
13326
13857
  name: "Bearer Token",
13327
- regex: /Bearer\s+[a-zA-Z0-9\-._~+/]{20,}=*/i,
13858
+ regex: /Bearer\s+([a-zA-Z0-9\-._~+/]{20,})=*/i,
13328
13859
  severity: "review",
13329
13860
  keywords: ["bearer"],
13330
13861
  contextBoost: true,
13331
- minEntropy: 3
13862
+ minEntropy: 3,
13863
+ secretGroup: 1
13332
13864
  },
13333
13865
  // ── HTTP Basic credential ─────────────────────────────────────────────────
13334
13866
  // `Authorization: Basic <base64 of user:password>`, or the bare scheme in a
@@ -13398,8 +13930,9 @@ var DLP_PATTERNS = [
13398
13930
  // ── Cloudinary ────────────────────────────────────────────────────────────
13399
13931
  {
13400
13932
  name: "Cloudinary URL",
13401
- regex: /\bcloudinary:\/\/[0-9]+:[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+/,
13933
+ regex: /\bcloudinary:\/\/[0-9]+:([a-zA-Z0-9_-]+)@[a-zA-Z0-9_-]+/,
13402
13934
  severity: "block",
13935
+ secretGroup: 1,
13403
13936
  keywords: ["cloudinary://"]
13404
13937
  },
13405
13938
  // ── Airtable ──────────────────────────────────────────────────────────────
@@ -13663,6 +14196,7 @@ var SENSITIVE_PATH_PATTERNS = [
13663
14196
  ];
13664
14197
  function matchSensitivePath2(resolvedPath, originalPath, options = {}) {
13665
14198
  const normalised = resolvedPath.replace(/\\/g, "/");
14199
+ if (options.readOnly && isPublicSshMaterial(normalised)) return null;
13666
14200
  if (!options.systemAccessHandled && isLegacySystemPath(normalised))
13667
14201
  return sensitivePathMatch(originalPath);
13668
14202
  for (const pattern of SENSITIVE_PATH_PATTERNS) {
@@ -13697,6 +14231,16 @@ function assertBuiltinPatternsAreSafe() {
13697
14231
  );
13698
14232
  }
13699
14233
  }
14234
+ for (const p of DLP_PATTERNS) {
14235
+ const groups = (new RegExp(`${p.regex.source}|`).exec("")?.length ?? 1) - 1;
14236
+ for (const index of [p.secretGroup, p.redactGroup]) {
14237
+ if (index !== void 0 && (index < 1 || index > groups)) {
14238
+ throw new Error(
14239
+ `[node9 engine] Builtin DLP pattern '${p.name}' names group ${index} of ${groups}`
14240
+ );
14241
+ }
14242
+ }
14243
+ }
13700
14244
  for (const re of SENSITIVE_PATH_PATTERNS) {
13701
14245
  if (!safeRegex2(re.source)) {
13702
14246
  throw new Error(
@@ -13728,7 +14272,8 @@ var DLP_SCAN_LIMITS = {
13728
14272
  /** Max nesting depth walked; anything deeper is NOT scanned. */
13729
14273
  maxDepth: MAX_DEPTH2
13730
14274
  };
13731
- function suppressed(pattern, raw, before = "") {
14275
+ function suppressed(pattern, m, before = "") {
14276
+ const raw = m[0];
13732
14277
  if (pattern.validate) {
13733
14278
  let ok;
13734
14279
  try {
@@ -13738,8 +14283,14 @@ function suppressed(pattern, raw, before = "") {
13738
14283
  }
13739
14284
  return !ok;
13740
14285
  }
13741
- if (DLP_STOPWORDS.some((sw) => raw.toLowerCase().includes(sw))) return true;
13742
- if (pattern.minEntropy !== void 0 && shannonEntropy(raw) < pattern.minEntropy) return true;
14286
+ const group = pattern.secretGroup !== void 0 ? m[pattern.secretGroup] : void 0;
14287
+ const secret = typeof group === "string" && group.length > 0 ? group : raw;
14288
+ if (isPlaceholder(secret) || isPhrase(secret)) return true;
14289
+ const lower2 = secret.toLowerCase();
14290
+ const prefix = pattern.keywords?.find((kw) => lower2.startsWith(kw.toLowerCase()));
14291
+ const body = prefix ? secret.slice(prefix.length) : "";
14292
+ if (prefix && (isPlaceholder(body) || isPhrase(body))) return true;
14293
+ if (pattern.minEntropy !== void 0 && shannonEntropy(secret) < pattern.minEntropy) return true;
13743
14294
  return false;
13744
14295
  }
13745
14296
  function firstAcceptedMatch(pattern, text) {
@@ -13751,7 +14302,7 @@ function firstAcceptedMatch(pattern, text) {
13751
14302
  re.lastIndex = m.index + 1;
13752
14303
  continue;
13753
14304
  }
13754
- if (!suppressed(pattern, m[0], text.slice(Math.max(0, m.index - 64), m.index))) return m[0];
14305
+ if (!suppressed(pattern, m, text.slice(Math.max(0, m.index - 64), m.index))) return m[0];
13755
14306
  }
13756
14307
  return null;
13757
14308
  }
@@ -13917,7 +14468,7 @@ function redactText(text) {
13917
14468
  continue;
13918
14469
  }
13919
14470
  result = result.replace(globalRegex, (match, ...rest) => {
13920
- if (suppressed(pattern, match)) return match;
14471
+ if (suppressed(pattern, [match, ...rest])) return match;
13921
14472
  if (!found.includes(pattern.name)) found.push(pattern.name);
13922
14473
  const marker = `[node9-redacted:${pattern.name}]`;
13923
14474
  const group = pattern.redactGroup !== void 0 && typeof rest[pattern.redactGroup - 1] === "string" ? rest[pattern.redactGroup - 1] : void 0;
@@ -14268,9 +14819,9 @@ var GitWalk = class {
14268
14819
  const name = n.Name.Value;
14269
14820
  if (n.Append) {
14270
14821
  const prev = this.appended.has(name) ? this.appended.get(name) : resolveWordLiteral(n.Value) === null ? null : void 0;
14271
- const base3 = prev === void 0 ? recordedExpansion(name) : prev;
14822
+ const base4 = prev === void 0 ? recordedExpansion(name) : prev;
14272
14823
  const piece = resolveWordLiteral(n.Value);
14273
- this.appended.set(name, typeof base3 === "string" && piece !== null ? base3 + piece : null);
14824
+ this.appended.set(name, typeof base4 === "string" && piece !== null ? base4 + piece : null);
14274
14825
  this.treeTopVars.delete(name);
14275
14826
  return true;
14276
14827
  }
@@ -15310,9 +15861,9 @@ var INSTRUCTION_NAMES = /* @__PURE__ */ new Set([
15310
15861
  var SETTINGS_RE = /\/(?:\.claude\/settings(?:\.local)?\.json|\.gemini\/settings\.json|\.codex\/hooks\.json|\.cursor\/hooks\.json)$/i;
15311
15862
  function agentFileKind(p) {
15312
15863
  const lower2 = p.toLowerCase();
15313
- const base3 = lower2.slice(lower2.lastIndexOf("/") + 1);
15314
- if (INSTRUCTION_NAMES.has(base3)) return "instructions";
15315
- if (base3 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base3))
15864
+ const base4 = lower2.slice(lower2.lastIndexOf("/") + 1);
15865
+ if (INSTRUCTION_NAMES.has(base4)) return "instructions";
15866
+ if (base4 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base4))
15316
15867
  return "instructions";
15317
15868
  if (/\/\.cursor\/rules(?:\/|$)/.test(lower2)) return "instructions";
15318
15869
  if (/\/\.claude\/projects\/[^/]+\/memory(?:\/|$)/.test(lower2)) return "memory";
@@ -15482,7 +16033,7 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
15482
16033
  skills: "agent skill",
15483
16034
  settings: "agent settings"
15484
16035
  };
15485
- const base3 = `${kindLabel[kind]} written: ${access.path}`;
16036
+ const base4 = `${kindLabel[kind]} written: ${access.path}`;
15486
16037
  if (!signal && !every) {
15487
16038
  return {
15488
16039
  decision: "allow",
@@ -15492,14 +16043,14 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
15492
16043
  path: access.path,
15493
16044
  operation: access.operation,
15494
16045
  kind,
15495
- reason: base3,
16046
+ reason: base4,
15496
16047
  ruleDescription: "The AI writes to a file every later agent session loads as instructions.",
15497
- blockedByLabel: `Node9 Files: ${base3}`,
16048
+ blockedByLabel: `Node9 Files: ${base4}`,
15498
16049
  tier: 2
15499
16050
  };
15500
16051
  }
15501
16052
  const ruleName = signal === "content" ? "review-agent-file-content" : signal === "hooks" ? "review-agent-hooks-change" : "review-agent-file-write";
15502
- const reason = signal ? `${base3} (${detail})` : base3;
16053
+ const reason = signal ? `${base4} (${detail})` : base4;
15503
16054
  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.";
15504
16055
  return {
15505
16056
  decision: value === "log" ? "allow" : value,
@@ -17766,6 +18317,7 @@ var SENSITIVE_PATTERNS = [
17766
18317
  // generic credentials files
17767
18318
  ];
17768
18319
  function isSensitivePath(p) {
18320
+ if (isPublicSshMaterial(p)) return false;
17769
18321
  return isPasswordHashPath(p) || SENSITIVE_PATTERNS.some((re) => re.test(p));
17770
18322
  }
17771
18323
  function splitOnPipe(cmd) {
@@ -18409,7 +18961,9 @@ var DAEMON_CMDLINES = [
18409
18961
  "node9 daemon start"
18410
18962
  ];
18411
18963
  var DAEMON_NAMES = ["node", "node9"];
18412
- var KILLALL_NAMES = /* @__PURE__ */ new Set(["node", "node9", "node.exe", "node9.exe"]);
18964
+ var KILLALL_NAMES = /* @__PURE__ */ new Set(["node9", "node9.exe"]);
18965
+ var ORDINARY_NODE_CMDLINES = ["node server.js"];
18966
+ var ORDINARY_NODE_NAMES = ["node"];
18413
18967
  var STOP_SYSTEMCTL = /* @__PURE__ */ new Set(["stop", "disable", "mask", "kill"]);
18414
18968
  var STOP_LAUNCHCTL = /* @__PURE__ */ new Set(["unload", "bootout", "remove", "stop", "kill", "disable"]);
18415
18969
  var PKILL_VALUE_FLAGS = /* @__PURE__ */ new Set([
@@ -18439,11 +18993,16 @@ function patternSelects(pattern, targets) {
18439
18993
  if (pieces.length === 0) return false;
18440
18994
  return targets.some((t) => pieces.every((p) => t.includes(p)));
18441
18995
  }
18996
+ function aimedAtDaemon(pattern, full) {
18997
+ return pattern.split("|").some(
18998
+ (alternative) => patternSelects(alternative, full ? DAEMON_CMDLINES : DAEMON_NAMES) && !patternSelects(alternative, full ? ORDINARY_NODE_CMDLINES : ORDINARY_NODE_NAMES)
18999
+ );
19000
+ }
18442
19001
  function sourceText(bytes, pos, end) {
18443
19002
  if (typeof pos !== "number" || typeof end !== "number" || pos < 0 || end < pos) return "";
18444
19003
  return new TextDecoder().decode(bytes.subarray(pos, end));
18445
19004
  }
18446
- var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
19005
+ var base3 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
18447
19006
  function nextOperand(words, from) {
18448
19007
  for (let i = from; i < words.length; i++) {
18449
19008
  const w = words[i];
@@ -18453,7 +19012,7 @@ function nextOperand(words, from) {
18453
19012
  return -1;
18454
19013
  }
18455
19014
  function node9Command(words, h) {
18456
- const head = base2(words[h]);
19015
+ const head = base3(words[h]);
18457
19016
  if (head !== "node9" && head !== "node9.cmd" && words[h] !== "@node9/proxy") return null;
18458
19017
  const s = nextOperand(words, h + 1);
18459
19018
  const sub = s < 0 ? "" : (words[s] ?? "").toLowerCase();
@@ -18465,7 +19024,7 @@ function node9Command(words, h) {
18465
19024
  }
18466
19025
  var HOME_PID_FILE_RE = /(?:^|[\s"'(=`])(?:~|\$HOME|\$\{HOME\}|\/home\/[^/\s]+|\/Users\/[^/\s]+|\/root)\/\.node9\/daemon\.pid/;
18467
19026
  function killsDaemon(words, texts, h, daemonPid) {
18468
- const head = base2(words[h]);
19027
+ const head = base3(words[h]);
18469
19028
  const args = words.slice(h + 1);
18470
19029
  if (head === "kill") {
18471
19030
  for (let i = 0; i < args.length; i++) {
@@ -18499,13 +19058,13 @@ function killsDaemon(words, texts, h, daemonPid) {
18499
19058
  pattern = w;
18500
19059
  }
18501
19060
  if (pattern === null) return null;
18502
- return patternSelects(pattern, full ? DAEMON_CMDLINES : DAEMON_NAMES) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
19061
+ return aimedAtDaemon(pattern, full) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
18503
19062
  }
18504
19063
  if (head === "killall") {
18505
19064
  const regex = args.some((w) => w === "-r" || w === "--regexp");
18506
19065
  for (const w of args) {
18507
19066
  if (w === null || w.startsWith("-")) continue;
18508
- if (regex ? patternSelects(w, DAEMON_NAMES) : KILLALL_NAMES.has(w.toLowerCase()))
19067
+ if (regex ? aimedAtDaemon(w, false) : KILLALL_NAMES.has(w.toLowerCase()))
18509
19068
  return `killall ${w}`;
18510
19069
  }
18511
19070
  return null;
@@ -18523,7 +19082,7 @@ function killsDaemon(words, texts, h, daemonPid) {
18523
19082
  return null;
18524
19083
  }
18525
19084
  function stopsService(words, h) {
18526
- const head = base2(words[h]);
19085
+ const head = base3(words[h]);
18527
19086
  const args = words.slice(h + 1).map((w) => (w ?? "").toLowerCase());
18528
19087
  if (head === "systemctl") {
18529
19088
  const action = args.find((w) => STOP_SYSTEMCTL.has(w));
@@ -18552,7 +19111,7 @@ function analyzeNode9Disarm(command, daemonPid = null, depth = 0) {
18552
19111
  const h = unwrapCommandHead(words);
18553
19112
  shown = node9Command(words, h) ?? killsDaemon(words, texts, h, daemonPid) ?? stopsService(words, h);
18554
19113
  if (shown === null) {
18555
- const payload = literalShellPayload(words, base2(words[0]));
19114
+ const payload = literalShellPayload(words, base3(words[0]));
18556
19115
  if (payload) {
18557
19116
  const inner = analyzeNode9Disarm(payload, daemonPid, depth + 1);
18558
19117
  if (inner) shown = inner.reason.replace(/^node9 switched off by the agent: /, "");
@@ -19247,7 +19806,15 @@ var MAX_DESTINATIONS = 200;
19247
19806
  var MAX_SCAN_CHARS = 1e5;
19248
19807
  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;
19249
19808
  var URL_RE = /\b(?:[a-z][a-z0-9+.-]*:\/\/|www\.)[^\s<>"'`){}]+/gi;
19250
- var IBAN_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/g;
19809
+ var IBAN_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/gi;
19810
+ var ACCOUNT_SHAPE_RE = /^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/;
19811
+ function accountOf(written) {
19812
+ if (written !== written.toUpperCase()) return null;
19813
+ const groups = written.split(/[ -]+/);
19814
+ const printed = groups.length > 1 && groups.slice(0, -1).every((g) => g.length === 4);
19815
+ const compact = printed ? groups.join("") : groups[0];
19816
+ return ACCOUNT_SHAPE_RE.test(compact) ? compact : null;
19817
+ }
19251
19818
  var RECIPIENT_KEYS = /* @__PURE__ */ new Set([
19252
19819
  "to",
19253
19820
  "cc",
@@ -19292,11 +19859,28 @@ function hostOfUrl(value) {
19292
19859
  return null;
19293
19860
  }
19294
19861
  }
19862
+ function ibanOf(written) {
19863
+ const compact = written.replace(/[ -]/g, "").toUpperCase();
19864
+ if (!validateIban(compact)) return null;
19865
+ const length = IBAN_LENGTH[compact.slice(0, 2)];
19866
+ const iban = compact.slice(0, length);
19867
+ if (written === written.toUpperCase()) return iban;
19868
+ let at = 0;
19869
+ for (const group of written.split(/[ -]+/)) {
19870
+ at += group.length;
19871
+ if (at === length) return iban;
19872
+ if (at > length) break;
19873
+ }
19874
+ return null;
19875
+ }
19295
19876
  function addIbans(text, out) {
19296
- for (const m of text.toUpperCase().matchAll(IBAN_RE)) {
19297
- const compact = m[0].replace(/[ -]/g, "");
19298
- if (validateIban(compact)) out.add(`iban:${compact}`);
19299
- else if (/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(compact)) out.add(`account:${compact}`);
19877
+ for (const m of text.matchAll(IBAN_RE)) {
19878
+ const iban = ibanOf(m[0]);
19879
+ if (iban) out.add(`iban:${iban}`);
19880
+ else {
19881
+ const account = accountOf(m[0]);
19882
+ if (account) out.add(`account:${account}`);
19883
+ }
19300
19884
  if (out.size >= MAX_DESTINATIONS) return;
19301
19885
  }
19302
19886
  }
@@ -19344,8 +19928,8 @@ function walk2(value, key, out, depth) {
19344
19928
  s.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").replace(/^\/\//, "").split(/[/?#]/)[0].replace(/:\d+$/, "")
19345
19929
  );
19346
19930
  if (h && (h.includes(":") || /\.\p{L}{2,}$/u.test(h))) out.add(`host:${h}`);
19347
- const acct = s.replace(/[ .-]/g, "").toUpperCase();
19348
- if (/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(acct) && !validateIban(acct))
19931
+ const acct = s.replace(/[ .-]/g, "");
19932
+ if (acct === acct.toUpperCase() && ACCOUNT_SHAPE_RE.test(acct) && !validateIban(acct))
19349
19933
  out.add(`account:${acct}`);
19350
19934
  }
19351
19935
  return;
@@ -19548,8 +20132,8 @@ function hasRoutingNumber(text) {
19548
20132
  return false;
19549
20133
  }
19550
20134
  var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
19551
- function* validCardRuns(text, base3, exemptFractions = true) {
19552
- const re = new RegExp(base3.source, "g");
20135
+ function* validCardRuns(text, base4, exemptFractions = true) {
20136
+ const re = new RegExp(base4.source, "g");
19553
20137
  let m;
19554
20138
  while ((m = re.exec(text)) !== null) {
19555
20139
  const digits = m[0].replace(/\D/g, "");
@@ -19562,17 +20146,17 @@ function* validCardRuns(text, base3, exemptFractions = true) {
19562
20146
  }
19563
20147
  }
19564
20148
  function hasValidCard(text) {
19565
- for (const base3 of CARD_PATTERNS) {
19566
- if (!validCardRuns(text, base3).next().done) return true;
20149
+ for (const base4 of CARD_PATTERNS) {
20150
+ if (!validCardRuns(text, base4).next().done) return true;
19567
20151
  }
19568
20152
  return false;
19569
20153
  }
19570
20154
  function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
19571
20155
  let out = text;
19572
- for (const base3 of CARD_PATTERNS) {
20156
+ for (const base4 of CARD_PATTERNS) {
19573
20157
  let res = "";
19574
20158
  let last = 0;
19575
- for (const run of validCardRuns(out, base3, exemptFractions)) {
20159
+ for (const run of validCardRuns(out, base4, exemptFractions)) {
19576
20160
  res += out.slice(last, run.index) + replace(run.digits);
19577
20161
  last = run.index + run.length;
19578
20162
  }
@@ -19861,9 +20445,9 @@ function maskLeaf(value, key, depth) {
19861
20445
  const used = /* @__PURE__ */ new Set();
19862
20446
  return Object.fromEntries(
19863
20447
  Object.entries(value).map(([k, v]) => {
19864
- const base3 = maskPersonalData(k);
19865
- let name = base3;
19866
- for (let n = 2; used.has(name); n++) name = `${base3}#${n}`;
20448
+ const base4 = maskPersonalData(k);
20449
+ let name = base4;
20450
+ for (let n = 2; used.has(name); n++) name = `${base4}#${n}`;
19867
20451
  used.add(name);
19868
20452
  return [name, maskLeaf(v, k, depth + 1)];
19869
20453
  })
@@ -20105,7 +20689,7 @@ function classifyCall(head, args, prefixes, env, state, out) {
20105
20689
  }
20106
20690
  case "scp":
20107
20691
  case "rsync": {
20108
- const pos = positionals(args, VALUE_FLAGS[head] ?? /* @__PURE__ */ new Set()).filter(
20692
+ const pos = positionals(args, VALUE_FLAGS2[head] ?? /* @__PURE__ */ new Set()).filter(
20109
20693
  (p) => p !== null
20110
20694
  );
20111
20695
  if (pos.length < 2) return;
@@ -20727,7 +21311,7 @@ function summarizeBlast(result, opts = {}) {
20727
21311
  // src/scan/destructive-regex.ts
20728
21312
  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;
20729
21313
  var PRIVILEGE_ESCALATION_RE = /\bchmod\s+(0?777|\+x)\b|\bchown\s+root\b/i;
20730
- 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;
21314
+ 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;
20731
21315
  var FILE_TOOLS = /* @__PURE__ */ new Set([
20732
21316
  "read",
20733
21317
  "read_file",
@@ -20930,8 +21514,8 @@ function matchCanaryArgs(args, values) {
20930
21514
 
20931
21515
  // src/scan/canonical.ts
20932
21516
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
20933
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
20934
- var CANONICAL_EXTRACTOR_HASH = "1c4a57ad24e7c8c3";
21517
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v41";
21518
+ var CANONICAL_EXTRACTOR_HASH = "dbde5e7f06f3738a";
20935
21519
  var DEDUPE_PREVIEW_LEN = 120;
20936
21520
  function extractCanonicalFindings(call, ctx) {
20937
21521
  const out = [];
@@ -21433,12 +22017,14 @@ export {
21433
22017
  PATTERN_VERB_NAMES,
21434
22018
  POSTURE_CATEGORY_OWASP,
21435
22019
  PRIVILEGE_ESCALATION_RE,
22020
+ PUBLIC_SSH_NAME_SOURCE,
21436
22021
  REALTIME_PII_PATTERNS,
21437
22022
  REPLACED_SHIELDS,
21438
22023
  SCAN_REPO_RULES_WITHOUT_RISK,
21439
22024
  SCAN_SIGNAL_WEIGHTS,
21440
22025
  SENSITIVE_PATH_RE,
21441
22026
  SENSITIVE_PATH_REGEXES,
22027
+ SHELL_INTERPRETERS,
21442
22028
  SSRF_MAX_HOST,
21443
22029
  STARTUP_NAMES,
21444
22030
  SYSTEM_AUTH_DIRS,
@@ -21539,6 +22125,7 @@ export {
21539
22125
  isPrivateHost,
21540
22126
  isProtectedHomePath,
21541
22127
  isPublicRegistryHost,
22128
+ isPublicSshMaterial,
21542
22129
  isRecordOnly,
21543
22130
  isShellShapedTool,
21544
22131
  isShieldVerdict,