@node9/policy-engine 2.33.2 → 2.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1083,6 +1083,11 @@ var CHECK_TEXT = {
1083
1083
  example: "cat /etc/shadow",
1084
1084
  advice: "Keep Review, or choose Block when agents must never read system password hashes."
1085
1085
  },
1086
+ "files.system-dirs": {
1087
+ plain: "The agent writes, creates or deletes a file in a system directory, or sends a system file in a request. /usr/local and a container working directory under /usr/src are ordinary project space and are not included.",
1088
+ example: "wget -O /usr/bin/tool https://example.com/tool",
1089
+ advice: "Keep Review on a workstation. A container image build that installs into /usr can set it to Log."
1090
+ },
1086
1091
  // ── Commands ──────────────────────────────────────────────────────────────
1087
1092
  "commands.inline-exec": {
1088
1093
  plain: "The agent runs a small program written inside the command itself.",
@@ -1279,7 +1284,7 @@ var CHECK_TEXT = {
1279
1284
  advice: "Fixed at Block. A person accepts the change on the machine (node9 mcp pin update)."
1280
1285
  },
1281
1286
  "loading.malicious-package": {
1282
- plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago.",
1287
+ plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago. Covers npm, PyPI, RubyGems, crates.io, Go, NuGet, Maven, Packagist and VS Code extensions; the publish-age and install-script signals are npm and PyPI only.",
1283
1288
  example: "npm install of a package flagged as malware",
1284
1289
  advice: "Keep Block for known-malicious packages; brand-new packages already stop for Review."
1285
1290
  }
@@ -1330,6 +1335,15 @@ var PRODUCT_CHECKS = [
1330
1335
  defaultValue: "review",
1331
1336
  legacy: ["review-password-hash-read"]
1332
1337
  },
1338
+ {
1339
+ id: "files.system-dirs",
1340
+ group: "files",
1341
+ title: "System directories",
1342
+ catches: "Writes, new files and removals under /usr, /etc, /boot, /bin, /sbin, /lib and /var/log, and uploads of system files",
1343
+ values: ALL,
1344
+ defaultValue: "review",
1345
+ legacy: ["review-system-dir-mutation", "review-system-file-upload"]
1346
+ },
1333
1347
  // ── Commands ────────────────────────────────────────────────────────────
1334
1348
  {
1335
1349
  id: "commands.inline-exec",
@@ -3491,6 +3505,124 @@ function expandPlainParam(p) {
3491
3505
  if (recorded !== void 0) return recorded;
3492
3506
  return HOME_VARIABLES.has(p.Param?.Value) ? "~" : void 0;
3493
3507
  }
3508
+ var MAX_CALL_DEPTH = 4;
3509
+ var MAX_CALL_WALKS = 256;
3510
+ var callDepth = 0;
3511
+ var callWalks = 0;
3512
+ function functionBodies(f) {
3513
+ const out = /* @__PURE__ */ new Map();
3514
+ syntax.Walk(f, (node) => {
3515
+ const n = node;
3516
+ if (n && syntax.NodeType(n) === "FuncDecl" && n.Name?.Value && n.Body) {
3517
+ const list = out.get(n.Name.Value) ?? [];
3518
+ list.push(n.Body);
3519
+ out.set(n.Name.Value, list);
3520
+ }
3521
+ return true;
3522
+ });
3523
+ return out;
3524
+ }
3525
+ function rebindsPositionals(body) {
3526
+ let found = false;
3527
+ syntax.Walk(body, (node) => {
3528
+ const n = node;
3529
+ if (found || !n) return false;
3530
+ if (syntax.NodeType(n) === "CallExpr") {
3531
+ const words = (n.Args || []).map((a) => resolveWordLiteral(a));
3532
+ if (words[0] === "shift") found = true;
3533
+ else if (words[0] === "set" && words.slice(1).some((w) => w === null || w === "--" || !/^[-+]/.test(w)))
3534
+ found = true;
3535
+ }
3536
+ return !found;
3537
+ });
3538
+ return found;
3539
+ }
3540
+ function tableBindings() {
3541
+ if (!assignmentTable) return "";
3542
+ const out = [];
3543
+ for (const [name, rec] of assignmentTable)
3544
+ if (rec.at < currentStmtOffset) out.push(`${name}=${rec.value ?? "\0"}`);
3545
+ return out.sort().join("");
3546
+ }
3547
+ function walkWithCalls(f, visit) {
3548
+ const bodies = functionBodies(f);
3549
+ if (bodies.size === 0) {
3550
+ syntax.Walk(f, visit);
3551
+ return;
3552
+ }
3553
+ const seenCalls = /* @__PURE__ */ new Set();
3554
+ const inline = (call) => {
3555
+ const words = (call.Args || []).map((a) => resolveWordLiteral(a));
3556
+ const list = words[0] ? bodies.get(words[0]) : void 0;
3557
+ if (!list || callDepth >= MAX_CALL_DEPTH) return;
3558
+ const args = words.slice(1);
3559
+ const key = `${words[0]}\0${JSON.stringify(args)}\0${tableBindings()}`;
3560
+ if (seenCalls.has(key)) return;
3561
+ seenCalls.add(key);
3562
+ const outerTable = assignmentTable;
3563
+ const outerOffset = currentStmtOffset;
3564
+ for (const body of list) {
3565
+ if (callWalks >= MAX_CALL_WALKS) return;
3566
+ callWalks++;
3567
+ const table = /* @__PURE__ */ new Map();
3568
+ for (const [name, rec] of outerTable ?? [])
3569
+ if (rec.at < outerOffset) table.set(name, { value: rec.value, at: -1 });
3570
+ for (const name of ["1", "2", "3", "4", "5", "6", "7", "8", "9", "@", "*", "#"])
3571
+ table.delete(name);
3572
+ if (!rebindsPositionals(body)) {
3573
+ args.slice(0, 9).forEach((value, i) => table.set(String(i + 1), { value, at: -1 }));
3574
+ if (args.length === 1) {
3575
+ table.set("@", { value: args[0], at: -1 });
3576
+ table.set("*", { value: args[0], at: -1 });
3577
+ }
3578
+ table.set("#", { value: String(args.length), at: -1 });
3579
+ }
3580
+ assignmentTable = table;
3581
+ currentStmtOffset = Number.MAX_SAFE_INTEGER;
3582
+ callDepth++;
3583
+ try {
3584
+ if (body.Cmd && syntax.NodeType(body.Cmd) === "Block") recordTopLevelAssignments(body.Cmd);
3585
+ syntax.Walk(body, step);
3586
+ } finally {
3587
+ callDepth--;
3588
+ assignmentTable = outerTable;
3589
+ currentStmtOffset = outerOffset;
3590
+ }
3591
+ }
3592
+ };
3593
+ const step = (node) => {
3594
+ if (!node) return false;
3595
+ const go = visit(node);
3596
+ if (go !== false && syntax.NodeType(node) === "CallExpr") inline(node);
3597
+ return go;
3598
+ };
3599
+ syntax.Walk(f, step);
3600
+ }
3601
+ function withAssignments(f, body) {
3602
+ const outerTable = assignmentTable;
3603
+ const outerOffset = currentStmtOffset;
3604
+ const outerWalks = callWalks;
3605
+ callWalks = 0;
3606
+ assignmentTable = new Map(
3607
+ [...outerTable ?? []].map(([k, r]) => [k, { value: r.value, at: -1 }])
3608
+ );
3609
+ currentStmtOffset = Number.MAX_SAFE_INTEGER;
3610
+ try {
3611
+ recordTopLevelAssignments(f);
3612
+ return body();
3613
+ } finally {
3614
+ assignmentTable = outerTable;
3615
+ currentStmtOffset = outerOffset;
3616
+ callWalks = outerWalks;
3617
+ }
3618
+ }
3619
+ function trackStatement(n) {
3620
+ try {
3621
+ currentStmtOffset = n.Pos().Offset();
3622
+ } catch {
3623
+ currentStmtOffset = Number.MAX_SAFE_INTEGER;
3624
+ }
3625
+ }
3494
3626
  function resolveWordLiteral(w) {
3495
3627
  const parts = w?.Parts || [];
3496
3628
  let s = "";
@@ -3611,27 +3743,31 @@ function extractShellDestinations(command) {
3611
3743
  const out = [];
3612
3744
  const seen = /* @__PURE__ */ new Set();
3613
3745
  try {
3614
- syntax.Walk(f, (node) => {
3615
- if (!node) return false;
3616
- const n = node;
3617
- if (syntax.NodeType(n) !== "CallExpr") return true;
3618
- const callArgs = n.Args || [];
3619
- if (callArgs.length === 0) return true;
3620
- const words = callArgs.map((a) => resolveWordLiteral(a));
3621
- const at = unwrapCommandHead(words);
3622
- const name = (words[at] || "").toLowerCase().split("/").pop() ?? "";
3623
- if (!NET_BINARIES.has(name)) return true;
3624
- const rest = words.slice(at + 1);
3625
- for (const raw of destTokensForBinary(name, rest)) {
3626
- const host2 = parseDestHost(raw);
3627
- if (!host2) continue;
3628
- const key = `${name}:${host2}`;
3629
- if (seen.has(key)) continue;
3630
- seen.add(key);
3631
- out.push({ host: host2, binary: name, raw });
3632
- }
3633
- return true;
3634
- });
3746
+ withAssignments(
3747
+ f,
3748
+ () => walkWithCalls(f, (node) => {
3749
+ if (!node) return false;
3750
+ const n = node;
3751
+ if (syntax.NodeType(n) === "Stmt") trackStatement(n);
3752
+ if (syntax.NodeType(n) !== "CallExpr") return true;
3753
+ const callArgs = n.Args || [];
3754
+ if (callArgs.length === 0) return true;
3755
+ const words = callArgs.map((a) => resolveWordLiteral(a));
3756
+ const at = unwrapCommandHead(words);
3757
+ const name = (words[at] || "").toLowerCase().split("/").pop() ?? "";
3758
+ if (!NET_BINARIES.has(name)) return true;
3759
+ const rest = words.slice(at + 1);
3760
+ for (const raw of destTokensForBinary(name, rest)) {
3761
+ const host2 = parseDestHost(raw);
3762
+ if (!host2) continue;
3763
+ const key = `${name}:${host2}`;
3764
+ if (seen.has(key)) continue;
3765
+ seen.add(key);
3766
+ out.push({ host: host2, binary: name, raw });
3767
+ }
3768
+ return true;
3769
+ })
3770
+ );
3635
3771
  } catch {
3636
3772
  return out;
3637
3773
  }
@@ -3643,39 +3779,45 @@ function extractShellDestTokens(command) {
3643
3779
  const out = [];
3644
3780
  const seen = /* @__PURE__ */ new Set();
3645
3781
  try {
3646
- syntax.Walk(f, (node) => {
3647
- if (!node) return false;
3648
- const n = node;
3649
- if (syntax.NodeType(n) !== "CallExpr") return true;
3650
- const callArgs = n.Args || [];
3651
- if (callArgs.length === 0) return true;
3652
- const name = (resolveWordLiteral(callArgs[0]) || "").toLowerCase();
3653
- if (!NET_BINARIES.has(name)) return true;
3654
- const rest = callArgs.slice(1).map((a) => resolveWordLiteral(a));
3655
- for (const raw of destTokensForBinary(name, rest)) {
3656
- if (!raw) continue;
3657
- let tok = raw.trim();
3658
- const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(tok);
3659
- const hasScheme = scheme !== null;
3660
- if (hasScheme) tok = tok.slice(scheme[0].length);
3661
- tok = tok.split(/[/?#]/)[0];
3662
- const at = tok.lastIndexOf("@");
3663
- if (at >= 0) tok = tok.slice(at + 1);
3664
- if (tok.startsWith("[")) {
3665
- const close = tok.indexOf("]");
3666
- if (close > 0) tok = tok.slice(0, close + 1);
3667
- } else {
3668
- tok = tok.split(":")[0];
3782
+ withAssignments(
3783
+ f,
3784
+ () => walkWithCalls(f, (node) => {
3785
+ if (!node) return false;
3786
+ const n = node;
3787
+ if (syntax.NodeType(n) === "Stmt") trackStatement(n);
3788
+ if (syntax.NodeType(n) !== "CallExpr") return true;
3789
+ const callArgs = n.Args || [];
3790
+ if (callArgs.length === 0) return true;
3791
+ const words = callArgs.map((a) => resolveWordLiteral(a));
3792
+ const head = unwrapCommandHead(words);
3793
+ const name = (words[head] || "").toLowerCase().split("/").pop() ?? "";
3794
+ if (!NET_BINARIES.has(name)) return true;
3795
+ const rest = words.slice(head + 1);
3796
+ for (const raw of destTokensForBinary(name, rest)) {
3797
+ if (!raw) continue;
3798
+ let tok = raw.trim();
3799
+ const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(tok);
3800
+ const hasScheme = scheme !== null;
3801
+ if (hasScheme) tok = tok.slice(scheme[0].length);
3802
+ tok = tok.split(/[/?#]/)[0];
3803
+ const at = tok.lastIndexOf("@");
3804
+ if (at >= 0) tok = tok.slice(at + 1);
3805
+ if (tok.startsWith("[")) {
3806
+ const close = tok.indexOf("]");
3807
+ if (close > 0) tok = tok.slice(0, close + 1);
3808
+ } else {
3809
+ tok = tok.split(":")[0];
3810
+ }
3811
+ if (!tok) continue;
3812
+ if (!hasScheme && /^\d+$/.test(tok) && Number(tok) < 16777216) continue;
3813
+ const key = `${name}:${tok}`;
3814
+ if (seen.has(key)) continue;
3815
+ seen.add(key);
3816
+ out.push({ token: tok, binary: name });
3669
3817
  }
3670
- if (!tok) continue;
3671
- if (!hasScheme && /^\d+$/.test(tok) && Number(tok) < 16777216) continue;
3672
- const key = `${name}:${tok}`;
3673
- if (seen.has(key)) continue;
3674
- seen.add(key);
3675
- out.push({ token: tok, binary: name });
3676
- }
3677
- return true;
3678
- });
3818
+ return true;
3819
+ })
3820
+ );
3679
3821
  } catch {
3680
3822
  return out;
3681
3823
  }
@@ -3805,6 +3947,7 @@ function analyzeFsOperationImpl(command, depth = 0) {
3805
3947
  if (depth === 0) {
3806
3948
  seenPayloads = /* @__PURE__ */ new Set();
3807
3949
  payloadBudget = PAYLOAD_BUDGET;
3950
+ if (callDepth === 0) callWalks = 0;
3808
3951
  }
3809
3952
  assignmentTable = new Map(
3810
3953
  [...outerTable ?? []].map(([k, r]) => [k, { value: r.value, at: -1 }])
@@ -3812,7 +3955,7 @@ function analyzeFsOperationImpl(command, depth = 0) {
3812
3955
  currentStmtOffset = Number.MAX_SAFE_INTEGER;
3813
3956
  try {
3814
3957
  recordTopLevelAssignments(f);
3815
- syntax.Walk(f, (node) => {
3958
+ walkWithCalls(f, (node) => {
3816
3959
  if (!node || result?.verdict === "block") return false;
3817
3960
  const n = node;
3818
3961
  const nodeType = syntax.NodeType(n);
@@ -4654,10 +4797,17 @@ function shellRuleArgs(tool, args, ruleTool, inspection = {}) {
4654
4797
  import mvdanSh2 from "mvdan-sh";
4655
4798
  var { syntax: syntax2 } = mvdanSh2;
4656
4799
  var MAX_ALTERNATIVES = 64;
4800
+ var MAX_CALL_DEPTH2 = 4;
4801
+ var MAX_CALL_WALKS2 = 256;
4802
+ var POSITIONAL = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "@", "*", "#"];
4657
4803
  var MAX_DEPTH = 64;
4658
4804
  var MAX_PAYLOAD_DEPTH = 24;
4659
4805
  var unique = (a) => [...new Set(a)].slice(0, MAX_ALTERNATIVES);
4660
- var clone = (s) => ({ cwd: [...s.cwd], vars: new Map(s.vars) });
4806
+ var clone = (s) => ({
4807
+ cwd: [...s.cwd],
4808
+ vars: new Map(s.vars),
4809
+ ...s.callDepth ? { callDepth: s.callDepth } : {}
4810
+ });
4661
4811
  function runnablePrefix(command) {
4662
4812
  let text = command;
4663
4813
  for (let attempt = 0; attempt < 32; attempt++) {
@@ -4673,6 +4823,81 @@ function runnablePrefix(command) {
4673
4823
  }
4674
4824
  return null;
4675
4825
  }
4826
+ var SENDING_STDIN = /* @__PURE__ */ new Set(["nc", "ncat", "netcat", "socat", "telnet", "curl", "wget"]);
4827
+ var DOWNLOAD_SHORT_VALUE = {
4828
+ curl: "odDeEFHKmPrtTuUwxXyYzAbcCQ",
4829
+ wget: "OoaPiBetTwQlARDXIUY",
4830
+ aria2c: "odisx"
4831
+ };
4832
+ var DOWNLOAD_LONG_VALUE = {
4833
+ curl: [
4834
+ "--output",
4835
+ "--output-dir",
4836
+ "--dump-header",
4837
+ "--cookie-jar",
4838
+ "--data",
4839
+ "--data-binary",
4840
+ "--data-raw",
4841
+ "--data-ascii",
4842
+ "--data-urlencode",
4843
+ "--form",
4844
+ "--header",
4845
+ "--request",
4846
+ "--user",
4847
+ "--user-agent",
4848
+ "--referer",
4849
+ "--cookie",
4850
+ "--config",
4851
+ "--json",
4852
+ "--upload-file",
4853
+ "--max-time",
4854
+ "--proxy",
4855
+ "--write-out",
4856
+ "--url"
4857
+ ],
4858
+ wget: [
4859
+ "--output-document",
4860
+ "--output-file",
4861
+ "--append-output",
4862
+ "--directory-prefix",
4863
+ "--input-file",
4864
+ "--post-data",
4865
+ "--post-file",
4866
+ "--body-data",
4867
+ "--body-file",
4868
+ "--method",
4869
+ "--header",
4870
+ "--user-agent",
4871
+ "--user",
4872
+ "--password",
4873
+ "--tries",
4874
+ "--timeout"
4875
+ ],
4876
+ aria2c: ["--out", "--dir", "--input-file"]
4877
+ };
4878
+ var DOWNLOAD_OUTPUT_FLAGS = {
4879
+ curl: ["-o", "--output", "-D", "--dump-header", "-c", "--cookie-jar"],
4880
+ wget: ["-O", "--output-document", "-o", "--output-file", "-a", "--append-output"],
4881
+ aria2c: ["-o", "--out"]
4882
+ };
4883
+ var DOWNLOAD_DIR_FLAGS = {
4884
+ curl: ["--output-dir"],
4885
+ wget: ["-P", "--directory-prefix"],
4886
+ aria2c: ["-d", "--dir"]
4887
+ };
4888
+ function uploadedFile(tool, flag, value) {
4889
+ const v = value.value;
4890
+ const file = (f) => f && f !== "-" && f !== "." ? { value: f } : null;
4891
+ if (tool === "curl") {
4892
+ if (["-d", "--data", "--data-ascii", "--data-binary", "--json"].includes(flag))
4893
+ return v.startsWith("@") ? file(v.slice(1)) : null;
4894
+ if (flag === "--data-urlencode") return file(/^[^=@]*@(.+)$/.exec(v)?.[1]);
4895
+ if (flag === "-F" || flag === "--form") return file(/^[^=]*=[@<]([^;]+)/.exec(v)?.[1]);
4896
+ if (flag === "-T" || flag === "--upload-file") return file(v);
4897
+ }
4898
+ if (tool === "wget" && ["--post-file", "--body-file"].includes(flag)) return file(v);
4899
+ return null;
4900
+ }
4676
4901
  var base = (s) => (s ?? "").replace(/\/+$/, "").split("/").pop() ?? "";
4677
4902
  var quoteGlob = (s) => s.replace(/[\\*?\[\]{}()!+@]/g, "\\$&");
4678
4903
  var asWord = (p) => ({ value: p.value, ...p.glob ? { pattern: p.pattern } : {} });
@@ -4760,6 +4985,9 @@ function wordValues(word, state) {
4760
4985
  function collectShellFileAccesses(command, context = {}) {
4761
4986
  const out = [];
4762
4987
  let payloads = 256;
4988
+ const functions = /* @__PURE__ */ new Map();
4989
+ const seenCalls = /* @__PURE__ */ new Set();
4990
+ let callWalks2 = MAX_CALL_WALKS2;
4763
4991
  const initial = {
4764
4992
  cwd: [context.cwd ?? ""],
4765
4993
  vars: /* @__PURE__ */ new Map([["HOME", [context.homeDirs?.[0] ?? "~"]]])
@@ -5017,8 +5245,98 @@ function collectShellFileAccesses(command, context = {}) {
5017
5245
  }
5018
5246
  return;
5019
5247
  }
5248
+ if (name === "wget" || name === "curl" || name === "aria2c") {
5249
+ downloadOutputs(name, args, state);
5250
+ return;
5251
+ }
5252
+ if (["http", "https", "xh", "xhs"].includes(name)) {
5253
+ for (const token of args) {
5254
+ if (!token || token.dynamic || /^[a-z][a-z0-9+.-]*:\/\//i.test(token.value)) continue;
5255
+ const m = /^(?:@|[^=:@\s]+@|[^=:@\s]*=@)(.+)$/.exec(token.value);
5256
+ if (m && m[1] !== "-") add("read", { value: m[1] }, state, { upload: true });
5257
+ }
5258
+ return;
5259
+ }
5260
+ if (name === "scp" || name === "rsync") {
5261
+ const operands2 = strings.filter((s) => s && !s.startsWith("-"));
5262
+ const remote = operands2.slice(1).some((o) => /^[^/\s]+:/.test(o));
5263
+ for (const p of copySourcePaths(words))
5264
+ add("read", locate(p), state, remote ? { upload: true } : {});
5265
+ return;
5266
+ }
5020
5267
  for (const p of copySourcePaths(words)) add("read", locate(p), state);
5021
5268
  }
5269
+ function downloadOutputs(name, args, state) {
5270
+ const valueShort = DOWNLOAD_SHORT_VALUE[name];
5271
+ const outputs = [];
5272
+ const urls = [];
5273
+ let dir = null;
5274
+ let remoteName = false;
5275
+ let document = false;
5276
+ let serverNamed = false;
5277
+ const take = (flag, value) => {
5278
+ if (!value) return;
5279
+ const sent = uploadedFile(name, flag, value);
5280
+ if (sent) add("read", sent, state, { upload: true });
5281
+ if (DOWNLOAD_OUTPUT_FLAGS[name].includes(flag)) {
5282
+ if (["-O", "--output-document", "--out"].includes(flag) || name === "aria2c" && flag === "-o")
5283
+ document = true;
5284
+ if (value.value !== "-" || value.pattern || value.dynamic) outputs.push(value);
5285
+ } else if (DOWNLOAD_DIR_FLAGS[name].includes(flag)) dir = value;
5286
+ else if (name === "wget" && (flag === "-i" || flag === "--input-file")) serverNamed = true;
5287
+ };
5288
+ for (let i = 0; i < args.length; i++) {
5289
+ const token = args[i];
5290
+ if (!token) continue;
5291
+ const v = token.value;
5292
+ if (v.startsWith("--")) {
5293
+ const eq = v.indexOf("=");
5294
+ const flag = eq < 0 ? v : v.slice(0, eq);
5295
+ if (["--remote-name", "--remote-name-all"].includes(flag)) remoteName = true;
5296
+ if (["--remote-header-name", "--recursive", "--mirror", "--page-requisites"].includes(flag))
5297
+ serverNamed = true;
5298
+ if (DOWNLOAD_LONG_VALUE[name].includes(flag))
5299
+ take(flag, eq < 0 ? args[++i] ?? null : { ...token, value: v.slice(eq + 1) });
5300
+ continue;
5301
+ }
5302
+ if (v.startsWith("-") && v.length > 1 && !token.dynamic) {
5303
+ for (let j = 1; j < v.length; j++) {
5304
+ const c = v[j];
5305
+ if (name === "wget" && c === "n") {
5306
+ j++;
5307
+ continue;
5308
+ }
5309
+ if (name === "curl" && c === "O") remoteName = true;
5310
+ if (name === "curl" && c === "J") serverNamed = true;
5311
+ if (name === "wget" && (c === "r" || c === "m" || c === "p")) serverNamed = true;
5312
+ if (valueShort.includes(c)) {
5313
+ const rest = v.slice(j + 1);
5314
+ take(`-${c}`, rest ? { value: rest } : args[++i] ?? null);
5315
+ break;
5316
+ }
5317
+ }
5318
+ continue;
5319
+ }
5320
+ if (/^(?:https?|ftps?):\/\//i.test(v)) urls.push(v);
5321
+ }
5322
+ for (const out2 of outputs) {
5323
+ const spelled = name === "aria2c" && dir?.value && !out2.value.startsWith("/") ? { ...out2, value: `${dir.value.replace(/\/+$/, "")}/${out2.value}` } : out2;
5324
+ if (name === "curl" && /#\d/.test(spelled.value))
5325
+ add("write", { value: "", pattern: spelled.value.replace(/#\d+/g, "*"), dot: true }, state);
5326
+ else add("write", spelled, state);
5327
+ }
5328
+ const remote = name === "curl" ? remoteName || serverNamed : !document || serverNamed;
5329
+ if (!remote) return;
5330
+ const into = dir?.value ? dir.value.replace(/\/+$/, "") : ".";
5331
+ if (serverNamed || urls.length === 0) {
5332
+ add("write", { value: "", pattern: `${quoteGlob(into)}/*`, dot: true }, state);
5333
+ return;
5334
+ }
5335
+ for (const url of urls) {
5336
+ const file = url.replace(/[?#].*$/, "").replace(/^[a-z]+:\/\/[^/]*/i, "").split("/").pop();
5337
+ add("write", { value: `${into}/${file || "index.html"}` }, state);
5338
+ }
5339
+ }
5022
5340
  function findActions2(tokens, words, head, state, nested, depth) {
5023
5341
  const starts = findStartPoints(words, head).starts;
5024
5342
  const roots = (starts.length ? starts : ["."]).slice(0, MAX_ALTERNATIVES);
@@ -5090,7 +5408,35 @@ function collectShellFileAccesses(command, context = {}) {
5090
5408
  const words = wordValues(node, state);
5091
5409
  alternatives = alternatives.flatMap((prefix) => (words.length ? words : [null]).map((w) => [...prefix, w])).slice(0, MAX_ALTERNATIVES);
5092
5410
  }
5093
- for (const tokens of alternatives) fromWords(tokens, state, nested, depth);
5411
+ for (const tokens of alternatives) {
5412
+ fromWords(tokens, state, nested, depth);
5413
+ inlineCall(tokens, state, depth);
5414
+ }
5415
+ }
5416
+ function inlineCall(tokens, state, depth) {
5417
+ const head = tokens[0];
5418
+ if (!head || head.dynamic || head.pattern) return;
5419
+ const bodies = functions.get(head.value);
5420
+ if (!bodies || (state.callDepth ?? 0) >= MAX_CALL_DEPTH2) return;
5421
+ const args = tokens.slice(1).map((a) => a && !a.dynamic ? a.value : null);
5422
+ const vars = JSON.stringify([...state.vars].sort(([a], [b]) => a < b ? -1 : 1));
5423
+ const key = `${head.value}\0${JSON.stringify(args)}\0${state.cwd.join("")}\0${vars}`;
5424
+ if (seenCalls.has(key)) return;
5425
+ seenCalls.add(key);
5426
+ for (const body of bodies) {
5427
+ if (callWalks2-- <= 0) return;
5428
+ const local = clone(state);
5429
+ local.callDepth = (state.callDepth ?? 0) + 1;
5430
+ for (const name of POSITIONAL) local.vars.delete(name);
5431
+ if (!rebindsPositionals(body)) {
5432
+ args.slice(0, 9).forEach((v, i) => local.vars.set(String(i + 1), v === null ? null : [v]));
5433
+ const all = args.every((v) => v !== null) && args.length ? unique(args) : null;
5434
+ local.vars.set("@", all);
5435
+ local.vars.set("*", all);
5436
+ local.vars.set("#", [String(args.length)]);
5437
+ }
5438
+ statement(body, local, depth + 1);
5439
+ }
5094
5440
  }
5095
5441
  function readsScriptFromStdin(stmt) {
5096
5442
  const cmd = stmt?.Cmd;
@@ -5127,11 +5473,13 @@ function collectShellFileAccesses(command, context = {}) {
5127
5473
  if (!stmt || depth > MAX_DEPTH) return;
5128
5474
  state.onSuccess = void 0;
5129
5475
  if (stmt.Background) state = clone(state);
5476
+ const headWord = stmt.Cmd && syntax2.NodeType(stmt.Cmd) === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
5477
+ const sends = SENDING_STDIN.has(headWord);
5130
5478
  for (const redir of stmt.Redirs ?? []) {
5131
5479
  substitutions(redir.Word, state, depth);
5132
5480
  for (const word of wordValues(redir.Word, state)) {
5133
5481
  if (WRITES.has(redir.Op)) add("write", word, state);
5134
- if (READS.has(redir.Op)) add("read", word, state);
5482
+ if (READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
5135
5483
  if (redir.Op === DUP_OUT && word.value && !/^\d+$/.test(word.value))
5136
5484
  add("write", word, state);
5137
5485
  }
@@ -5240,7 +5588,10 @@ function collectShellFileAccesses(command, context = {}) {
5240
5588
  }
5241
5589
  const parsed = parseShared(command);
5242
5590
  const program = typeof parsed !== "symbol" ? parsed : runnablePrefix(command);
5243
- if (program) statements(program.Stmts ?? [], initial, 0);
5591
+ if (program) {
5592
+ for (const [name, bodies] of functionBodies(program)) functions.set(name, bodies);
5593
+ statements(program.Stmts ?? [], initial, 0);
5594
+ }
5244
5595
  return out;
5245
5596
  }
5246
5597
 
@@ -5255,6 +5606,18 @@ var SYSTEM_AUTH_FILES = [
5255
5606
  var SYSTEM_AUTH_DIRS = ["/etc/security", "/etc/pam.d", "/etc/sudoers.d"];
5256
5607
  var PASSWORD_HASH_FILES = ["/etc/shadow", "/etc/gshadow"];
5257
5608
  var STARTUP_NAMES = [".bashrc", ".zshrc", ".profile", ".bash_profile"];
5609
+ var SYSTEM_DIRS = [
5610
+ "/usr",
5611
+ "/etc",
5612
+ "/boot",
5613
+ "/bin",
5614
+ "/sbin",
5615
+ "/lib",
5616
+ "/lib64",
5617
+ "/var/log"
5618
+ ];
5619
+ var SYSTEM_DIRS_EXEMPT = ["/usr/local", "/usr/src"];
5620
+ var UPLOAD_SYSTEM_DIRS = [...SYSTEM_DIRS, "/proc", "/sys", "/root"];
5258
5621
  var AGENT_INSTRUCTION_FILES = [
5259
5622
  ".gitlab-ci.yml",
5260
5623
  "CLAUDE.md",
@@ -5387,6 +5750,34 @@ function hits(access, paths, directories, context) {
5387
5750
  }
5388
5751
  return false;
5389
5752
  }
5753
+ var exempt = (p) => SYSTEM_DIRS_EXEMPT.some((d) => within(p, d));
5754
+ function hitsSystemDir(access, context, dirs = SYSTEM_DIRS) {
5755
+ const home = context.homeDirs?.[0] ?? "~";
5756
+ const candidates = access.candidates ?? [
5757
+ normalizeFilePath(access.path, access.cwd ?? context.cwd, home)
5758
+ ];
5759
+ for (const p of candidates) {
5760
+ if (dirs.some((d) => within(p, d)) && !exempt(p)) return true;
5761
+ if (access.recursive && dirs.some((d) => within(d, p))) return true;
5762
+ }
5763
+ if (!access.glob) return false;
5764
+ const pattern = normalizeFilePath(access.glob, access.cwd ?? context.cwd, home);
5765
+ const magic = pattern.search(/[*?[{]/);
5766
+ const literal = magic < 0 ? pattern : pattern.slice(0, pattern.lastIndexOf("/", magic) + 1);
5767
+ if (literal && exempt(literal.replace(/\/$/, "") || "/")) return false;
5768
+ const options = { dot: access.dotGlob === true, nonegate: true };
5769
+ const components = pattern.split("/");
5770
+ for (const root of dirs) {
5771
+ const count = root.split("/").length;
5772
+ if (components.length > count && picomatch(components.slice(0, count).join("/"), options)(root))
5773
+ return true;
5774
+ if (access.recursive && picomatch(pattern, options)(root)) return true;
5775
+ }
5776
+ return false;
5777
+ }
5778
+ function uploadDirs(context) {
5779
+ return context.homeDirs?.[0] === "/root" ? UPLOAD_SYSTEM_DIRS.filter((d) => d !== "/root") : UPLOAD_SYSTEM_DIRS;
5780
+ }
5390
5781
  var RANK = { allow: 0, review: 1, block: 2 };
5391
5782
  function evaluateProtectedFileAccess(accesses, context, settings) {
5392
5783
  const homes = [.../* @__PURE__ */ new Set([...context.homeDirs ?? ["~"], "/root"])];
@@ -5409,6 +5800,14 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
5409
5800
  "files.shell-startup",
5410
5801
  "review-shell-startup-mutation",
5411
5802
  "Changing shell startup files requires approval"
5803
+ ] : mutation && hitsSystemDir(access, context) ? [
5804
+ "files.system-dirs",
5805
+ "review-system-dir-mutation",
5806
+ "Changing files in a system directory requires approval"
5807
+ ] : !mutation && access.upload && hitsSystemDir(access, context, uploadDirs(context)) ? [
5808
+ "files.system-dirs",
5809
+ "review-system-file-upload",
5810
+ "Uploading a system file requires approval"
5412
5811
  ] : !mutation && hits(access, PASSWORD_HASH_FILES, [], context) ? [
5413
5812
  "files.password-hashes",
5414
5813
  "review-password-hash-read",
@@ -8053,6 +8452,7 @@ var REFERENCE_VALUE_RE = /^[$@%]|^(?:process\.env|os\.environ|env|config|setting
8053
8452
  var IDENTIFIER_VALUE_RE = /^[A-Za-z_.-]+$/;
8054
8453
  var PATH_VALUE_RE = /^(?:\/|\.{1,2}\/|~\/)/;
8055
8454
  var DOTTED_REFERENCE_RE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/;
8455
+ var CONCATENATION_RE = /^\+[A-Za-z_$][\w$]*\./;
8056
8456
  var EMAIL_VALUE_RE = /^[^@\s]+@[^@\s]+\.[A-Za-z]{2,}$/;
8057
8457
  function looksLikeJoinedWords(value) {
8058
8458
  const segments2 = value.replace(/[0-9]/g, "").split(/[-_.]/);
@@ -8083,26 +8483,32 @@ function looksGenerated(value, minLength, minEntropy, lettersOnlyAllowed = false
8083
8483
  if (EMAIL_VALUE_RE.test(value)) return false;
8084
8484
  if (looksLikeJoinedWords(value) || hasSequentialRun(value)) return false;
8085
8485
  if (PATH_VALUE_RE.test(value) || DOTTED_REFERENCE_RE.test(value)) return false;
8486
+ if (CONCATENATION_RE.test(value)) return false;
8086
8487
  if (rejectedByStructuredValidator(value)) return false;
8087
8488
  return shannonEntropy(value) >= minEntropy;
8088
8489
  }
8089
8490
  var FIXTURE_NAME_RE = /(?:fake|dummy|example|sample|mock|stub|placeholder|test)/i;
8090
- var DERIVATIVE_NAME_RE = /(?:hash|digest|id|type|name|url|uri|path|file|len|length|count|size|ttl|expires?|expiry|age|date|time|format|field|header|param)$/i;
8491
+ var DERIVATIVE_NAME_RE = /(?:hash|digest|fingerprint|thumbprint|checksum|id|type|name|url|uri|path|file|len|length|count|size|ttl|expires?|expiry|age|date|time|format|field|header|param)$/i;
8091
8492
  function nameHoldsCredential(name) {
8092
8493
  return !FIXTURE_NAME_RE.test(name) && !DERIVATIVE_NAME_RE.test(name);
8093
8494
  }
8094
8495
  var QUERY_CREDENTIAL_VALUE_RE = /=([A-Za-z0-9%+/_.~-]{8,512}={0,2})$/;
8095
8496
  var OTP_SECRET_RE = /^[A-Z2-7]{16,}=*$/i;
8497
+ var OTP_DOC_SECRETS = /* @__PURE__ */ new Set(["JBSWY3DPEHPK3PXP", "GEZDGNBVGY3TQOJQ"]);
8498
+ function isOtpDocSecret(value) {
8499
+ return OTP_DOC_SECRETS.has(value.replace(/=+$/, "").toUpperCase());
8500
+ }
8096
8501
  function validateQueryCredential(raw) {
8097
8502
  const value = capturedValue(raw, QUERY_CREDENTIAL_VALUE_RE);
8098
8503
  if (value === null) return false;
8099
- if (OTP_SECRET_RE.test(value)) return looksGenerated(value, 16, 3, true);
8504
+ if (OTP_SECRET_RE.test(value))
8505
+ return !isOtpDocSecret(value) && looksGenerated(value, 16, 3, true);
8100
8506
  if (!/[0-9]/.test(value) || !/[A-Za-z]/.test(value)) return false;
8101
8507
  return looksGenerated(value, 12, 3);
8102
8508
  }
8103
- var ASSIGNED_SECRET_VALUE_RE = /(?::=|=>|[:=])[ \t]{0,8}["'`]?([A-Za-z0-9+/_.!@#$%^*~-]{12,512}={0,2})$/;
8509
+ var ASSIGNED_SECRET_VALUE_RE = /(?::=|=>|[:=])[ \t]{0,8}\\?["'`]?([A-Za-z0-9+/_.!@#$%^*~-]{12,512}={0,2})$/;
8104
8510
  var ASSIGNED_SECRET_NAME_RE = /^([A-Za-z0-9_]+)/;
8105
- var NAME_KEYWORD_RE = /^(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret)/i;
8511
+ var NAME_KEYWORD_RE = /^(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret|consumer[_-]?key|app[_-]?key|signing[_-]?key|encryption[_-]?key|master[_-]?key|jsapi[_-]?ticket|pass)/i;
8106
8512
  function keywordEndsAPart(name) {
8107
8513
  const keyword = name.match(NAME_KEYWORD_RE)?.[0];
8108
8514
  if (!keyword) return false;
@@ -8114,13 +8520,43 @@ function keywordEndsAPart(name) {
8114
8520
  var ARN_CONTEXT_RE = /\barn:[A-Za-z0-9-]*:[^\s"'`]*$/i;
8115
8521
  function validateAssignedSecret(raw, before = "") {
8116
8522
  const value = capturedValue(raw, ASSIGNED_SECRET_VALUE_RE);
8117
- const name = capturedValue(raw, ASSIGNED_SECRET_NAME_RE);
8523
+ const name = capturedValue(raw, ASSIGNED_SECRET_NAME_RE)?.replace(/^_+/, "") ?? null;
8118
8524
  if (value === null || name === null) return false;
8119
- if (!keywordEndsAPart(name) || ARN_CONTEXT_RE.test(before)) return false;
8120
- const prefix = before.match(/[A-Za-z0-9_]*$/)?.[0] ?? "";
8525
+ if (!keywordEndsAPart(name)) return false;
8526
+ if (ARN_CONTEXT_RE.test(before)) return false;
8527
+ const prefix = (before.match(/[A-Za-z0-9_]*$/)?.[0] ?? "") + (raw.startsWith("_") ? "_" : "");
8121
8528
  if (!nameHoldsCredential(prefix + name)) return false;
8122
8529
  return looksGenerated(value, 12, 3.5);
8123
8530
  }
8531
+ var BASIC_VALUE_RE = /([A-Za-z0-9+/]{8,512}={0,2})$/;
8532
+ var BASIC_PAIR_RE = /^([^:\s]{1,128}):(\S{8,256})$/;
8533
+ function validateBasicCredential(raw) {
8534
+ const b64 = capturedValue(raw, BASIC_VALUE_RE);
8535
+ if (b64 === null) return false;
8536
+ const bare = b64.replace(/=+$/, "");
8537
+ if (bare.length % 4 === 1) return false;
8538
+ const bytes = Buffer.from(b64, "base64");
8539
+ if (bytes.toString("base64").replace(/=+$/, "") !== bare) return false;
8540
+ const text = bytes.toString("utf8");
8541
+ if (!Buffer.from(text, "utf8").equals(bytes)) return false;
8542
+ for (let i = 0; i < text.length; i++) {
8543
+ const c = text.charCodeAt(i);
8544
+ if (c < 32 || c === 127) return false;
8545
+ }
8546
+ const pair = BASIC_PAIR_RE.exec(text);
8547
+ if (!pair) return false;
8548
+ const password = pair[2];
8549
+ if (!/[0-9]/.test(password) || !/[A-Za-z]/.test(password)) return false;
8550
+ const lower2 = password.toLowerCase();
8551
+ if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || hasSequentialRun(password)) return false;
8552
+ return shannonEntropy(password) >= 3;
8553
+ }
8554
+ var OTP_CAPTURE_RE = /["']([A-Z2-7]{16,128}=*)["']$/i;
8555
+ function validateOtpSecret(raw) {
8556
+ const secret = capturedValue(raw, OTP_CAPTURE_RE);
8557
+ if (secret === null || isOtpDocSecret(secret)) return false;
8558
+ return looksGenerated(secret.replace(/=+$/, ""), 16, 3, true);
8559
+ }
8124
8560
  var DLP_PATTERNS = [
8125
8561
  // ── AWS ───────────────────────────────────────────────────────────────────
8126
8562
  {
@@ -8458,6 +8894,22 @@ var DLP_PATTERNS = [
8458
8894
  contextBoost: true,
8459
8895
  minEntropy: 3
8460
8896
  },
8897
+ // ── HTTP Basic credential ─────────────────────────────────────────────────
8898
+ // `Authorization: Basic <base64 of user:password>`, or the bare scheme in a
8899
+ // config list. The validator decodes the value and accepts only a
8900
+ // `user:password` whose password looks generated (letters and digits, 8+
8901
+ // characters, the query-credential rule), so prose ("Basic authentication")
8902
+ // and documentation pairs (`admin:changeme`, `user:pass1234`) stay allowed.
8903
+ // review: the same weight as a bare Bearer token.
8904
+ {
8905
+ name: "HTTP Basic Credential",
8906
+ regex: /\bBasic[ \t]{1,8}([A-Za-z0-9+/]{8,512}={0,2})/i,
8907
+ severity: "review",
8908
+ keywords: ["basic"],
8909
+ validate: validateBasicCredential,
8910
+ redactGroup: 1,
8911
+ argumentsOnly: true
8912
+ },
8461
8913
  // ── Resend ────────────────────────────────────────────────────────────────
8462
8914
  {
8463
8915
  name: "Resend API Key",
@@ -8599,6 +9051,19 @@ var DLP_PATTERNS = [
8599
9051
  validate: validateQueryCredential,
8600
9052
  argumentsOnly: true
8601
9053
  },
9054
+ // ── OTP secret in a constructor ───────────────────────────────────────────
9055
+ // `ROTP::TOTP.new('<base32>')`, `pyotp.TOTP("<base32>")`, `new HOTP('...')`:
9056
+ // the shared secret of a one-time-password generator written as a literal.
9057
+ // The otpauth URI form is `Credential in URL Query`. review.
9058
+ {
9059
+ name: "OTP Secret",
9060
+ regex: /\b(?:TOTP|HOTP|OTP)(?:\.new|\.create)?[ \t]{0,8}\(?[ \t]{0,8}["']([A-Z2-7]{16,128}=*)["']/i,
9061
+ severity: "review",
9062
+ keywords: ["otp"],
9063
+ validate: validateOtpSecret,
9064
+ redactGroup: 1,
9065
+ argumentsOnly: true
9066
+ },
8602
9067
  // ── Secret assigned to a telling name ─────────────────────────────────────
8603
9068
  // `password: ...`, `JWT_SECRET=...`, `api_key = "..."`. The name alone is
8604
9069
  // not a finding: most such lines hold a reference (`process.env.X`), a
@@ -8606,12 +9071,14 @@ var DLP_PATTERNS = [
8606
9071
  // generated: 12+ characters, not an identifier, Shannon entropy of 3.5
8607
9072
  // bits per character or more. review, never block (node9Firewall#348,
8608
9073
  // item 4). Tuned on CredData's public split; its look-alike lines are the
8609
- // negative control.
9074
+ // negative control. A quote may be escaped (`\"access_token\":\"...\"`):
9075
+ // JSON written inside a string literal. The two optional quotes after the
9076
+ // name are written out, not as a counted group, to keep star height 1.
8610
9077
  {
8611
9078
  name: "Assigned Secret",
8612
- regex: /(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret)[A-Za-z0-9_]{0,40}["'\]]{0,2}[ \t]{0,8}(?::=|=>|[:=])[ \t]{0,8}["'`]?([A-Za-z0-9+/_.!@#$%^*~-]{12,512}={0,2})/i,
9079
+ regex: /(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret|consumer[_-]?key|app[_-]?key|signing[_-]?key|encryption[_-]?key|master[_-]?key|jsapi[_-]?ticket|\bpass(?![A-Za-z0-9])|_pass(?![A-Za-z0-9]))[A-Za-z0-9_]{0,40}\\?["'\]]?\\?["'\]]?[ \t]{0,8}(?::=|=>|[:=])[ \t]{0,8}\\?["'`]?([A-Za-z0-9+/_.!@#$%^*~-]{12,512}={0,2})/i,
8613
9080
  severity: "review",
8614
- keywords: ["password", "passphrase", "passwd", "pwd", "secret", "token", "key"],
9081
+ keywords: ["pass", "pwd", "secret", "token", "key", "ticket"],
8615
9082
  validate: validateAssignedSecret,
8616
9083
  argumentsOnly: true
8617
9084
  }
@@ -9190,10 +9657,322 @@ function parsePySpec(raw) {
9190
9657
  const exact = PY_EXACT_RE.exec(m[2].trim());
9191
9658
  return { name, version: exact ? exact[1] : void 0 };
9192
9659
  }
9660
+ var EXACT_VERSION_RE = /^=?v?(\d+(?:\.\d+)*(?:[-+][0-9A-Za-z][0-9A-Za-z.+-]*)?)$/;
9661
+ function exactVersion(v) {
9662
+ if (!v) return void 0;
9663
+ const m = EXACT_VERSION_RE.exec(v.trim());
9664
+ return m ? m[1] : void 0;
9665
+ }
9666
+ function push(out, ecosystem, manager, name, version, raw) {
9667
+ out.push({ ecosystem, manager, name, ...version ? { version } : {}, raw });
9668
+ }
9669
+ var GEM_NAME_RE = /^[\p{L}\p{N}][\p{L}\p{N}_.-]*$/u;
9670
+ var GEM_VALUE_FLAGS = /* @__PURE__ */ new Set([
9671
+ "-v",
9672
+ "--version",
9673
+ "-i",
9674
+ "--install-dir",
9675
+ "-n",
9676
+ "--bindir",
9677
+ "--document",
9678
+ "--build-root",
9679
+ "-P",
9680
+ "--trust-policy",
9681
+ "-s",
9682
+ "--source",
9683
+ "-p",
9684
+ "--http-proxy",
9685
+ "--platform",
9686
+ "-g",
9687
+ "--file",
9688
+ "--without"
9689
+ ]);
9690
+ var BUNDLE_VALUE_FLAGS = /* @__PURE__ */ new Set([
9691
+ "-v",
9692
+ "--version",
9693
+ "-g",
9694
+ "--group",
9695
+ "-s",
9696
+ "--source",
9697
+ "-r",
9698
+ "--require",
9699
+ "--path",
9700
+ "--git",
9701
+ "--github",
9702
+ "--branch",
9703
+ "--ref",
9704
+ "--glob"
9705
+ ]);
9706
+ function gemInstall(words, from, out) {
9707
+ const dash = words.indexOf("--", from);
9708
+ const own = dash < 0 ? words : words.slice(0, dash);
9709
+ const pinned = exactVersion(flagValues(own, from, ["-v", "--version"])[0]);
9710
+ for (const raw of operands(own, from, GEM_VALUE_FLAGS)) {
9711
+ if (NON_REGISTRY_RE.test(raw) || /\.gem$/i.test(raw)) continue;
9712
+ const colon = raw.indexOf(":");
9713
+ const name = colon < 0 ? raw : raw.slice(0, colon);
9714
+ if (!GEM_NAME_RE.test(name)) continue;
9715
+ push(
9716
+ out,
9717
+ "RubyGems",
9718
+ "gem",
9719
+ name,
9720
+ colon < 0 ? pinned : exactVersion(raw.slice(colon + 1)),
9721
+ raw
9722
+ );
9723
+ }
9724
+ }
9725
+ var CRATE_NAME_RE = /^[\p{L}\p{N}][\p{L}\p{N}_-]*$/u;
9726
+ var CARGO_ADD_VALUE_FLAGS = /* @__PURE__ */ new Set([
9727
+ "-F",
9728
+ "--features",
9729
+ "--rename",
9730
+ "--registry",
9731
+ "--manifest-path",
9732
+ "-p",
9733
+ "--package",
9734
+ "--git",
9735
+ "--branch",
9736
+ "--tag",
9737
+ "--rev",
9738
+ "--path",
9739
+ "--base",
9740
+ "--target",
9741
+ "--color",
9742
+ "--config",
9743
+ "-Z",
9744
+ "--lockfile-path"
9745
+ ]);
9746
+ var CARGO_INSTALL_VALUE_FLAGS = /* @__PURE__ */ new Set([
9747
+ "--version",
9748
+ "--vers",
9749
+ "--git",
9750
+ "--branch",
9751
+ "--tag",
9752
+ "--rev",
9753
+ "--path",
9754
+ "--root",
9755
+ "--index",
9756
+ "--registry",
9757
+ "-F",
9758
+ "--features",
9759
+ "--profile",
9760
+ "--target",
9761
+ "--target-dir",
9762
+ "-j",
9763
+ "--jobs",
9764
+ "--bin",
9765
+ "--example",
9766
+ "--color",
9767
+ "--config",
9768
+ "-Z"
9769
+ ]);
9770
+ function cargoCrates(words, from, manager, out) {
9771
+ const flags = manager === "cargo add" ? CARGO_ADD_VALUE_FLAGS : CARGO_INSTALL_VALUE_FLAGS;
9772
+ if (flagValues(words, from, ["--git", "--path", "--registry", "--index"]).length > 0) return;
9773
+ if (words.some((w) => w === "--git" || w === "--path")) return;
9774
+ const flagVersion = manager === "cargo install" ? exactVersion(flagValues(words, from, ["--version", "--vers"])[0]) : void 0;
9775
+ for (const raw of operands(words, from, flags)) {
9776
+ const at = raw.indexOf("@");
9777
+ const name = at < 0 ? raw : raw.slice(0, at);
9778
+ if (!CRATE_NAME_RE.test(name)) continue;
9779
+ push(
9780
+ out,
9781
+ "crates.io",
9782
+ manager,
9783
+ name,
9784
+ at < 0 ? flagVersion : exactVersion(raw.slice(at + 1)),
9785
+ raw
9786
+ );
9787
+ }
9788
+ }
9789
+ var GO_VALUE_FLAGS = /* @__PURE__ */ new Set([
9790
+ "-C",
9791
+ "-tags",
9792
+ "-ldflags",
9793
+ "-gcflags",
9794
+ "-asmflags",
9795
+ "-mod",
9796
+ "-modfile",
9797
+ "-o",
9798
+ "-p",
9799
+ "-pkgdir",
9800
+ "-toolexec",
9801
+ "-exec",
9802
+ "-overlay",
9803
+ "-pgo",
9804
+ "-buildmode",
9805
+ "-compiler",
9806
+ "-gccgoflags",
9807
+ "-installsuffix",
9808
+ "-covermode",
9809
+ "-coverpkg"
9810
+ ]);
9811
+ var GO_PATH_RE = /^[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)+(?:\/[\p{L}\p{N}_.~+-]+)*$/u;
9812
+ function goModules(words, from, manager, out) {
9813
+ let specs = operands(words, from, GO_VALUE_FLAGS);
9814
+ if (manager === "go run") specs = specs.slice(0, 1).filter((s) => s.includes("@"));
9815
+ for (const raw of specs) {
9816
+ const at = raw.indexOf("@");
9817
+ const pathPart = (at < 0 ? raw : raw.slice(0, at)).replace(/\/\.\.\.$/, "");
9818
+ const ver = at < 0 ? void 0 : raw.slice(at + 1);
9819
+ if (ver === "none") continue;
9820
+ if (!GO_PATH_RE.test(pathPart) || /\.go$/i.test(pathPart)) continue;
9821
+ const exact = ver && /^v\d/.test(ver) ? exactVersion(ver) : void 0;
9822
+ push(out, "Go", manager, pathPart, exact, raw);
9823
+ }
9824
+ }
9825
+ var NUGET_NAME_RE = /^[\p{L}\p{N}_][\p{L}\p{N}_.-]*$/u;
9826
+ var DOTNET_ADD_VALUE_FLAGS = /* @__PURE__ */ new Set([
9827
+ "-v",
9828
+ "--version",
9829
+ "-s",
9830
+ "--source",
9831
+ "-f",
9832
+ "--framework",
9833
+ "--package-directory"
9834
+ ]);
9835
+ var DOTNET_TOOL_VALUE_FLAGS = /* @__PURE__ */ new Set([
9836
+ "--version",
9837
+ "--add-source",
9838
+ "--configfile",
9839
+ "--framework",
9840
+ "--tool-path",
9841
+ "-a",
9842
+ "--arch",
9843
+ "--tool-manifest",
9844
+ "-v",
9845
+ "--verbosity"
9846
+ ]);
9847
+ var NUGET_VALUE_FLAGS = /* @__PURE__ */ new Set([
9848
+ "-version",
9849
+ "-outputdirectory",
9850
+ "-o",
9851
+ "-source",
9852
+ "-configfile",
9853
+ "-fallbacksource",
9854
+ "-framework",
9855
+ "-packagesavemode",
9856
+ "-dependencyversion",
9857
+ "-solutiondirectory",
9858
+ "-verbosity"
9859
+ ]);
9860
+ function dotnetAdd(words, from, out) {
9861
+ let k = -1;
9862
+ for (let i = from; i < Math.min(words.length, from + 2); i++) {
9863
+ if (lower(words[i]) === "package") {
9864
+ k = i;
9865
+ break;
9866
+ }
9867
+ }
9868
+ if (k < 0) return;
9869
+ const name = operands(words, k + 1, DOTNET_ADD_VALUE_FLAGS)[0];
9870
+ if (!name || !NUGET_NAME_RE.test(name)) return;
9871
+ const version = exactVersion(flagValues(words, k + 1, ["-v", "--version"])[0]);
9872
+ push(out, "NuGet", "dotnet add package", name, version, name);
9873
+ }
9874
+ function dotnetTool(words, from, out) {
9875
+ const name = operands(words, from, DOTNET_TOOL_VALUE_FLAGS)[0];
9876
+ if (!name || !NUGET_NAME_RE.test(name)) return;
9877
+ const version = exactVersion(flagValues(words, from, ["--version"])[0]);
9878
+ push(out, "NuGet", "dotnet tool", name, version, name);
9879
+ }
9880
+ function nugetInstall(words, from, out) {
9881
+ const lowered = words.map((w) => w !== null && w.startsWith("-") ? w.toLowerCase() : w);
9882
+ const name = operands(lowered, from, NUGET_VALUE_FLAGS)[0];
9883
+ if (!name || !NUGET_NAME_RE.test(name) || /\.config$/i.test(name)) return;
9884
+ const version = exactVersion(flagValues(lowered, from, ["-version"])[0]);
9885
+ push(out, "NuGet", "nuget install", name, version, name);
9886
+ }
9887
+ var MAVEN_COORD_RE = /^[\p{L}\p{N}_.-]+:[\p{L}\p{N}_.-]+$/u;
9888
+ function mavenGet(words, from, out) {
9889
+ const goal = words.slice(from).some(
9890
+ (w) => w !== null && /(?:^|:)dependency:get$|^org\.apache\.maven\.plugins:maven-dependency-plugin:(?:[\w.-]+:)?get$/.test(
9891
+ w
9892
+ )
9893
+ );
9894
+ if (!goal) return;
9895
+ const prop = (key) => {
9896
+ for (let i = from; i < words.length; i++) {
9897
+ const w = words[i];
9898
+ if (w === null) continue;
9899
+ if (w.startsWith(`-D${key}=`)) return w.slice(key.length + 3);
9900
+ if (w === "-D" && words[i + 1]?.startsWith(`${key}=`))
9901
+ return words[i + 1].slice(key.length + 1);
9902
+ }
9903
+ return void 0;
9904
+ };
9905
+ const artifact = prop("artifact");
9906
+ let coord;
9907
+ let ver;
9908
+ if (artifact) {
9909
+ const parts = artifact.split(":");
9910
+ if (parts.length < 2) return;
9911
+ coord = `${parts[0]}:${parts[1]}`;
9912
+ ver = parts[2];
9913
+ } else {
9914
+ const g = prop("groupId");
9915
+ const a = prop("artifactId");
9916
+ if (!g || !a) return;
9917
+ coord = `${g}:${a}`;
9918
+ ver = prop("version");
9919
+ }
9920
+ if (!MAVEN_COORD_RE.test(coord)) return;
9921
+ const exact = ver && !/^(?:LATEST|RELEASE)$/i.test(ver) ? exactVersion(ver) : void 0;
9922
+ push(out, "Maven", "mvn dependency:get", coord, exact, artifact ?? coord);
9923
+ }
9924
+ var COMPOSER_NAME_RE = /^[\p{L}\p{N}][\p{L}\p{N}_.-]*\/[\p{L}\p{N}][\p{L}\p{N}_.-]*$/u;
9925
+ var COMPOSER_VALUE_FLAGS = /* @__PURE__ */ new Set([
9926
+ "-d",
9927
+ "--working-dir",
9928
+ "--stability",
9929
+ "--repository",
9930
+ "--add-repository"
9931
+ ]);
9932
+ function composerPackages(words, from, manager, out) {
9933
+ const ops = operands(words, from, COMPOSER_VALUE_FLAGS);
9934
+ const specs = manager === "composer create-project" ? ops.slice(0, 1) : ops;
9935
+ for (const raw of specs) {
9936
+ const sep = raw.search(/[:=]/);
9937
+ const name = sep < 0 ? raw : raw.slice(0, sep);
9938
+ if (!COMPOSER_NAME_RE.test(name)) continue;
9939
+ let ver = sep < 0 ? void 0 : raw.slice(sep + 1);
9940
+ if (manager === "composer create-project" && ver === void 0) ver = ops[2] ?? void 0;
9941
+ push(out, "Packagist", manager, name.toLowerCase(), exactVersion(ver), raw);
9942
+ }
9943
+ }
9944
+ var EDITOR_HEADS = ["code", "code-insiders", "codium", "vscodium", "cursor"];
9945
+ var EXTENSION_ID_RE = /^[\p{L}\p{N}][\p{L}\p{N}_-]*\.[\p{L}\p{N}][\p{L}\p{N}_.-]*$/u;
9946
+ function editorExtensions(words, from, out) {
9947
+ for (const raw of flagValues(words, from, ["--install-extension"])) {
9948
+ if (/\.vsix$/i.test(raw) || NON_REGISTRY_RE.test(raw)) continue;
9949
+ const at = raw.lastIndexOf("@");
9950
+ const name = at <= 0 ? raw : raw.slice(0, at);
9951
+ if (!EXTENSION_ID_RE.test(name)) continue;
9952
+ push(
9953
+ out,
9954
+ "VSCode",
9955
+ "code --install-extension",
9956
+ name,
9957
+ at <= 0 ? void 0 : exactVersion(raw.slice(at + 1)),
9958
+ raw
9959
+ );
9960
+ }
9961
+ }
9193
9962
  function basename(w) {
9194
9963
  return (w ?? "").toLowerCase().split("/").pop() ?? "";
9195
9964
  }
9196
9965
  var MANAGER_HEADS = /* @__PURE__ */ new Set([
9966
+ "gem",
9967
+ "bundle",
9968
+ "cargo",
9969
+ "go",
9970
+ "dotnet",
9971
+ "nuget",
9972
+ "mvn",
9973
+ "mvnw",
9974
+ "composer",
9975
+ ...EDITOR_HEADS,
9197
9976
  "npm",
9198
9977
  "npx",
9199
9978
  "pnpm",
@@ -9442,7 +10221,63 @@ function fromCall(words, out, depth) {
9442
10221
  pushPy(out, "pipenv", operands(words, v + 1, PIPENV_VALUE_FLAGS));
9443
10222
  return;
9444
10223
  }
10224
+ case "gem": {
10225
+ const v = verbIndex(words, start + 1, GEM_VALUE_FLAGS);
10226
+ if (v >= 0 && ["install", "i"].includes(lower(words[v]))) gemInstall(words, v + 1, out);
10227
+ return;
10228
+ }
10229
+ case "bundle": {
10230
+ const v = verbIndex(words, start + 1, BUNDLE_VALUE_FLAGS);
10231
+ if (v < 0 || lower(words[v]) !== "add") return;
10232
+ if (flagValues(words, v + 1, ["--git", "--github", "--path"]).length > 0) return;
10233
+ const version = exactVersion(flagValues(words, v + 1, ["-v", "--version"])[0]);
10234
+ for (const raw of operands(words, v + 1, BUNDLE_VALUE_FLAGS))
10235
+ if (GEM_NAME_RE.test(raw)) push(out, "RubyGems", "bundle add", raw, version, raw);
10236
+ return;
10237
+ }
10238
+ case "cargo": {
10239
+ const from = words[start + 1]?.startsWith("+") ? start + 2 : start + 1;
10240
+ const v = verbIndex(words, from, CARGO_ADD_VALUE_FLAGS);
10241
+ const verb = lower(words[v]);
10242
+ if (verb === "add") cargoCrates(words, v + 1, "cargo add", out);
10243
+ else if (verb === "install") cargoCrates(words, v + 1, "cargo install", out);
10244
+ return;
10245
+ }
10246
+ case "go": {
10247
+ const v = verbIndex(words, start + 1, GO_VALUE_FLAGS);
10248
+ const verb = lower(words[v]);
10249
+ if (verb === "get" || verb === "install" || verb === "run")
10250
+ goModules(words, v + 1, `go ${verb}`, out);
10251
+ return;
10252
+ }
10253
+ case "dotnet": {
10254
+ const v = verbIndex(words, start + 1, DOTNET_ADD_VALUE_FLAGS);
10255
+ const verb = lower(words[v]);
10256
+ if (verb === "add") dotnetAdd(words, v + 1, out);
10257
+ else if (verb === "tool" && ["install", "update"].includes(lower(words[v + 1])))
10258
+ dotnetTool(words, v + 2, out);
10259
+ return;
10260
+ }
10261
+ case "nuget": {
10262
+ if (lower(words[start + 1]) === "install") nugetInstall(words, start + 2, out);
10263
+ return;
10264
+ }
10265
+ case "mvn":
10266
+ case "mvnw":
10267
+ mavenGet(words, start + 1, out);
10268
+ return;
10269
+ case "composer": {
10270
+ let v = verbIndex(words, start + 1, COMPOSER_VALUE_FLAGS);
10271
+ if (v >= 0 && lower(words[v]) === "global") v = verbIndex(words, v + 1, COMPOSER_VALUE_FLAGS);
10272
+ const verb = lower(words[v]);
10273
+ if (verb === "require" || verb === "req" || verb === "r")
10274
+ composerPackages(words, v + 1, "composer require", out);
10275
+ else if (verb === "create-project")
10276
+ composerPackages(words, v + 1, "composer create-project", out);
10277
+ return;
10278
+ }
9445
10279
  default:
10280
+ if (EDITOR_HEADS.includes(family)) editorExtensions(words, start + 1, out);
9446
10281
  return;
9447
10282
  }
9448
10283
  }
@@ -9747,6 +10582,7 @@ function checkToLegacyPolicy(policy, id, v) {
9747
10582
  var MAP_GOVERNED = /* @__PURE__ */ new Set([
9748
10583
  "files.shell-startup",
9749
10584
  "files.password-hashes",
10585
+ "files.system-dirs",
9750
10586
  "commands.inline-exec",
9751
10587
  "commands.eval-dynamic",
9752
10588
  "commands.curl-pipe-shell",
@@ -11364,18 +12200,17 @@ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
11364
12200
  }
11365
12201
  return out;
11366
12202
  }
11367
- var NUMBER_LEAD_RE = /[\s:=;([{"'+-]/;
11368
12203
  function isDecimalFraction(text, index, unseparated) {
11369
12204
  if (!unseparated) return false;
11370
12205
  const sep = text[index - 1];
11371
12206
  const a = text[index - 2];
11372
12207
  if (sep === ".") {
11373
12208
  if (a !== void 0 && a >= "0" && a <= "9") return true;
11374
- return a === void 0 || NUMBER_LEAD_RE.test(a);
12209
+ return a === void 0 || (a === "-" || a === "+") && index === 2;
11375
12210
  }
11376
12211
  if (sep === "," && a === "0") {
11377
12212
  const b = text[index - 3];
11378
- return b === void 0 || NUMBER_LEAD_RE.test(b);
12213
+ return b === void 0 || b === ";";
11379
12214
  }
11380
12215
  return false;
11381
12216
  }
@@ -12543,8 +13378,8 @@ function matchCanaryArgs(args, values) {
12543
13378
 
12544
13379
  // src/scan/canonical.ts
12545
13380
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
12546
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
12547
- var CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
13381
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v28";
13382
+ var CANONICAL_EXTRACTOR_HASH = "11df698796585cbe";
12548
13383
  var DEDUPE_PREVIEW_LEN = 120;
12549
13384
  function extractCanonicalFindings(call, ctx) {
12550
13385
  const out = [];