@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.js CHANGED
@@ -1305,6 +1305,11 @@ var CHECK_TEXT = {
1305
1305
  example: "cat /etc/shadow",
1306
1306
  advice: "Keep Review, or choose Block when agents must never read system password hashes."
1307
1307
  },
1308
+ "files.system-dirs": {
1309
+ 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.",
1310
+ example: "wget -O /usr/bin/tool https://example.com/tool",
1311
+ advice: "Keep Review on a workstation. A container image build that installs into /usr can set it to Log."
1312
+ },
1308
1313
  // ── Commands ──────────────────────────────────────────────────────────────
1309
1314
  "commands.inline-exec": {
1310
1315
  plain: "The agent runs a small program written inside the command itself.",
@@ -1501,7 +1506,7 @@ var CHECK_TEXT = {
1501
1506
  advice: "Fixed at Block. A person accepts the change on the machine (node9 mcp pin update)."
1502
1507
  },
1503
1508
  "loading.malicious-package": {
1504
- plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago.",
1509
+ 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.",
1505
1510
  example: "npm install of a package flagged as malware",
1506
1511
  advice: "Keep Block for known-malicious packages; brand-new packages already stop for Review."
1507
1512
  }
@@ -1552,6 +1557,15 @@ var PRODUCT_CHECKS = [
1552
1557
  defaultValue: "review",
1553
1558
  legacy: ["review-password-hash-read"]
1554
1559
  },
1560
+ {
1561
+ id: "files.system-dirs",
1562
+ group: "files",
1563
+ title: "System directories",
1564
+ catches: "Writes, new files and removals under /usr, /etc, /boot, /bin, /sbin, /lib and /var/log, and uploads of system files",
1565
+ values: ALL,
1566
+ defaultValue: "review",
1567
+ legacy: ["review-system-dir-mutation", "review-system-file-upload"]
1568
+ },
1555
1569
  // ── Commands ────────────────────────────────────────────────────────────
1556
1570
  {
1557
1571
  id: "commands.inline-exec",
@@ -3713,6 +3727,124 @@ function expandPlainParam(p) {
3713
3727
  if (recorded !== void 0) return recorded;
3714
3728
  return HOME_VARIABLES.has(p.Param?.Value) ? "~" : void 0;
3715
3729
  }
3730
+ var MAX_CALL_DEPTH = 4;
3731
+ var MAX_CALL_WALKS = 256;
3732
+ var callDepth = 0;
3733
+ var callWalks = 0;
3734
+ function functionBodies(f) {
3735
+ const out = /* @__PURE__ */ new Map();
3736
+ syntax.Walk(f, (node) => {
3737
+ const n = node;
3738
+ if (n && syntax.NodeType(n) === "FuncDecl" && n.Name?.Value && n.Body) {
3739
+ const list = out.get(n.Name.Value) ?? [];
3740
+ list.push(n.Body);
3741
+ out.set(n.Name.Value, list);
3742
+ }
3743
+ return true;
3744
+ });
3745
+ return out;
3746
+ }
3747
+ function rebindsPositionals(body) {
3748
+ let found = false;
3749
+ syntax.Walk(body, (node) => {
3750
+ const n = node;
3751
+ if (found || !n) return false;
3752
+ if (syntax.NodeType(n) === "CallExpr") {
3753
+ const words = (n.Args || []).map((a) => resolveWordLiteral(a));
3754
+ if (words[0] === "shift") found = true;
3755
+ else if (words[0] === "set" && words.slice(1).some((w) => w === null || w === "--" || !/^[-+]/.test(w)))
3756
+ found = true;
3757
+ }
3758
+ return !found;
3759
+ });
3760
+ return found;
3761
+ }
3762
+ function tableBindings() {
3763
+ if (!assignmentTable) return "";
3764
+ const out = [];
3765
+ for (const [name, rec] of assignmentTable)
3766
+ if (rec.at < currentStmtOffset) out.push(`${name}=${rec.value ?? "\0"}`);
3767
+ return out.sort().join("");
3768
+ }
3769
+ function walkWithCalls(f, visit) {
3770
+ const bodies = functionBodies(f);
3771
+ if (bodies.size === 0) {
3772
+ syntax.Walk(f, visit);
3773
+ return;
3774
+ }
3775
+ const seenCalls = /* @__PURE__ */ new Set();
3776
+ const inline = (call) => {
3777
+ const words = (call.Args || []).map((a) => resolveWordLiteral(a));
3778
+ const list = words[0] ? bodies.get(words[0]) : void 0;
3779
+ if (!list || callDepth >= MAX_CALL_DEPTH) return;
3780
+ const args = words.slice(1);
3781
+ const key = `${words[0]}\0${JSON.stringify(args)}\0${tableBindings()}`;
3782
+ if (seenCalls.has(key)) return;
3783
+ seenCalls.add(key);
3784
+ const outerTable = assignmentTable;
3785
+ const outerOffset = currentStmtOffset;
3786
+ for (const body of list) {
3787
+ if (callWalks >= MAX_CALL_WALKS) return;
3788
+ callWalks++;
3789
+ const table = /* @__PURE__ */ new Map();
3790
+ for (const [name, rec] of outerTable ?? [])
3791
+ if (rec.at < outerOffset) table.set(name, { value: rec.value, at: -1 });
3792
+ for (const name of ["1", "2", "3", "4", "5", "6", "7", "8", "9", "@", "*", "#"])
3793
+ table.delete(name);
3794
+ if (!rebindsPositionals(body)) {
3795
+ args.slice(0, 9).forEach((value, i) => table.set(String(i + 1), { value, at: -1 }));
3796
+ if (args.length === 1) {
3797
+ table.set("@", { value: args[0], at: -1 });
3798
+ table.set("*", { value: args[0], at: -1 });
3799
+ }
3800
+ table.set("#", { value: String(args.length), at: -1 });
3801
+ }
3802
+ assignmentTable = table;
3803
+ currentStmtOffset = Number.MAX_SAFE_INTEGER;
3804
+ callDepth++;
3805
+ try {
3806
+ if (body.Cmd && syntax.NodeType(body.Cmd) === "Block") recordTopLevelAssignments(body.Cmd);
3807
+ syntax.Walk(body, step);
3808
+ } finally {
3809
+ callDepth--;
3810
+ assignmentTable = outerTable;
3811
+ currentStmtOffset = outerOffset;
3812
+ }
3813
+ }
3814
+ };
3815
+ const step = (node) => {
3816
+ if (!node) return false;
3817
+ const go = visit(node);
3818
+ if (go !== false && syntax.NodeType(node) === "CallExpr") inline(node);
3819
+ return go;
3820
+ };
3821
+ syntax.Walk(f, step);
3822
+ }
3823
+ function withAssignments(f, body) {
3824
+ const outerTable = assignmentTable;
3825
+ const outerOffset = currentStmtOffset;
3826
+ const outerWalks = callWalks;
3827
+ callWalks = 0;
3828
+ assignmentTable = new Map(
3829
+ [...outerTable ?? []].map(([k, r]) => [k, { value: r.value, at: -1 }])
3830
+ );
3831
+ currentStmtOffset = Number.MAX_SAFE_INTEGER;
3832
+ try {
3833
+ recordTopLevelAssignments(f);
3834
+ return body();
3835
+ } finally {
3836
+ assignmentTable = outerTable;
3837
+ currentStmtOffset = outerOffset;
3838
+ callWalks = outerWalks;
3839
+ }
3840
+ }
3841
+ function trackStatement(n) {
3842
+ try {
3843
+ currentStmtOffset = n.Pos().Offset();
3844
+ } catch {
3845
+ currentStmtOffset = Number.MAX_SAFE_INTEGER;
3846
+ }
3847
+ }
3716
3848
  function resolveWordLiteral(w) {
3717
3849
  const parts = w?.Parts || [];
3718
3850
  let s = "";
@@ -3833,27 +3965,31 @@ function extractShellDestinations(command) {
3833
3965
  const out = [];
3834
3966
  const seen = /* @__PURE__ */ new Set();
3835
3967
  try {
3836
- syntax.Walk(f, (node) => {
3837
- if (!node) return false;
3838
- const n = node;
3839
- if (syntax.NodeType(n) !== "CallExpr") return true;
3840
- const callArgs = n.Args || [];
3841
- if (callArgs.length === 0) return true;
3842
- const words = callArgs.map((a) => resolveWordLiteral(a));
3843
- const at = unwrapCommandHead(words);
3844
- const name = (words[at] || "").toLowerCase().split("/").pop() ?? "";
3845
- if (!NET_BINARIES.has(name)) return true;
3846
- const rest = words.slice(at + 1);
3847
- for (const raw of destTokensForBinary(name, rest)) {
3848
- const host2 = parseDestHost(raw);
3849
- if (!host2) continue;
3850
- const key = `${name}:${host2}`;
3851
- if (seen.has(key)) continue;
3852
- seen.add(key);
3853
- out.push({ host: host2, binary: name, raw });
3854
- }
3855
- return true;
3856
- });
3968
+ withAssignments(
3969
+ f,
3970
+ () => walkWithCalls(f, (node) => {
3971
+ if (!node) return false;
3972
+ const n = node;
3973
+ if (syntax.NodeType(n) === "Stmt") trackStatement(n);
3974
+ if (syntax.NodeType(n) !== "CallExpr") return true;
3975
+ const callArgs = n.Args || [];
3976
+ if (callArgs.length === 0) return true;
3977
+ const words = callArgs.map((a) => resolveWordLiteral(a));
3978
+ const at = unwrapCommandHead(words);
3979
+ const name = (words[at] || "").toLowerCase().split("/").pop() ?? "";
3980
+ if (!NET_BINARIES.has(name)) return true;
3981
+ const rest = words.slice(at + 1);
3982
+ for (const raw of destTokensForBinary(name, rest)) {
3983
+ const host2 = parseDestHost(raw);
3984
+ if (!host2) continue;
3985
+ const key = `${name}:${host2}`;
3986
+ if (seen.has(key)) continue;
3987
+ seen.add(key);
3988
+ out.push({ host: host2, binary: name, raw });
3989
+ }
3990
+ return true;
3991
+ })
3992
+ );
3857
3993
  } catch {
3858
3994
  return out;
3859
3995
  }
@@ -3865,39 +4001,45 @@ function extractShellDestTokens(command) {
3865
4001
  const out = [];
3866
4002
  const seen = /* @__PURE__ */ new Set();
3867
4003
  try {
3868
- syntax.Walk(f, (node) => {
3869
- if (!node) return false;
3870
- const n = node;
3871
- if (syntax.NodeType(n) !== "CallExpr") return true;
3872
- const callArgs = n.Args || [];
3873
- if (callArgs.length === 0) return true;
3874
- const name = (resolveWordLiteral(callArgs[0]) || "").toLowerCase();
3875
- if (!NET_BINARIES.has(name)) return true;
3876
- const rest = callArgs.slice(1).map((a) => resolveWordLiteral(a));
3877
- for (const raw of destTokensForBinary(name, rest)) {
3878
- if (!raw) continue;
3879
- let tok = raw.trim();
3880
- const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(tok);
3881
- const hasScheme = scheme !== null;
3882
- if (hasScheme) tok = tok.slice(scheme[0].length);
3883
- tok = tok.split(/[/?#]/)[0];
3884
- const at = tok.lastIndexOf("@");
3885
- if (at >= 0) tok = tok.slice(at + 1);
3886
- if (tok.startsWith("[")) {
3887
- const close = tok.indexOf("]");
3888
- if (close > 0) tok = tok.slice(0, close + 1);
3889
- } else {
3890
- tok = tok.split(":")[0];
4004
+ withAssignments(
4005
+ f,
4006
+ () => walkWithCalls(f, (node) => {
4007
+ if (!node) return false;
4008
+ const n = node;
4009
+ if (syntax.NodeType(n) === "Stmt") trackStatement(n);
4010
+ if (syntax.NodeType(n) !== "CallExpr") return true;
4011
+ const callArgs = n.Args || [];
4012
+ if (callArgs.length === 0) return true;
4013
+ const words = callArgs.map((a) => resolveWordLiteral(a));
4014
+ const head = unwrapCommandHead(words);
4015
+ const name = (words[head] || "").toLowerCase().split("/").pop() ?? "";
4016
+ if (!NET_BINARIES.has(name)) return true;
4017
+ const rest = words.slice(head + 1);
4018
+ for (const raw of destTokensForBinary(name, rest)) {
4019
+ if (!raw) continue;
4020
+ let tok = raw.trim();
4021
+ const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(tok);
4022
+ const hasScheme = scheme !== null;
4023
+ if (hasScheme) tok = tok.slice(scheme[0].length);
4024
+ tok = tok.split(/[/?#]/)[0];
4025
+ const at = tok.lastIndexOf("@");
4026
+ if (at >= 0) tok = tok.slice(at + 1);
4027
+ if (tok.startsWith("[")) {
4028
+ const close = tok.indexOf("]");
4029
+ if (close > 0) tok = tok.slice(0, close + 1);
4030
+ } else {
4031
+ tok = tok.split(":")[0];
4032
+ }
4033
+ if (!tok) continue;
4034
+ if (!hasScheme && /^\d+$/.test(tok) && Number(tok) < 16777216) continue;
4035
+ const key = `${name}:${tok}`;
4036
+ if (seen.has(key)) continue;
4037
+ seen.add(key);
4038
+ out.push({ token: tok, binary: name });
3891
4039
  }
3892
- if (!tok) continue;
3893
- if (!hasScheme && /^\d+$/.test(tok) && Number(tok) < 16777216) continue;
3894
- const key = `${name}:${tok}`;
3895
- if (seen.has(key)) continue;
3896
- seen.add(key);
3897
- out.push({ token: tok, binary: name });
3898
- }
3899
- return true;
3900
- });
4040
+ return true;
4041
+ })
4042
+ );
3901
4043
  } catch {
3902
4044
  return out;
3903
4045
  }
@@ -4027,6 +4169,7 @@ function analyzeFsOperationImpl(command, depth = 0) {
4027
4169
  if (depth === 0) {
4028
4170
  seenPayloads = /* @__PURE__ */ new Set();
4029
4171
  payloadBudget = PAYLOAD_BUDGET;
4172
+ if (callDepth === 0) callWalks = 0;
4030
4173
  }
4031
4174
  assignmentTable = new Map(
4032
4175
  [...outerTable ?? []].map(([k, r]) => [k, { value: r.value, at: -1 }])
@@ -4034,7 +4177,7 @@ function analyzeFsOperationImpl(command, depth = 0) {
4034
4177
  currentStmtOffset = Number.MAX_SAFE_INTEGER;
4035
4178
  try {
4036
4179
  recordTopLevelAssignments(f);
4037
- syntax.Walk(f, (node) => {
4180
+ walkWithCalls(f, (node) => {
4038
4181
  if (!node || result?.verdict === "block") return false;
4039
4182
  const n = node;
4040
4183
  const nodeType = syntax.NodeType(n);
@@ -4876,10 +5019,17 @@ function shellRuleArgs(tool, args, ruleTool, inspection = {}) {
4876
5019
  var import_mvdan_sh2 = __toESM(require("mvdan-sh"));
4877
5020
  var { syntax: syntax2 } = import_mvdan_sh2.default;
4878
5021
  var MAX_ALTERNATIVES = 64;
5022
+ var MAX_CALL_DEPTH2 = 4;
5023
+ var MAX_CALL_WALKS2 = 256;
5024
+ var POSITIONAL = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "@", "*", "#"];
4879
5025
  var MAX_DEPTH = 64;
4880
5026
  var MAX_PAYLOAD_DEPTH = 24;
4881
5027
  var unique = (a) => [...new Set(a)].slice(0, MAX_ALTERNATIVES);
4882
- var clone = (s) => ({ cwd: [...s.cwd], vars: new Map(s.vars) });
5028
+ var clone = (s) => ({
5029
+ cwd: [...s.cwd],
5030
+ vars: new Map(s.vars),
5031
+ ...s.callDepth ? { callDepth: s.callDepth } : {}
5032
+ });
4883
5033
  function runnablePrefix(command) {
4884
5034
  let text = command;
4885
5035
  for (let attempt = 0; attempt < 32; attempt++) {
@@ -4895,6 +5045,81 @@ function runnablePrefix(command) {
4895
5045
  }
4896
5046
  return null;
4897
5047
  }
5048
+ var SENDING_STDIN = /* @__PURE__ */ new Set(["nc", "ncat", "netcat", "socat", "telnet", "curl", "wget"]);
5049
+ var DOWNLOAD_SHORT_VALUE = {
5050
+ curl: "odDeEFHKmPrtTuUwxXyYzAbcCQ",
5051
+ wget: "OoaPiBetTwQlARDXIUY",
5052
+ aria2c: "odisx"
5053
+ };
5054
+ var DOWNLOAD_LONG_VALUE = {
5055
+ curl: [
5056
+ "--output",
5057
+ "--output-dir",
5058
+ "--dump-header",
5059
+ "--cookie-jar",
5060
+ "--data",
5061
+ "--data-binary",
5062
+ "--data-raw",
5063
+ "--data-ascii",
5064
+ "--data-urlencode",
5065
+ "--form",
5066
+ "--header",
5067
+ "--request",
5068
+ "--user",
5069
+ "--user-agent",
5070
+ "--referer",
5071
+ "--cookie",
5072
+ "--config",
5073
+ "--json",
5074
+ "--upload-file",
5075
+ "--max-time",
5076
+ "--proxy",
5077
+ "--write-out",
5078
+ "--url"
5079
+ ],
5080
+ wget: [
5081
+ "--output-document",
5082
+ "--output-file",
5083
+ "--append-output",
5084
+ "--directory-prefix",
5085
+ "--input-file",
5086
+ "--post-data",
5087
+ "--post-file",
5088
+ "--body-data",
5089
+ "--body-file",
5090
+ "--method",
5091
+ "--header",
5092
+ "--user-agent",
5093
+ "--user",
5094
+ "--password",
5095
+ "--tries",
5096
+ "--timeout"
5097
+ ],
5098
+ aria2c: ["--out", "--dir", "--input-file"]
5099
+ };
5100
+ var DOWNLOAD_OUTPUT_FLAGS = {
5101
+ curl: ["-o", "--output", "-D", "--dump-header", "-c", "--cookie-jar"],
5102
+ wget: ["-O", "--output-document", "-o", "--output-file", "-a", "--append-output"],
5103
+ aria2c: ["-o", "--out"]
5104
+ };
5105
+ var DOWNLOAD_DIR_FLAGS = {
5106
+ curl: ["--output-dir"],
5107
+ wget: ["-P", "--directory-prefix"],
5108
+ aria2c: ["-d", "--dir"]
5109
+ };
5110
+ function uploadedFile(tool, flag, value) {
5111
+ const v = value.value;
5112
+ const file = (f) => f && f !== "-" && f !== "." ? { value: f } : null;
5113
+ if (tool === "curl") {
5114
+ if (["-d", "--data", "--data-ascii", "--data-binary", "--json"].includes(flag))
5115
+ return v.startsWith("@") ? file(v.slice(1)) : null;
5116
+ if (flag === "--data-urlencode") return file(/^[^=@]*@(.+)$/.exec(v)?.[1]);
5117
+ if (flag === "-F" || flag === "--form") return file(/^[^=]*=[@<]([^;]+)/.exec(v)?.[1]);
5118
+ if (flag === "-T" || flag === "--upload-file") return file(v);
5119
+ }
5120
+ if (tool === "wget" && ["--post-file", "--body-file"].includes(flag)) return file(v);
5121
+ return null;
5122
+ }
4898
5123
  var base = (s) => (s ?? "").replace(/\/+$/, "").split("/").pop() ?? "";
4899
5124
  var quoteGlob = (s) => s.replace(/[\\*?\[\]{}()!+@]/g, "\\$&");
4900
5125
  var asWord = (p) => ({ value: p.value, ...p.glob ? { pattern: p.pattern } : {} });
@@ -4982,6 +5207,9 @@ function wordValues(word, state) {
4982
5207
  function collectShellFileAccesses(command, context = {}) {
4983
5208
  const out = [];
4984
5209
  let payloads = 256;
5210
+ const functions = /* @__PURE__ */ new Map();
5211
+ const seenCalls = /* @__PURE__ */ new Set();
5212
+ let callWalks2 = MAX_CALL_WALKS2;
4985
5213
  const initial = {
4986
5214
  cwd: [context.cwd ?? ""],
4987
5215
  vars: /* @__PURE__ */ new Map([["HOME", [context.homeDirs?.[0] ?? "~"]]])
@@ -5239,8 +5467,98 @@ function collectShellFileAccesses(command, context = {}) {
5239
5467
  }
5240
5468
  return;
5241
5469
  }
5470
+ if (name === "wget" || name === "curl" || name === "aria2c") {
5471
+ downloadOutputs(name, args, state);
5472
+ return;
5473
+ }
5474
+ if (["http", "https", "xh", "xhs"].includes(name)) {
5475
+ for (const token of args) {
5476
+ if (!token || token.dynamic || /^[a-z][a-z0-9+.-]*:\/\//i.test(token.value)) continue;
5477
+ const m = /^(?:@|[^=:@\s]+@|[^=:@\s]*=@)(.+)$/.exec(token.value);
5478
+ if (m && m[1] !== "-") add("read", { value: m[1] }, state, { upload: true });
5479
+ }
5480
+ return;
5481
+ }
5482
+ if (name === "scp" || name === "rsync") {
5483
+ const operands2 = strings.filter((s) => s && !s.startsWith("-"));
5484
+ const remote = operands2.slice(1).some((o) => /^[^/\s]+:/.test(o));
5485
+ for (const p of copySourcePaths(words))
5486
+ add("read", locate(p), state, remote ? { upload: true } : {});
5487
+ return;
5488
+ }
5242
5489
  for (const p of copySourcePaths(words)) add("read", locate(p), state);
5243
5490
  }
5491
+ function downloadOutputs(name, args, state) {
5492
+ const valueShort = DOWNLOAD_SHORT_VALUE[name];
5493
+ const outputs = [];
5494
+ const urls = [];
5495
+ let dir = null;
5496
+ let remoteName = false;
5497
+ let document = false;
5498
+ let serverNamed = false;
5499
+ const take = (flag, value) => {
5500
+ if (!value) return;
5501
+ const sent = uploadedFile(name, flag, value);
5502
+ if (sent) add("read", sent, state, { upload: true });
5503
+ if (DOWNLOAD_OUTPUT_FLAGS[name].includes(flag)) {
5504
+ if (["-O", "--output-document", "--out"].includes(flag) || name === "aria2c" && flag === "-o")
5505
+ document = true;
5506
+ if (value.value !== "-" || value.pattern || value.dynamic) outputs.push(value);
5507
+ } else if (DOWNLOAD_DIR_FLAGS[name].includes(flag)) dir = value;
5508
+ else if (name === "wget" && (flag === "-i" || flag === "--input-file")) serverNamed = true;
5509
+ };
5510
+ for (let i = 0; i < args.length; i++) {
5511
+ const token = args[i];
5512
+ if (!token) continue;
5513
+ const v = token.value;
5514
+ if (v.startsWith("--")) {
5515
+ const eq = v.indexOf("=");
5516
+ const flag = eq < 0 ? v : v.slice(0, eq);
5517
+ if (["--remote-name", "--remote-name-all"].includes(flag)) remoteName = true;
5518
+ if (["--remote-header-name", "--recursive", "--mirror", "--page-requisites"].includes(flag))
5519
+ serverNamed = true;
5520
+ if (DOWNLOAD_LONG_VALUE[name].includes(flag))
5521
+ take(flag, eq < 0 ? args[++i] ?? null : { ...token, value: v.slice(eq + 1) });
5522
+ continue;
5523
+ }
5524
+ if (v.startsWith("-") && v.length > 1 && !token.dynamic) {
5525
+ for (let j = 1; j < v.length; j++) {
5526
+ const c = v[j];
5527
+ if (name === "wget" && c === "n") {
5528
+ j++;
5529
+ continue;
5530
+ }
5531
+ if (name === "curl" && c === "O") remoteName = true;
5532
+ if (name === "curl" && c === "J") serverNamed = true;
5533
+ if (name === "wget" && (c === "r" || c === "m" || c === "p")) serverNamed = true;
5534
+ if (valueShort.includes(c)) {
5535
+ const rest = v.slice(j + 1);
5536
+ take(`-${c}`, rest ? { value: rest } : args[++i] ?? null);
5537
+ break;
5538
+ }
5539
+ }
5540
+ continue;
5541
+ }
5542
+ if (/^(?:https?|ftps?):\/\//i.test(v)) urls.push(v);
5543
+ }
5544
+ for (const out2 of outputs) {
5545
+ const spelled = name === "aria2c" && dir?.value && !out2.value.startsWith("/") ? { ...out2, value: `${dir.value.replace(/\/+$/, "")}/${out2.value}` } : out2;
5546
+ if (name === "curl" && /#\d/.test(spelled.value))
5547
+ add("write", { value: "", pattern: spelled.value.replace(/#\d+/g, "*"), dot: true }, state);
5548
+ else add("write", spelled, state);
5549
+ }
5550
+ const remote = name === "curl" ? remoteName || serverNamed : !document || serverNamed;
5551
+ if (!remote) return;
5552
+ const into = dir?.value ? dir.value.replace(/\/+$/, "") : ".";
5553
+ if (serverNamed || urls.length === 0) {
5554
+ add("write", { value: "", pattern: `${quoteGlob(into)}/*`, dot: true }, state);
5555
+ return;
5556
+ }
5557
+ for (const url of urls) {
5558
+ const file = url.replace(/[?#].*$/, "").replace(/^[a-z]+:\/\/[^/]*/i, "").split("/").pop();
5559
+ add("write", { value: `${into}/${file || "index.html"}` }, state);
5560
+ }
5561
+ }
5244
5562
  function findActions2(tokens, words, head, state, nested, depth) {
5245
5563
  const starts = findStartPoints(words, head).starts;
5246
5564
  const roots = (starts.length ? starts : ["."]).slice(0, MAX_ALTERNATIVES);
@@ -5312,7 +5630,35 @@ function collectShellFileAccesses(command, context = {}) {
5312
5630
  const words = wordValues(node, state);
5313
5631
  alternatives = alternatives.flatMap((prefix) => (words.length ? words : [null]).map((w) => [...prefix, w])).slice(0, MAX_ALTERNATIVES);
5314
5632
  }
5315
- for (const tokens of alternatives) fromWords(tokens, state, nested, depth);
5633
+ for (const tokens of alternatives) {
5634
+ fromWords(tokens, state, nested, depth);
5635
+ inlineCall(tokens, state, depth);
5636
+ }
5637
+ }
5638
+ function inlineCall(tokens, state, depth) {
5639
+ const head = tokens[0];
5640
+ if (!head || head.dynamic || head.pattern) return;
5641
+ const bodies = functions.get(head.value);
5642
+ if (!bodies || (state.callDepth ?? 0) >= MAX_CALL_DEPTH2) return;
5643
+ const args = tokens.slice(1).map((a) => a && !a.dynamic ? a.value : null);
5644
+ const vars = JSON.stringify([...state.vars].sort(([a], [b]) => a < b ? -1 : 1));
5645
+ const key = `${head.value}\0${JSON.stringify(args)}\0${state.cwd.join("")}\0${vars}`;
5646
+ if (seenCalls.has(key)) return;
5647
+ seenCalls.add(key);
5648
+ for (const body of bodies) {
5649
+ if (callWalks2-- <= 0) return;
5650
+ const local = clone(state);
5651
+ local.callDepth = (state.callDepth ?? 0) + 1;
5652
+ for (const name of POSITIONAL) local.vars.delete(name);
5653
+ if (!rebindsPositionals(body)) {
5654
+ args.slice(0, 9).forEach((v, i) => local.vars.set(String(i + 1), v === null ? null : [v]));
5655
+ const all = args.every((v) => v !== null) && args.length ? unique(args) : null;
5656
+ local.vars.set("@", all);
5657
+ local.vars.set("*", all);
5658
+ local.vars.set("#", [String(args.length)]);
5659
+ }
5660
+ statement(body, local, depth + 1);
5661
+ }
5316
5662
  }
5317
5663
  function readsScriptFromStdin(stmt) {
5318
5664
  const cmd = stmt?.Cmd;
@@ -5349,11 +5695,13 @@ function collectShellFileAccesses(command, context = {}) {
5349
5695
  if (!stmt || depth > MAX_DEPTH) return;
5350
5696
  state.onSuccess = void 0;
5351
5697
  if (stmt.Background) state = clone(state);
5698
+ const headWord = stmt.Cmd && syntax2.NodeType(stmt.Cmd) === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
5699
+ const sends = SENDING_STDIN.has(headWord);
5352
5700
  for (const redir of stmt.Redirs ?? []) {
5353
5701
  substitutions(redir.Word, state, depth);
5354
5702
  for (const word of wordValues(redir.Word, state)) {
5355
5703
  if (WRITES.has(redir.Op)) add("write", word, state);
5356
- if (READS.has(redir.Op)) add("read", word, state);
5704
+ if (READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
5357
5705
  if (redir.Op === DUP_OUT && word.value && !/^\d+$/.test(word.value))
5358
5706
  add("write", word, state);
5359
5707
  }
@@ -5462,7 +5810,10 @@ function collectShellFileAccesses(command, context = {}) {
5462
5810
  }
5463
5811
  const parsed = parseShared(command);
5464
5812
  const program = typeof parsed !== "symbol" ? parsed : runnablePrefix(command);
5465
- if (program) statements(program.Stmts ?? [], initial, 0);
5813
+ if (program) {
5814
+ for (const [name, bodies] of functionBodies(program)) functions.set(name, bodies);
5815
+ statements(program.Stmts ?? [], initial, 0);
5816
+ }
5466
5817
  return out;
5467
5818
  }
5468
5819
 
@@ -5477,6 +5828,18 @@ var SYSTEM_AUTH_FILES = [
5477
5828
  var SYSTEM_AUTH_DIRS = ["/etc/security", "/etc/pam.d", "/etc/sudoers.d"];
5478
5829
  var PASSWORD_HASH_FILES = ["/etc/shadow", "/etc/gshadow"];
5479
5830
  var STARTUP_NAMES = [".bashrc", ".zshrc", ".profile", ".bash_profile"];
5831
+ var SYSTEM_DIRS = [
5832
+ "/usr",
5833
+ "/etc",
5834
+ "/boot",
5835
+ "/bin",
5836
+ "/sbin",
5837
+ "/lib",
5838
+ "/lib64",
5839
+ "/var/log"
5840
+ ];
5841
+ var SYSTEM_DIRS_EXEMPT = ["/usr/local", "/usr/src"];
5842
+ var UPLOAD_SYSTEM_DIRS = [...SYSTEM_DIRS, "/proc", "/sys", "/root"];
5480
5843
  var AGENT_INSTRUCTION_FILES = [
5481
5844
  ".gitlab-ci.yml",
5482
5845
  "CLAUDE.md",
@@ -5609,6 +5972,34 @@ function hits(access, paths, directories, context) {
5609
5972
  }
5610
5973
  return false;
5611
5974
  }
5975
+ var exempt = (p) => SYSTEM_DIRS_EXEMPT.some((d) => within(p, d));
5976
+ function hitsSystemDir(access, context, dirs = SYSTEM_DIRS) {
5977
+ const home = context.homeDirs?.[0] ?? "~";
5978
+ const candidates = access.candidates ?? [
5979
+ normalizeFilePath(access.path, access.cwd ?? context.cwd, home)
5980
+ ];
5981
+ for (const p of candidates) {
5982
+ if (dirs.some((d) => within(p, d)) && !exempt(p)) return true;
5983
+ if (access.recursive && dirs.some((d) => within(d, p))) return true;
5984
+ }
5985
+ if (!access.glob) return false;
5986
+ const pattern = normalizeFilePath(access.glob, access.cwd ?? context.cwd, home);
5987
+ const magic = pattern.search(/[*?[{]/);
5988
+ const literal = magic < 0 ? pattern : pattern.slice(0, pattern.lastIndexOf("/", magic) + 1);
5989
+ if (literal && exempt(literal.replace(/\/$/, "") || "/")) return false;
5990
+ const options = { dot: access.dotGlob === true, nonegate: true };
5991
+ const components = pattern.split("/");
5992
+ for (const root of dirs) {
5993
+ const count = root.split("/").length;
5994
+ if (components.length > count && (0, import_picomatch2.default)(components.slice(0, count).join("/"), options)(root))
5995
+ return true;
5996
+ if (access.recursive && (0, import_picomatch2.default)(pattern, options)(root)) return true;
5997
+ }
5998
+ return false;
5999
+ }
6000
+ function uploadDirs(context) {
6001
+ return context.homeDirs?.[0] === "/root" ? UPLOAD_SYSTEM_DIRS.filter((d) => d !== "/root") : UPLOAD_SYSTEM_DIRS;
6002
+ }
5612
6003
  var RANK = { allow: 0, review: 1, block: 2 };
5613
6004
  function evaluateProtectedFileAccess(accesses, context, settings) {
5614
6005
  const homes = [.../* @__PURE__ */ new Set([...context.homeDirs ?? ["~"], "/root"])];
@@ -5631,6 +6022,14 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
5631
6022
  "files.shell-startup",
5632
6023
  "review-shell-startup-mutation",
5633
6024
  "Changing shell startup files requires approval"
6025
+ ] : mutation && hitsSystemDir(access, context) ? [
6026
+ "files.system-dirs",
6027
+ "review-system-dir-mutation",
6028
+ "Changing files in a system directory requires approval"
6029
+ ] : !mutation && access.upload && hitsSystemDir(access, context, uploadDirs(context)) ? [
6030
+ "files.system-dirs",
6031
+ "review-system-file-upload",
6032
+ "Uploading a system file requires approval"
5634
6033
  ] : !mutation && hits(access, PASSWORD_HASH_FILES, [], context) ? [
5635
6034
  "files.password-hashes",
5636
6035
  "review-password-hash-read",
@@ -8275,6 +8674,7 @@ var REFERENCE_VALUE_RE = /^[$@%]|^(?:process\.env|os\.environ|env|config|setting
8275
8674
  var IDENTIFIER_VALUE_RE = /^[A-Za-z_.-]+$/;
8276
8675
  var PATH_VALUE_RE = /^(?:\/|\.{1,2}\/|~\/)/;
8277
8676
  var DOTTED_REFERENCE_RE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/;
8677
+ var CONCATENATION_RE = /^\+[A-Za-z_$][\w$]*\./;
8278
8678
  var EMAIL_VALUE_RE = /^[^@\s]+@[^@\s]+\.[A-Za-z]{2,}$/;
8279
8679
  function looksLikeJoinedWords(value) {
8280
8680
  const segments2 = value.replace(/[0-9]/g, "").split(/[-_.]/);
@@ -8305,26 +8705,32 @@ function looksGenerated(value, minLength, minEntropy, lettersOnlyAllowed = false
8305
8705
  if (EMAIL_VALUE_RE.test(value)) return false;
8306
8706
  if (looksLikeJoinedWords(value) || hasSequentialRun(value)) return false;
8307
8707
  if (PATH_VALUE_RE.test(value) || DOTTED_REFERENCE_RE.test(value)) return false;
8708
+ if (CONCATENATION_RE.test(value)) return false;
8308
8709
  if (rejectedByStructuredValidator(value)) return false;
8309
8710
  return shannonEntropy(value) >= minEntropy;
8310
8711
  }
8311
8712
  var FIXTURE_NAME_RE = /(?:fake|dummy|example|sample|mock|stub|placeholder|test)/i;
8312
- 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;
8713
+ 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;
8313
8714
  function nameHoldsCredential(name) {
8314
8715
  return !FIXTURE_NAME_RE.test(name) && !DERIVATIVE_NAME_RE.test(name);
8315
8716
  }
8316
8717
  var QUERY_CREDENTIAL_VALUE_RE = /=([A-Za-z0-9%+/_.~-]{8,512}={0,2})$/;
8317
8718
  var OTP_SECRET_RE = /^[A-Z2-7]{16,}=*$/i;
8719
+ var OTP_DOC_SECRETS = /* @__PURE__ */ new Set(["JBSWY3DPEHPK3PXP", "GEZDGNBVGY3TQOJQ"]);
8720
+ function isOtpDocSecret(value) {
8721
+ return OTP_DOC_SECRETS.has(value.replace(/=+$/, "").toUpperCase());
8722
+ }
8318
8723
  function validateQueryCredential(raw) {
8319
8724
  const value = capturedValue(raw, QUERY_CREDENTIAL_VALUE_RE);
8320
8725
  if (value === null) return false;
8321
- if (OTP_SECRET_RE.test(value)) return looksGenerated(value, 16, 3, true);
8726
+ if (OTP_SECRET_RE.test(value))
8727
+ return !isOtpDocSecret(value) && looksGenerated(value, 16, 3, true);
8322
8728
  if (!/[0-9]/.test(value) || !/[A-Za-z]/.test(value)) return false;
8323
8729
  return looksGenerated(value, 12, 3);
8324
8730
  }
8325
- var ASSIGNED_SECRET_VALUE_RE = /(?::=|=>|[:=])[ \t]{0,8}["'`]?([A-Za-z0-9+/_.!@#$%^*~-]{12,512}={0,2})$/;
8731
+ var ASSIGNED_SECRET_VALUE_RE = /(?::=|=>|[:=])[ \t]{0,8}\\?["'`]?([A-Za-z0-9+/_.!@#$%^*~-]{12,512}={0,2})$/;
8326
8732
  var ASSIGNED_SECRET_NAME_RE = /^([A-Za-z0-9_]+)/;
8327
- var NAME_KEYWORD_RE = /^(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret)/i;
8733
+ 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;
8328
8734
  function keywordEndsAPart(name) {
8329
8735
  const keyword = name.match(NAME_KEYWORD_RE)?.[0];
8330
8736
  if (!keyword) return false;
@@ -8336,13 +8742,43 @@ function keywordEndsAPart(name) {
8336
8742
  var ARN_CONTEXT_RE = /\barn:[A-Za-z0-9-]*:[^\s"'`]*$/i;
8337
8743
  function validateAssignedSecret(raw, before = "") {
8338
8744
  const value = capturedValue(raw, ASSIGNED_SECRET_VALUE_RE);
8339
- const name = capturedValue(raw, ASSIGNED_SECRET_NAME_RE);
8745
+ const name = capturedValue(raw, ASSIGNED_SECRET_NAME_RE)?.replace(/^_+/, "") ?? null;
8340
8746
  if (value === null || name === null) return false;
8341
- if (!keywordEndsAPart(name) || ARN_CONTEXT_RE.test(before)) return false;
8342
- const prefix = before.match(/[A-Za-z0-9_]*$/)?.[0] ?? "";
8747
+ if (!keywordEndsAPart(name)) return false;
8748
+ if (ARN_CONTEXT_RE.test(before)) return false;
8749
+ const prefix = (before.match(/[A-Za-z0-9_]*$/)?.[0] ?? "") + (raw.startsWith("_") ? "_" : "");
8343
8750
  if (!nameHoldsCredential(prefix + name)) return false;
8344
8751
  return looksGenerated(value, 12, 3.5);
8345
8752
  }
8753
+ var BASIC_VALUE_RE = /([A-Za-z0-9+/]{8,512}={0,2})$/;
8754
+ var BASIC_PAIR_RE = /^([^:\s]{1,128}):(\S{8,256})$/;
8755
+ function validateBasicCredential(raw) {
8756
+ const b64 = capturedValue(raw, BASIC_VALUE_RE);
8757
+ if (b64 === null) return false;
8758
+ const bare = b64.replace(/=+$/, "");
8759
+ if (bare.length % 4 === 1) return false;
8760
+ const bytes = Buffer.from(b64, "base64");
8761
+ if (bytes.toString("base64").replace(/=+$/, "") !== bare) return false;
8762
+ const text = bytes.toString("utf8");
8763
+ if (!Buffer.from(text, "utf8").equals(bytes)) return false;
8764
+ for (let i = 0; i < text.length; i++) {
8765
+ const c = text.charCodeAt(i);
8766
+ if (c < 32 || c === 127) return false;
8767
+ }
8768
+ const pair = BASIC_PAIR_RE.exec(text);
8769
+ if (!pair) return false;
8770
+ const password = pair[2];
8771
+ if (!/[0-9]/.test(password) || !/[A-Za-z]/.test(password)) return false;
8772
+ const lower2 = password.toLowerCase();
8773
+ if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || hasSequentialRun(password)) return false;
8774
+ return shannonEntropy(password) >= 3;
8775
+ }
8776
+ var OTP_CAPTURE_RE = /["']([A-Z2-7]{16,128}=*)["']$/i;
8777
+ function validateOtpSecret(raw) {
8778
+ const secret = capturedValue(raw, OTP_CAPTURE_RE);
8779
+ if (secret === null || isOtpDocSecret(secret)) return false;
8780
+ return looksGenerated(secret.replace(/=+$/, ""), 16, 3, true);
8781
+ }
8346
8782
  var DLP_PATTERNS = [
8347
8783
  // ── AWS ───────────────────────────────────────────────────────────────────
8348
8784
  {
@@ -8680,6 +9116,22 @@ var DLP_PATTERNS = [
8680
9116
  contextBoost: true,
8681
9117
  minEntropy: 3
8682
9118
  },
9119
+ // ── HTTP Basic credential ─────────────────────────────────────────────────
9120
+ // `Authorization: Basic <base64 of user:password>`, or the bare scheme in a
9121
+ // config list. The validator decodes the value and accepts only a
9122
+ // `user:password` whose password looks generated (letters and digits, 8+
9123
+ // characters, the query-credential rule), so prose ("Basic authentication")
9124
+ // and documentation pairs (`admin:changeme`, `user:pass1234`) stay allowed.
9125
+ // review: the same weight as a bare Bearer token.
9126
+ {
9127
+ name: "HTTP Basic Credential",
9128
+ regex: /\bBasic[ \t]{1,8}([A-Za-z0-9+/]{8,512}={0,2})/i,
9129
+ severity: "review",
9130
+ keywords: ["basic"],
9131
+ validate: validateBasicCredential,
9132
+ redactGroup: 1,
9133
+ argumentsOnly: true
9134
+ },
8683
9135
  // ── Resend ────────────────────────────────────────────────────────────────
8684
9136
  {
8685
9137
  name: "Resend API Key",
@@ -8821,6 +9273,19 @@ var DLP_PATTERNS = [
8821
9273
  validate: validateQueryCredential,
8822
9274
  argumentsOnly: true
8823
9275
  },
9276
+ // ── OTP secret in a constructor ───────────────────────────────────────────
9277
+ // `ROTP::TOTP.new('<base32>')`, `pyotp.TOTP("<base32>")`, `new HOTP('...')`:
9278
+ // the shared secret of a one-time-password generator written as a literal.
9279
+ // The otpauth URI form is `Credential in URL Query`. review.
9280
+ {
9281
+ name: "OTP Secret",
9282
+ regex: /\b(?:TOTP|HOTP|OTP)(?:\.new|\.create)?[ \t]{0,8}\(?[ \t]{0,8}["']([A-Z2-7]{16,128}=*)["']/i,
9283
+ severity: "review",
9284
+ keywords: ["otp"],
9285
+ validate: validateOtpSecret,
9286
+ redactGroup: 1,
9287
+ argumentsOnly: true
9288
+ },
8824
9289
  // ── Secret assigned to a telling name ─────────────────────────────────────
8825
9290
  // `password: ...`, `JWT_SECRET=...`, `api_key = "..."`. The name alone is
8826
9291
  // not a finding: most such lines hold a reference (`process.env.X`), a
@@ -8828,12 +9293,14 @@ var DLP_PATTERNS = [
8828
9293
  // generated: 12+ characters, not an identifier, Shannon entropy of 3.5
8829
9294
  // bits per character or more. review, never block (node9Firewall#348,
8830
9295
  // item 4). Tuned on CredData's public split; its look-alike lines are the
8831
- // negative control.
9296
+ // negative control. A quote may be escaped (`\"access_token\":\"...\"`):
9297
+ // JSON written inside a string literal. The two optional quotes after the
9298
+ // name are written out, not as a counted group, to keep star height 1.
8832
9299
  {
8833
9300
  name: "Assigned Secret",
8834
- 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,
9301
+ 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,
8835
9302
  severity: "review",
8836
- keywords: ["password", "passphrase", "passwd", "pwd", "secret", "token", "key"],
9303
+ keywords: ["pass", "pwd", "secret", "token", "key", "ticket"],
8837
9304
  validate: validateAssignedSecret,
8838
9305
  argumentsOnly: true
8839
9306
  }
@@ -9412,10 +9879,322 @@ function parsePySpec(raw) {
9412
9879
  const exact = PY_EXACT_RE.exec(m[2].trim());
9413
9880
  return { name, version: exact ? exact[1] : void 0 };
9414
9881
  }
9882
+ var EXACT_VERSION_RE = /^=?v?(\d+(?:\.\d+)*(?:[-+][0-9A-Za-z][0-9A-Za-z.+-]*)?)$/;
9883
+ function exactVersion(v) {
9884
+ if (!v) return void 0;
9885
+ const m = EXACT_VERSION_RE.exec(v.trim());
9886
+ return m ? m[1] : void 0;
9887
+ }
9888
+ function push(out, ecosystem, manager, name, version, raw) {
9889
+ out.push({ ecosystem, manager, name, ...version ? { version } : {}, raw });
9890
+ }
9891
+ var GEM_NAME_RE = /^[\p{L}\p{N}][\p{L}\p{N}_.-]*$/u;
9892
+ var GEM_VALUE_FLAGS = /* @__PURE__ */ new Set([
9893
+ "-v",
9894
+ "--version",
9895
+ "-i",
9896
+ "--install-dir",
9897
+ "-n",
9898
+ "--bindir",
9899
+ "--document",
9900
+ "--build-root",
9901
+ "-P",
9902
+ "--trust-policy",
9903
+ "-s",
9904
+ "--source",
9905
+ "-p",
9906
+ "--http-proxy",
9907
+ "--platform",
9908
+ "-g",
9909
+ "--file",
9910
+ "--without"
9911
+ ]);
9912
+ var BUNDLE_VALUE_FLAGS = /* @__PURE__ */ new Set([
9913
+ "-v",
9914
+ "--version",
9915
+ "-g",
9916
+ "--group",
9917
+ "-s",
9918
+ "--source",
9919
+ "-r",
9920
+ "--require",
9921
+ "--path",
9922
+ "--git",
9923
+ "--github",
9924
+ "--branch",
9925
+ "--ref",
9926
+ "--glob"
9927
+ ]);
9928
+ function gemInstall(words, from, out) {
9929
+ const dash = words.indexOf("--", from);
9930
+ const own = dash < 0 ? words : words.slice(0, dash);
9931
+ const pinned = exactVersion(flagValues(own, from, ["-v", "--version"])[0]);
9932
+ for (const raw of operands(own, from, GEM_VALUE_FLAGS)) {
9933
+ if (NON_REGISTRY_RE.test(raw) || /\.gem$/i.test(raw)) continue;
9934
+ const colon = raw.indexOf(":");
9935
+ const name = colon < 0 ? raw : raw.slice(0, colon);
9936
+ if (!GEM_NAME_RE.test(name)) continue;
9937
+ push(
9938
+ out,
9939
+ "RubyGems",
9940
+ "gem",
9941
+ name,
9942
+ colon < 0 ? pinned : exactVersion(raw.slice(colon + 1)),
9943
+ raw
9944
+ );
9945
+ }
9946
+ }
9947
+ var CRATE_NAME_RE = /^[\p{L}\p{N}][\p{L}\p{N}_-]*$/u;
9948
+ var CARGO_ADD_VALUE_FLAGS = /* @__PURE__ */ new Set([
9949
+ "-F",
9950
+ "--features",
9951
+ "--rename",
9952
+ "--registry",
9953
+ "--manifest-path",
9954
+ "-p",
9955
+ "--package",
9956
+ "--git",
9957
+ "--branch",
9958
+ "--tag",
9959
+ "--rev",
9960
+ "--path",
9961
+ "--base",
9962
+ "--target",
9963
+ "--color",
9964
+ "--config",
9965
+ "-Z",
9966
+ "--lockfile-path"
9967
+ ]);
9968
+ var CARGO_INSTALL_VALUE_FLAGS = /* @__PURE__ */ new Set([
9969
+ "--version",
9970
+ "--vers",
9971
+ "--git",
9972
+ "--branch",
9973
+ "--tag",
9974
+ "--rev",
9975
+ "--path",
9976
+ "--root",
9977
+ "--index",
9978
+ "--registry",
9979
+ "-F",
9980
+ "--features",
9981
+ "--profile",
9982
+ "--target",
9983
+ "--target-dir",
9984
+ "-j",
9985
+ "--jobs",
9986
+ "--bin",
9987
+ "--example",
9988
+ "--color",
9989
+ "--config",
9990
+ "-Z"
9991
+ ]);
9992
+ function cargoCrates(words, from, manager, out) {
9993
+ const flags = manager === "cargo add" ? CARGO_ADD_VALUE_FLAGS : CARGO_INSTALL_VALUE_FLAGS;
9994
+ if (flagValues(words, from, ["--git", "--path", "--registry", "--index"]).length > 0) return;
9995
+ if (words.some((w) => w === "--git" || w === "--path")) return;
9996
+ const flagVersion = manager === "cargo install" ? exactVersion(flagValues(words, from, ["--version", "--vers"])[0]) : void 0;
9997
+ for (const raw of operands(words, from, flags)) {
9998
+ const at = raw.indexOf("@");
9999
+ const name = at < 0 ? raw : raw.slice(0, at);
10000
+ if (!CRATE_NAME_RE.test(name)) continue;
10001
+ push(
10002
+ out,
10003
+ "crates.io",
10004
+ manager,
10005
+ name,
10006
+ at < 0 ? flagVersion : exactVersion(raw.slice(at + 1)),
10007
+ raw
10008
+ );
10009
+ }
10010
+ }
10011
+ var GO_VALUE_FLAGS = /* @__PURE__ */ new Set([
10012
+ "-C",
10013
+ "-tags",
10014
+ "-ldflags",
10015
+ "-gcflags",
10016
+ "-asmflags",
10017
+ "-mod",
10018
+ "-modfile",
10019
+ "-o",
10020
+ "-p",
10021
+ "-pkgdir",
10022
+ "-toolexec",
10023
+ "-exec",
10024
+ "-overlay",
10025
+ "-pgo",
10026
+ "-buildmode",
10027
+ "-compiler",
10028
+ "-gccgoflags",
10029
+ "-installsuffix",
10030
+ "-covermode",
10031
+ "-coverpkg"
10032
+ ]);
10033
+ var GO_PATH_RE = /^[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)+(?:\/[\p{L}\p{N}_.~+-]+)*$/u;
10034
+ function goModules(words, from, manager, out) {
10035
+ let specs = operands(words, from, GO_VALUE_FLAGS);
10036
+ if (manager === "go run") specs = specs.slice(0, 1).filter((s) => s.includes("@"));
10037
+ for (const raw of specs) {
10038
+ const at = raw.indexOf("@");
10039
+ const pathPart = (at < 0 ? raw : raw.slice(0, at)).replace(/\/\.\.\.$/, "");
10040
+ const ver = at < 0 ? void 0 : raw.slice(at + 1);
10041
+ if (ver === "none") continue;
10042
+ if (!GO_PATH_RE.test(pathPart) || /\.go$/i.test(pathPart)) continue;
10043
+ const exact = ver && /^v\d/.test(ver) ? exactVersion(ver) : void 0;
10044
+ push(out, "Go", manager, pathPart, exact, raw);
10045
+ }
10046
+ }
10047
+ var NUGET_NAME_RE = /^[\p{L}\p{N}_][\p{L}\p{N}_.-]*$/u;
10048
+ var DOTNET_ADD_VALUE_FLAGS = /* @__PURE__ */ new Set([
10049
+ "-v",
10050
+ "--version",
10051
+ "-s",
10052
+ "--source",
10053
+ "-f",
10054
+ "--framework",
10055
+ "--package-directory"
10056
+ ]);
10057
+ var DOTNET_TOOL_VALUE_FLAGS = /* @__PURE__ */ new Set([
10058
+ "--version",
10059
+ "--add-source",
10060
+ "--configfile",
10061
+ "--framework",
10062
+ "--tool-path",
10063
+ "-a",
10064
+ "--arch",
10065
+ "--tool-manifest",
10066
+ "-v",
10067
+ "--verbosity"
10068
+ ]);
10069
+ var NUGET_VALUE_FLAGS = /* @__PURE__ */ new Set([
10070
+ "-version",
10071
+ "-outputdirectory",
10072
+ "-o",
10073
+ "-source",
10074
+ "-configfile",
10075
+ "-fallbacksource",
10076
+ "-framework",
10077
+ "-packagesavemode",
10078
+ "-dependencyversion",
10079
+ "-solutiondirectory",
10080
+ "-verbosity"
10081
+ ]);
10082
+ function dotnetAdd(words, from, out) {
10083
+ let k = -1;
10084
+ for (let i = from; i < Math.min(words.length, from + 2); i++) {
10085
+ if (lower(words[i]) === "package") {
10086
+ k = i;
10087
+ break;
10088
+ }
10089
+ }
10090
+ if (k < 0) return;
10091
+ const name = operands(words, k + 1, DOTNET_ADD_VALUE_FLAGS)[0];
10092
+ if (!name || !NUGET_NAME_RE.test(name)) return;
10093
+ const version = exactVersion(flagValues(words, k + 1, ["-v", "--version"])[0]);
10094
+ push(out, "NuGet", "dotnet add package", name, version, name);
10095
+ }
10096
+ function dotnetTool(words, from, out) {
10097
+ const name = operands(words, from, DOTNET_TOOL_VALUE_FLAGS)[0];
10098
+ if (!name || !NUGET_NAME_RE.test(name)) return;
10099
+ const version = exactVersion(flagValues(words, from, ["--version"])[0]);
10100
+ push(out, "NuGet", "dotnet tool", name, version, name);
10101
+ }
10102
+ function nugetInstall(words, from, out) {
10103
+ const lowered = words.map((w) => w !== null && w.startsWith("-") ? w.toLowerCase() : w);
10104
+ const name = operands(lowered, from, NUGET_VALUE_FLAGS)[0];
10105
+ if (!name || !NUGET_NAME_RE.test(name) || /\.config$/i.test(name)) return;
10106
+ const version = exactVersion(flagValues(lowered, from, ["-version"])[0]);
10107
+ push(out, "NuGet", "nuget install", name, version, name);
10108
+ }
10109
+ var MAVEN_COORD_RE = /^[\p{L}\p{N}_.-]+:[\p{L}\p{N}_.-]+$/u;
10110
+ function mavenGet(words, from, out) {
10111
+ const goal = words.slice(from).some(
10112
+ (w) => w !== null && /(?:^|:)dependency:get$|^org\.apache\.maven\.plugins:maven-dependency-plugin:(?:[\w.-]+:)?get$/.test(
10113
+ w
10114
+ )
10115
+ );
10116
+ if (!goal) return;
10117
+ const prop = (key) => {
10118
+ for (let i = from; i < words.length; i++) {
10119
+ const w = words[i];
10120
+ if (w === null) continue;
10121
+ if (w.startsWith(`-D${key}=`)) return w.slice(key.length + 3);
10122
+ if (w === "-D" && words[i + 1]?.startsWith(`${key}=`))
10123
+ return words[i + 1].slice(key.length + 1);
10124
+ }
10125
+ return void 0;
10126
+ };
10127
+ const artifact = prop("artifact");
10128
+ let coord;
10129
+ let ver;
10130
+ if (artifact) {
10131
+ const parts = artifact.split(":");
10132
+ if (parts.length < 2) return;
10133
+ coord = `${parts[0]}:${parts[1]}`;
10134
+ ver = parts[2];
10135
+ } else {
10136
+ const g = prop("groupId");
10137
+ const a = prop("artifactId");
10138
+ if (!g || !a) return;
10139
+ coord = `${g}:${a}`;
10140
+ ver = prop("version");
10141
+ }
10142
+ if (!MAVEN_COORD_RE.test(coord)) return;
10143
+ const exact = ver && !/^(?:LATEST|RELEASE)$/i.test(ver) ? exactVersion(ver) : void 0;
10144
+ push(out, "Maven", "mvn dependency:get", coord, exact, artifact ?? coord);
10145
+ }
10146
+ var COMPOSER_NAME_RE = /^[\p{L}\p{N}][\p{L}\p{N}_.-]*\/[\p{L}\p{N}][\p{L}\p{N}_.-]*$/u;
10147
+ var COMPOSER_VALUE_FLAGS = /* @__PURE__ */ new Set([
10148
+ "-d",
10149
+ "--working-dir",
10150
+ "--stability",
10151
+ "--repository",
10152
+ "--add-repository"
10153
+ ]);
10154
+ function composerPackages(words, from, manager, out) {
10155
+ const ops = operands(words, from, COMPOSER_VALUE_FLAGS);
10156
+ const specs = manager === "composer create-project" ? ops.slice(0, 1) : ops;
10157
+ for (const raw of specs) {
10158
+ const sep = raw.search(/[:=]/);
10159
+ const name = sep < 0 ? raw : raw.slice(0, sep);
10160
+ if (!COMPOSER_NAME_RE.test(name)) continue;
10161
+ let ver = sep < 0 ? void 0 : raw.slice(sep + 1);
10162
+ if (manager === "composer create-project" && ver === void 0) ver = ops[2] ?? void 0;
10163
+ push(out, "Packagist", manager, name.toLowerCase(), exactVersion(ver), raw);
10164
+ }
10165
+ }
10166
+ var EDITOR_HEADS = ["code", "code-insiders", "codium", "vscodium", "cursor"];
10167
+ var EXTENSION_ID_RE = /^[\p{L}\p{N}][\p{L}\p{N}_-]*\.[\p{L}\p{N}][\p{L}\p{N}_.-]*$/u;
10168
+ function editorExtensions(words, from, out) {
10169
+ for (const raw of flagValues(words, from, ["--install-extension"])) {
10170
+ if (/\.vsix$/i.test(raw) || NON_REGISTRY_RE.test(raw)) continue;
10171
+ const at = raw.lastIndexOf("@");
10172
+ const name = at <= 0 ? raw : raw.slice(0, at);
10173
+ if (!EXTENSION_ID_RE.test(name)) continue;
10174
+ push(
10175
+ out,
10176
+ "VSCode",
10177
+ "code --install-extension",
10178
+ name,
10179
+ at <= 0 ? void 0 : exactVersion(raw.slice(at + 1)),
10180
+ raw
10181
+ );
10182
+ }
10183
+ }
9415
10184
  function basename(w) {
9416
10185
  return (w ?? "").toLowerCase().split("/").pop() ?? "";
9417
10186
  }
9418
10187
  var MANAGER_HEADS = /* @__PURE__ */ new Set([
10188
+ "gem",
10189
+ "bundle",
10190
+ "cargo",
10191
+ "go",
10192
+ "dotnet",
10193
+ "nuget",
10194
+ "mvn",
10195
+ "mvnw",
10196
+ "composer",
10197
+ ...EDITOR_HEADS,
9419
10198
  "npm",
9420
10199
  "npx",
9421
10200
  "pnpm",
@@ -9664,7 +10443,63 @@ function fromCall(words, out, depth) {
9664
10443
  pushPy(out, "pipenv", operands(words, v + 1, PIPENV_VALUE_FLAGS));
9665
10444
  return;
9666
10445
  }
10446
+ case "gem": {
10447
+ const v = verbIndex(words, start + 1, GEM_VALUE_FLAGS);
10448
+ if (v >= 0 && ["install", "i"].includes(lower(words[v]))) gemInstall(words, v + 1, out);
10449
+ return;
10450
+ }
10451
+ case "bundle": {
10452
+ const v = verbIndex(words, start + 1, BUNDLE_VALUE_FLAGS);
10453
+ if (v < 0 || lower(words[v]) !== "add") return;
10454
+ if (flagValues(words, v + 1, ["--git", "--github", "--path"]).length > 0) return;
10455
+ const version = exactVersion(flagValues(words, v + 1, ["-v", "--version"])[0]);
10456
+ for (const raw of operands(words, v + 1, BUNDLE_VALUE_FLAGS))
10457
+ if (GEM_NAME_RE.test(raw)) push(out, "RubyGems", "bundle add", raw, version, raw);
10458
+ return;
10459
+ }
10460
+ case "cargo": {
10461
+ const from = words[start + 1]?.startsWith("+") ? start + 2 : start + 1;
10462
+ const v = verbIndex(words, from, CARGO_ADD_VALUE_FLAGS);
10463
+ const verb = lower(words[v]);
10464
+ if (verb === "add") cargoCrates(words, v + 1, "cargo add", out);
10465
+ else if (verb === "install") cargoCrates(words, v + 1, "cargo install", out);
10466
+ return;
10467
+ }
10468
+ case "go": {
10469
+ const v = verbIndex(words, start + 1, GO_VALUE_FLAGS);
10470
+ const verb = lower(words[v]);
10471
+ if (verb === "get" || verb === "install" || verb === "run")
10472
+ goModules(words, v + 1, `go ${verb}`, out);
10473
+ return;
10474
+ }
10475
+ case "dotnet": {
10476
+ const v = verbIndex(words, start + 1, DOTNET_ADD_VALUE_FLAGS);
10477
+ const verb = lower(words[v]);
10478
+ if (verb === "add") dotnetAdd(words, v + 1, out);
10479
+ else if (verb === "tool" && ["install", "update"].includes(lower(words[v + 1])))
10480
+ dotnetTool(words, v + 2, out);
10481
+ return;
10482
+ }
10483
+ case "nuget": {
10484
+ if (lower(words[start + 1]) === "install") nugetInstall(words, start + 2, out);
10485
+ return;
10486
+ }
10487
+ case "mvn":
10488
+ case "mvnw":
10489
+ mavenGet(words, start + 1, out);
10490
+ return;
10491
+ case "composer": {
10492
+ let v = verbIndex(words, start + 1, COMPOSER_VALUE_FLAGS);
10493
+ if (v >= 0 && lower(words[v]) === "global") v = verbIndex(words, v + 1, COMPOSER_VALUE_FLAGS);
10494
+ const verb = lower(words[v]);
10495
+ if (verb === "require" || verb === "req" || verb === "r")
10496
+ composerPackages(words, v + 1, "composer require", out);
10497
+ else if (verb === "create-project")
10498
+ composerPackages(words, v + 1, "composer create-project", out);
10499
+ return;
10500
+ }
9667
10501
  default:
10502
+ if (EDITOR_HEADS.includes(family)) editorExtensions(words, start + 1, out);
9668
10503
  return;
9669
10504
  }
9670
10505
  }
@@ -9969,6 +10804,7 @@ function checkToLegacyPolicy(policy, id, v) {
9969
10804
  var MAP_GOVERNED = /* @__PURE__ */ new Set([
9970
10805
  "files.shell-startup",
9971
10806
  "files.password-hashes",
10807
+ "files.system-dirs",
9972
10808
  "commands.inline-exec",
9973
10809
  "commands.eval-dynamic",
9974
10810
  "commands.curl-pipe-shell",
@@ -11586,18 +12422,17 @@ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
11586
12422
  }
11587
12423
  return out;
11588
12424
  }
11589
- var NUMBER_LEAD_RE = /[\s:=;([{"'+-]/;
11590
12425
  function isDecimalFraction(text, index, unseparated) {
11591
12426
  if (!unseparated) return false;
11592
12427
  const sep = text[index - 1];
11593
12428
  const a = text[index - 2];
11594
12429
  if (sep === ".") {
11595
12430
  if (a !== void 0 && a >= "0" && a <= "9") return true;
11596
- return a === void 0 || NUMBER_LEAD_RE.test(a);
12431
+ return a === void 0 || (a === "-" || a === "+") && index === 2;
11597
12432
  }
11598
12433
  if (sep === "," && a === "0") {
11599
12434
  const b = text[index - 3];
11600
- return b === void 0 || NUMBER_LEAD_RE.test(b);
12435
+ return b === void 0 || b === ";";
11601
12436
  }
11602
12437
  return false;
11603
12438
  }
@@ -12765,8 +13600,8 @@ function matchCanaryArgs(args, values) {
12765
13600
 
12766
13601
  // src/scan/canonical.ts
12767
13602
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
12768
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
12769
- var CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
13603
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v28";
13604
+ var CANONICAL_EXTRACTOR_HASH = "11df698796585cbe";
12770
13605
  var DEDUPE_PREVIEW_LEN = 120;
12771
13606
  function extractCanonicalFindings(call, ctx) {
12772
13607
  const out = [];