cverdict-mcp 0.1.5 → 0.2.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.
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import process$1 from "node:process";
3
+ import { lstatSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
4
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
5
  // node_modules/@modelcontextprotocol/server/dist/chunk-vYduTEsO.mjs
4
6
  var __create = Object.create;
5
7
  var __defProp = Object.defineProperty;
@@ -194,7 +196,7 @@ function mergeDefs(...defs) {
194
196
  function esc(str) {
195
197
  return JSON.stringify(str);
196
198
  }
197
- function slugify(input) {
199
+ function slugify$1(input) {
198
200
  return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
199
201
  }
200
202
  var captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
@@ -3821,7 +3823,7 @@ function _toUpperCase() {
3821
3823
  }
3822
3824
  // @__NO_SIDE_EFFECTS__
3823
3825
  function _slugify() {
3824
- return /* @__PURE__ */ _overwrite((input) => slugify(input));
3826
+ return /* @__PURE__ */ _overwrite((input) => slugify$1(input));
3825
3827
  }
3826
3828
  // @__NO_SIDE_EFFECTS__
3827
3829
  function _array(Class, element, params) {
@@ -5006,12 +5008,12 @@ var initializer = (inst, issues) => {
5006
5008
  };
5007
5009
  var ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
5008
5010
  // node_modules/zod/v4/classic/parse.js
5009
- var parse$1 = /* @__PURE__ */ _parse(ZodRealError);
5011
+ var parse$2 = /* @__PURE__ */ _parse(ZodRealError);
5010
5012
  var parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
5011
5013
  var safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
5012
5014
  var safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
5013
5015
  var encode = /* @__PURE__ */ _encode(ZodRealError);
5014
- var decode = /* @__PURE__ */ _decode(ZodRealError);
5016
+ var decode$1 = /* @__PURE__ */ _decode(ZodRealError);
5015
5017
  var encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
5016
5018
  var decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
5017
5019
  var safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
@@ -5137,7 +5139,7 @@ var ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
5137
5139
  own(this, "~standard", value);
5138
5140
  },
5139
5141
  parse: function _parse(data, params) {
5140
- return parse$1(this, data, params, { callee: _parse });
5142
+ return parse$2(this, data, params, { callee: _parse });
5141
5143
  },
5142
5144
  parseAsync: async function _parseAsync(data, params) {
5143
5145
  return await parseAsync(this, data, params, { callee: _parseAsync });
@@ -5164,7 +5166,7 @@ var ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
5164
5166
  return encode(this, data, params, { callee: _encode });
5165
5167
  },
5166
5168
  decode: function _decode(data, params) {
5167
- return decode(this, data, params, { callee: _decode });
5169
+ return decode$1(this, data, params, { callee: _decode });
5168
5170
  },
5169
5171
  encodeAsync: async function _encodeAsync(data, params) {
5170
5172
  return await encodeAsync(this, data, params, { callee: _encodeAsync });
@@ -24126,7 +24128,7 @@ var MCP_SERVER = {
24126
24128
  name: `io.github.${BRAND.repo}`,
24127
24129
  title: BRAND.name,
24128
24130
  /** Same as mcp/package.json (checked by a test). */
24129
- version: "0.1.5",
24131
+ version: "0.2.0",
24130
24132
  /** npm package name: `npx -y cverdict-mcp`. */
24131
24133
  npm: `${BRAND.slug}-mcp`,
24132
24134
  /** Where the server is documented. */
@@ -24177,6 +24179,21 @@ var MCP_TOOLS = [
24177
24179
  name: "search_cves",
24178
24180
  title: "Search the 30-day window",
24179
24181
  description: "Find CVEs published in the last 30 days by words in the ID, CNA, vendor, product or title (all words must match), highest score first." + UNTRUSTED
24182
+ },
24183
+ {
24184
+ name: "check_inventory",
24185
+ title: "Check a list of vendors and products",
24186
+ description: "Which tracked CVEs hit a list of vendors or products (1 to 200 names, e.g. from an asset inventory): per name, the matching CVEs most urgent first (tier, then soonest CISA KEV due date, then score) with verdict, score and KEV due date, plus the Atom feed for the name's slug (it may also carry other spellings). A name must equal a CVE's vendor or product, ignoring case, as the site's watchlist matches; no_match: true flags a name with no tracked CVE (check the spelling, or try search_cves). omitted counts what was left out (per_name, or the size budget)." + UNTRUSTED
24187
+ },
24188
+ {
24189
+ name: "check_dependencies",
24190
+ title: "Check lockfiles and SBOMs",
24191
+ description: "Which of the project's dependencies have CVEs, most exploited first: reads the lockfiles and SBOMs (eight ecosystems) under paths inside the server's working directory, and matches every CVE an OSV.dev advisory ties to a package version, with tier, file, line and fixed version. Files stay local; only the public index is downloaded." + UNTRUSTED
24192
+ },
24193
+ {
24194
+ name: "changes_since",
24195
+ title: "What changed since a time",
24196
+ description: "Verdict events after since, newest first: CISA KEV and exploited-catalog listings, vendor exploitation notes, tier rises, fast-lane flags, first Metasploit, Nuclei or Exploit-DB entries. Tiers are at the default evidence bar. To page, pass the first page's next_since as until; to catch up later, pass it as since. The log keeps 7 days; an older since is an error that says where it starts. Filter by names (as check_inventory matches) and types." + UNTRUSTED
24180
24197
  }
24181
24198
  ];
24182
24199
  /** Plain-language verdict per tier, as in the README's tier table. */
@@ -24188,10 +24205,21 @@ var VERDICT = {
24188
24205
  };
24189
24206
  /** Messages the server answers with. Failures come back as tool results with isError: true. */
24190
24207
  var MCP_MSG = {
24208
+ /** check_dependencies: a path that is not inside the working directory, or not a lockfile or SBOM. */
24209
+ outsideRoot: (p) => `${p}: only paths inside the server's working directory can be checked.`,
24210
+ notCheckable: (p) => `${p}: not a lockfile or SBOM name this tool reads (see its description). Pass the folder that holds it instead.`,
24211
+ noDependencyFiles: (paths) => `No lockfile or SBOM found under ${paths}. Pass the folder or file to check, relative to the server's working directory.`,
24212
+ dependenciesCut: (shown, total) => `Showing the ${shown} most urgent of ${total} findings, to stay within the size budget; counts cover them all.`,
24213
+ olderMissing: (why) => `Older CVEs were not checked (${why}): only CVEs published in the last 30 days, in CISA KEV, listed as exploited or woken up.`,
24191
24214
  notFound: "Not in CVErdict's data: it was published before the 30-day window and is not in CISA KEV, ENISA EU KEV (as exploited), the CIRCL catalog (as exploited) or Woke Up, or it has no published record. That says nothing either way about the CVE.",
24192
24215
  notCveId: "Not a CVE ID. Expected CVE-YYYY-NNNN.",
24193
24216
  detailTooMany: (max) => `detail: true takes at most ${max} IDs; ask again in groups of ${max}.`,
24194
24217
  tooManyWords: (max) => `query takes at most ${max} words.`,
24218
+ inventoryCut: (shown, of) => `To keep this answer under about 17,000 tokens it shows the ${shown} most urgent of ${of} CVEs across all names; omitted counts what each name left out. For the rest, ask again with fewer names or with tiers.`,
24219
+ badName: (max) => `names: each name needs 1 to ${max} characters after trimming.`,
24220
+ oddName: "names: a name may not contain control or invisible characters.",
24221
+ namesTooLong: "names: these names are too long together for one answer; ask again with fewer names.",
24222
+ beforeLog: (from, to, days) => `since is older than the event log: events.json holds the ${days} days from ${from} to ${to}. Ask again with since on or after ${from}; for older changes use woke_up or get_verdict.`,
24195
24223
  badDate: (field) => `${field} must be a UTC date (2026-10-01) or date-time (2026-10-01T06:00Z).`,
24196
24224
  notPublished: (file) => file === "meta.json" ? `meta.json is not at the first data base that answered, so no tool can answer. Check CVERDICT_DATA_BASE, or read the files directly: ${BROWSE_DATA}` : `${file} is not on the data branch yet, so this tool has nothing to read. The other tools still work.`,
24197
24225
  schema: (found, expected) => `The published data uses schema version ${String(found)}; this server reads version ${expected}. Update the server: ${MCP_SERVER.docs}`,
@@ -24233,6 +24261,16 @@ var ROW_COLS = [
24233
24261
  "kd",
24234
24262
  "b"
24235
24263
  ];
24264
+ var EVENT_TYPES = [
24265
+ "kev_added",
24266
+ "catalog_listed",
24267
+ "vendor_exploited",
24268
+ "tier_up",
24269
+ "fast_lane",
24270
+ "metasploit_module",
24271
+ "nuclei_template",
24272
+ "exploitdb_entry"
24273
+ ];
24236
24274
  /** `catalog`: a first exploited listing in ENISA EU KEV or the CIRCL catalog (the eukev/circl E chips). */
24237
24275
  var WAKE_KINDS = [
24238
24276
  "kev",
@@ -24243,6 +24281,16 @@ var WAKE_KINDS = [
24243
24281
  "poc",
24244
24282
  "epss"
24245
24283
  ];
24284
+ var PACKAGE_ECOSYSTEMS = [
24285
+ "npm",
24286
+ "PyPI",
24287
+ "Maven",
24288
+ "Go",
24289
+ "crates.io",
24290
+ "RubyGems",
24291
+ "Packagist",
24292
+ "NuGet"
24293
+ ];
24246
24294
  /** Tier for a score at a given knob. Shared so the site and pipeline always agree. */
24247
24295
  function tierFor(score, exploited, weaponized, knob) {
24248
24296
  if (exploited) return "exploited";
@@ -24258,6 +24306,536 @@ function rowFromColumns(cols, values) {
24258
24306
  function rowsFromTable(table) {
24259
24307
  return table.rows.map((r) => rowFromColumns(table.cols, r));
24260
24308
  }
24309
+ var DIGITS = /^\d+$/;
24310
+ /** Numeric comparison of two digit strings of any length (leading zeros allowed). */
24311
+ function cmpDigits(a, b) {
24312
+ let i = 0;
24313
+ let j = 0;
24314
+ while (i < a.length - 1 && a[i] === "0") i++;
24315
+ while (j < b.length - 1 && b[j] === "0") j++;
24316
+ const la = a.length - i;
24317
+ const lb = b.length - j;
24318
+ if (la !== lb) return la < lb ? -1 : 1;
24319
+ for (; i < a.length; i++, j++) if (a[i] !== b[j]) return a[i] < b[j] ? -1 : 1;
24320
+ return 0;
24321
+ }
24322
+ var cmpText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
24323
+ /** Wrap a parser with the length cap and trimming every comparator shares. */
24324
+ function capped(parse) {
24325
+ return (v) => {
24326
+ if (typeof v !== "string" || v.length > 128) return null;
24327
+ const s = v.trim();
24328
+ return s === "" ? null : parse(s);
24329
+ };
24330
+ }
24331
+ /** SemVer 2.0 prerelease identifiers (null: a release). Numeric < alphanumeric; more identifiers win. */
24332
+ function cmpPrerelease(a, b) {
24333
+ if (!a || !b) return a ? -1 : b ? 1 : 0;
24334
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
24335
+ const x = a[i];
24336
+ const y = b[i];
24337
+ if (x === void 0) return -1;
24338
+ if (y === void 0) return 1;
24339
+ const xn = DIGITS.test(x);
24340
+ const yn = DIGITS.test(y);
24341
+ const c = xn && yn ? cmpDigits(x, y) : xn !== yn ? xn ? -1 : 1 : cmpText(x, y);
24342
+ if (c !== 0) return c;
24343
+ }
24344
+ return 0;
24345
+ }
24346
+ var SEMVER_RE = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
24347
+ var semver = {
24348
+ parse: capped((s) => {
24349
+ const m = SEMVER_RE.exec(s);
24350
+ return m ? {
24351
+ n: [
24352
+ m[1],
24353
+ m[2],
24354
+ m[3]
24355
+ ],
24356
+ pre: m[4] ? m[4].split(".") : null
24357
+ } : null;
24358
+ }),
24359
+ cmp(a, b) {
24360
+ for (let i = 0; i < 3; i++) {
24361
+ const c = cmpDigits(a.n[i], b.n[i]);
24362
+ if (c !== 0) return c;
24363
+ }
24364
+ return cmpPrerelease(a.pre, b.pre);
24365
+ }
24366
+ };
24367
+ var PEP440_RE = /^v?(?:(\d+)!)?(\d+(?:\.\d+)*)(?:[-_.]?(alpha|beta|preview|pre|rc|a|b|c)[-_.]?(\d+)?)?(?:-(\d+)|[-_.]?(post|rev|r)[-_.]?(\d+)?)?(?:[-_.]?(dev)[-_.]?(\d+)?)?(?:\+([a-z0-9]+(?:[-_.][a-z0-9]+)*))?$/i;
24368
+ var PRE_RANK = {
24369
+ a: 0,
24370
+ alpha: 0,
24371
+ b: 1,
24372
+ beta: 1,
24373
+ c: 2,
24374
+ rc: 2,
24375
+ pre: 2,
24376
+ preview: 2
24377
+ };
24378
+ /** Rank of the pre-release part: a dev-only release sorts first, then pre-releases, then none. */
24379
+ function pepPreKey(k) {
24380
+ if (k.pre) return [
24381
+ 1,
24382
+ k.pre[0],
24383
+ k.pre[1]
24384
+ ];
24385
+ return k.post === null && k.dev !== null ? [
24386
+ 0,
24387
+ 0,
24388
+ "0"
24389
+ ] : [
24390
+ 2,
24391
+ 0,
24392
+ "0"
24393
+ ];
24394
+ }
24395
+ var pep440 = {
24396
+ parse: capped((s) => {
24397
+ const m = PEP440_RE.exec(s);
24398
+ if (!m) return null;
24399
+ const release = m[2].split(".");
24400
+ while (release.length > 1 && /^0+$/.test(release[release.length - 1])) release.pop();
24401
+ return {
24402
+ epoch: m[1] ?? "0",
24403
+ release,
24404
+ pre: m[3] ? [PRE_RANK[m[3].toLowerCase()], m[4] ?? "0"] : null,
24405
+ post: m[5] !== void 0 ? m[5] : m[6] ? m[7] ?? "0" : null,
24406
+ dev: m[8] ? m[9] ?? "0" : null,
24407
+ local: m[10] ? m[10].toLowerCase().split(/[-_.]/) : null
24408
+ };
24409
+ }),
24410
+ cmp(a, b) {
24411
+ let c = cmpDigits(a.epoch, b.epoch);
24412
+ if (c !== 0) return c;
24413
+ for (let i = 0; i < Math.max(a.release.length, b.release.length); i++) {
24414
+ c = cmpDigits(a.release[i] ?? "0", b.release[i] ?? "0");
24415
+ if (c !== 0) return c;
24416
+ }
24417
+ const pa = pepPreKey(a);
24418
+ const pb = pepPreKey(b);
24419
+ c = pa[0] - pb[0] || pa[1] - pb[1] || cmpDigits(pa[2], pb[2]);
24420
+ if (c !== 0) return c;
24421
+ if (a.post === null !== (b.post === null)) return a.post === null ? -1 : 1;
24422
+ if (a.post !== null && b.post !== null) {
24423
+ c = cmpDigits(a.post, b.post);
24424
+ if (c !== 0) return c;
24425
+ }
24426
+ if (a.dev === null !== (b.dev === null)) return a.dev === null ? 1 : -1;
24427
+ if (a.dev !== null && b.dev !== null) {
24428
+ c = cmpDigits(a.dev, b.dev);
24429
+ if (c !== 0) return c;
24430
+ }
24431
+ if (a.local === null !== (b.local === null)) return a.local === null ? -1 : 1;
24432
+ if (a.local && b.local) for (let i = 0; i < Math.max(a.local.length, b.local.length); i++) {
24433
+ const x = a.local[i];
24434
+ const y = b.local[i];
24435
+ if (x === void 0) return -1;
24436
+ if (y === void 0) return 1;
24437
+ const xn = DIGITS.test(x);
24438
+ const yn = DIGITS.test(y);
24439
+ c = xn && yn ? cmpDigits(x, y) : xn !== yn ? xn ? 1 : -1 : cmpText(x, y);
24440
+ if (c !== 0) return c;
24441
+ }
24442
+ return 0;
24443
+ }
24444
+ };
24445
+ var GEM_RE = /^[0-9]+(?:\.[0-9a-zA-Z]+)*(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
24446
+ var isNumSeg = (s) => s.charCodeAt(0) >= 48 && s.charCodeAt(0) <= 57;
24447
+ var rubygems = {
24448
+ parse: capped((s) => {
24449
+ if (!GEM_RE.test(s)) return null;
24450
+ const segs = s.replace(/-/g, ".pre.").match(/[0-9]+|[a-z]+/gi) ?? [];
24451
+ let split = segs.findIndex((x) => !isNumSeg(x));
24452
+ if (split < 0) split = segs.length;
24453
+ const trim = (xs) => {
24454
+ while (xs.length > 0 && isNumSeg(xs[xs.length - 1]) && /^0+$/.test(xs[xs.length - 1])) xs.pop();
24455
+ return xs;
24456
+ };
24457
+ return [...trim(segs.slice(0, split)), ...trim(segs.slice(split))];
24458
+ }),
24459
+ cmp(a, b) {
24460
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
24461
+ const x = a[i] ?? "0";
24462
+ const y = b[i] ?? "0";
24463
+ const xn = isNumSeg(x);
24464
+ const yn = isNumSeg(y);
24465
+ if (xn && yn) {
24466
+ const c = cmpDigits(x, y);
24467
+ if (c !== 0) return c;
24468
+ } else if (xn !== yn) return xn ? 1 : -1;
24469
+ else if (x !== y) return x < y ? -1 : 1;
24470
+ }
24471
+ return 0;
24472
+ }
24473
+ };
24474
+ var NUGET_RE = /^v?(\d+(?:\.\d+){0,3})(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
24475
+ var nuget = {
24476
+ parse: capped((s) => {
24477
+ const m = NUGET_RE.exec(s);
24478
+ if (!m) return null;
24479
+ const parts = m[1].split(".");
24480
+ while (parts.length < 4) parts.push("0");
24481
+ return {
24482
+ n: parts,
24483
+ pre: m[2] ? m[2].toLowerCase().split(".") : null
24484
+ };
24485
+ }),
24486
+ cmp(a, b) {
24487
+ for (let i = 0; i < 4; i++) {
24488
+ const c = cmpDigits(a.n[i], b.n[i]);
24489
+ if (c !== 0) return c;
24490
+ }
24491
+ return cmpPrerelease(a.pre, b.pre);
24492
+ }
24493
+ };
24494
+ /** Known qualifiers in order; "" is the release. Unknown qualifiers sort after all of them. */
24495
+ var MAVEN_QUALIFIERS = [
24496
+ "alpha",
24497
+ "beta",
24498
+ "milestone",
24499
+ "rc",
24500
+ "snapshot",
24501
+ "",
24502
+ "sp"
24503
+ ];
24504
+ var MAVEN_ALIASES = {
24505
+ ga: "",
24506
+ final: "",
24507
+ release: "",
24508
+ cr: "rc"
24509
+ };
24510
+ var MAVEN_SHORT = {
24511
+ a: "alpha",
24512
+ b: "beta",
24513
+ m: "milestone"
24514
+ };
24515
+ function mavenQualifier(q) {
24516
+ return Object.hasOwn(MAVEN_ALIASES, q) ? MAVEN_ALIASES[q] : q;
24517
+ }
24518
+ function cmpQualifier(a, b) {
24519
+ const ia = MAVEN_QUALIFIERS.indexOf(a);
24520
+ const ib = MAVEN_QUALIFIERS.indexOf(b);
24521
+ if (ia >= 0 && ib >= 0) return ia - ib;
24522
+ if (ia >= 0 || ib >= 0) return ia >= 0 ? -1 : 1;
24523
+ return cmpText(a, b);
24524
+ }
24525
+ var isMavenNull = (t) => t.num !== null ? /^0+$/.test(t.num) : t.qual === "";
24526
+ /** Qualifier < "-" number < "." number; numbers by value, qualifiers by the known order. */
24527
+ function cmpMavenToken(a, b) {
24528
+ if (a.num === null && b.num === null) return cmpQualifier(a.qual, b.qual);
24529
+ if (a.num === null || b.num === null) return a.num === null ? -1 : 1;
24530
+ if (a.sep !== b.sep) return a.sep === "-" ? -1 : 1;
24531
+ return cmpDigits(a.num, b.num);
24532
+ }
24533
+ /**
24534
+ * A token compared with nothing (the shorter version ran out): a number with 0, a qualifier with
24535
+ * the release qualifier "", whatever the separator. So "7.2.2.v20101205" is above "7.2.2" and
24536
+ * "1-SNAPSHOT" below "1", as Maven and OSV.dev order them.
24537
+ */
24538
+ function cmpMavenToNull(t) {
24539
+ return t.num !== null ? /^0+$/.test(t.num) ? 0 : 1 : cmpQualifier(t.qual, "");
24540
+ }
24541
+ var maven = {
24542
+ parse: capped((raw) => {
24543
+ if (/\s/.test(raw)) return null;
24544
+ const s = raw.toLowerCase();
24545
+ const tokens = [];
24546
+ let sep = ".";
24547
+ let start = 0;
24548
+ const push = (end, nextSep, followedByDigit) => {
24549
+ const text = s.slice(start, end);
24550
+ if (text === "") tokens.push({
24551
+ sep,
24552
+ num: "0",
24553
+ qual: ""
24554
+ });
24555
+ else if (/^\d/.test(text)) tokens.push({
24556
+ sep,
24557
+ num: text,
24558
+ qual: ""
24559
+ });
24560
+ else {
24561
+ const q = followedByDigit && Object.hasOwn(MAVEN_SHORT, text) ? MAVEN_SHORT[text] : text;
24562
+ tokens.push({
24563
+ sep,
24564
+ num: null,
24565
+ qual: mavenQualifier(q)
24566
+ });
24567
+ }
24568
+ sep = nextSep;
24569
+ };
24570
+ for (let i = 0; i < s.length; i++) {
24571
+ const ch = s[i];
24572
+ if (ch === "." || ch === "-") {
24573
+ push(i, ch, false);
24574
+ start = i + 1;
24575
+ } else if (i > start) {
24576
+ const digit = ch >= "0" && ch <= "9";
24577
+ if (digit !== (s[i - 1] >= "0" && s[i - 1] <= "9")) {
24578
+ push(i, "-", digit);
24579
+ start = i;
24580
+ }
24581
+ }
24582
+ }
24583
+ if (start < s.length) push(s.length, ".", false);
24584
+ else if (s.length > 0 && (s.endsWith(".") || s.endsWith("-"))) push(s.length, ".", false);
24585
+ let i = tokens.length - 1;
24586
+ while (i > 0) {
24587
+ if (isMavenNull(tokens[i])) {
24588
+ tokens.splice(i, 1);
24589
+ i--;
24590
+ continue;
24591
+ }
24592
+ while (i >= 0 && tokens[i].sep !== "-") i--;
24593
+ i--;
24594
+ }
24595
+ return tokens;
24596
+ }),
24597
+ cmp(a, b) {
24598
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
24599
+ const c = i >= a.length ? -cmpMavenToNull(b[i]) : i >= b.length ? cmpMavenToNull(a[i]) : cmpMavenToken(a[i], b[i]);
24600
+ if (c !== 0) return c;
24601
+ }
24602
+ return 0;
24603
+ }
24604
+ };
24605
+ var COMPOSER_RE = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:[._-]?(stable|beta|b|rc|alpha|a|patch|pl|p)(\d*(?:[.-]\d+)*))?([._-]?dev)?$/;
24606
+ var COMPOSER_STABILITY = {
24607
+ alpha: 1,
24608
+ a: 1,
24609
+ beta: 2,
24610
+ b: 2,
24611
+ rc: 3,
24612
+ stable: 4,
24613
+ patch: 5,
24614
+ pl: 5,
24615
+ p: 5
24616
+ };
24617
+ var COMPARATORS = {
24618
+ npm: semver,
24619
+ "crates.io": semver,
24620
+ Go: semver,
24621
+ PyPI: pep440,
24622
+ RubyGems: rubygems,
24623
+ NuGet: nuget,
24624
+ Maven: maven,
24625
+ Packagist: {
24626
+ parse: capped((raw) => {
24627
+ const m = COMPOSER_RE.exec(raw.toLowerCase());
24628
+ if (!m) return null;
24629
+ const dev = m[7] !== void 0;
24630
+ const stability = m[5] ? COMPOSER_STABILITY[m[5]] : dev ? 0 : 4;
24631
+ return {
24632
+ n: [
24633
+ m[1],
24634
+ m[2] ?? "0",
24635
+ m[3] ?? "0",
24636
+ m[4] ?? "0"
24637
+ ],
24638
+ stability,
24639
+ numbers: (m[6] ?? "").split(/[.-]/).filter((x) => x !== ""),
24640
+ dev: dev && m[5] !== void 0
24641
+ };
24642
+ }),
24643
+ cmp(a, b) {
24644
+ for (let i = 0; i < 4; i++) {
24645
+ const c = cmpDigits(a.n[i], b.n[i]);
24646
+ if (c !== 0) return c;
24647
+ }
24648
+ if (a.stability !== b.stability) return a.stability - b.stability;
24649
+ for (let i = 0; i < Math.max(a.numbers.length, b.numbers.length); i++) {
24650
+ const c = cmpDigits(a.numbers[i] ?? "0", b.numbers[i] ?? "0");
24651
+ if (c !== 0) return c;
24652
+ }
24653
+ if (a.dev !== b.dev) return a.dev ? -1 : 1;
24654
+ return 0;
24655
+ }
24656
+ }
24657
+ };
24658
+ /** ">=V" introduced, "<V" fixed, "<=V" last affected, "?kind=V" anything else; null if malformed. */
24659
+ function parseEvent(event) {
24660
+ if (typeof event !== "string") return null;
24661
+ if (event.startsWith(">=")) return {
24662
+ op: ">=",
24663
+ v: event.slice(2)
24664
+ };
24665
+ if (event.startsWith("<=")) return {
24666
+ op: "<=",
24667
+ v: event.slice(2)
24668
+ };
24669
+ if (event.startsWith("<")) return {
24670
+ op: "<",
24671
+ v: event.slice(1)
24672
+ };
24673
+ const m = /^\?([a-z_]{1,32})=([^\s]{0,128})$/.exec(event);
24674
+ return m ? {
24675
+ op: "?",
24676
+ kind: m[1],
24677
+ v: m[2]
24678
+ } : null;
24679
+ }
24680
+ /** Parse a range's events once; null when one of them cannot be evaluated. */
24681
+ function compileRange(c, events) {
24682
+ if (events.length === 0) return null;
24683
+ const out = [];
24684
+ for (const e of events) {
24685
+ const p = parseEvent(e);
24686
+ if (!p || p.op === "?") return null;
24687
+ if (p.op === ">=" && p.v === "0") {
24688
+ out.push({
24689
+ op: ">=",
24690
+ key: null
24691
+ });
24692
+ continue;
24693
+ }
24694
+ const key = c.parse(p.v);
24695
+ if (key === null) return null;
24696
+ out.push({
24697
+ op: p.op,
24698
+ key
24699
+ });
24700
+ }
24701
+ return out.sort((x, y) => x.key === null ? y.key === null ? 0 : -1 : y.key === null ? 1 : c.cmp(x.key, y.key));
24702
+ }
24703
+ /**
24704
+ * The OSV evaluation of `ranges` for one ecosystem, compiled once. Per range, walk the events in
24705
+ * version order: an introduced event at or below the version turns "affected" on, a fixed event
24706
+ * at or below it turns it off, a last-affected event below it turns it off. The version is
24707
+ * affected when any range ends on; otherwise unknown (null) when a range could not be evaluated
24708
+ * (an unparseable bound or a "?" event) or the version does not parse; otherwise not affected.
24709
+ */
24710
+ function compileRanges(eco, ranges) {
24711
+ const c = COMPARATORS[eco];
24712
+ const compiled = ranges.map((r) => compileRange(c, r));
24713
+ const someUnknown = compiled.includes(null);
24714
+ return (version) => {
24715
+ const v = c.parse(version);
24716
+ if (v === null) return null;
24717
+ for (const events of compiled) {
24718
+ if (!events) continue;
24719
+ let affected = false;
24720
+ for (const { op, key } of events) if (op === ">=") {
24721
+ if (key === null || c.cmp(v, key) >= 0) affected = true;
24722
+ } else if (op === "<") {
24723
+ if (c.cmp(v, key) >= 0) affected = false;
24724
+ } else if (c.cmp(v, key) > 0) affected = false;
24725
+ if (affected) return true;
24726
+ }
24727
+ return someUnknown ? null : false;
24728
+ };
24729
+ }
24730
+ /**
24731
+ * `version` null means "no exact version". A listed extra version matches as an exact string, or
24732
+ * as an equal version when both parse; then the ranges decide. An entry with no range and no
24733
+ * listed version cannot be evaluated, so it is "unchecked", never "not affected".
24734
+ */
24735
+ function matchAffect(eco, version, ranges, extra = []) {
24736
+ if (version === null || version === "") return "unchecked";
24737
+ if (extra.includes(version)) return "affected";
24738
+ const c = COMPARATORS[eco];
24739
+ const v = c.parse(version);
24740
+ if (v !== null && extra.some((x) => {
24741
+ const k = c.parse(x);
24742
+ return k !== null && c.cmp(v, k) === 0;
24743
+ })) return "affected";
24744
+ if (ranges.length === 0) return extra.length > 0 && v !== null ? "not_affected" : "unchecked";
24745
+ const r = compileRanges(eco, ranges)(version);
24746
+ return r === true ? "affected" : r === null ? "unchecked" : "not_affected";
24747
+ }
24748
+ // shared/packages.ts
24749
+ /**
24750
+ * Package keys, advisory IDs, licences and range wording for v1/packages.json, shared by the
24751
+ * pipeline (which builds and validates the file) and the site (which matches an SBOM against it).
24752
+ * No Node or DOM APIs.
24753
+ */
24754
+ /**
24755
+ * How a package name is compared within an ecosystem, applied both to OSV names and to names from
24756
+ * the user's file. PyPI per PEP 503; crates.io treats case and "-"/"_" as equal; NuGet and
24757
+ * Packagist are case-insensitive; npm, Go module paths, Maven group:artifact and RubyGems as given.
24758
+ */
24759
+ function packageKey(eco, name) {
24760
+ switch (eco) {
24761
+ case "PyPI": return name.replace(/[-_.]+/g, "-").toLowerCase();
24762
+ case "crates.io": return name.toLowerCase().replace(/_/g, "-");
24763
+ case "NuGet":
24764
+ case "Packagist": return name.toLowerCase();
24765
+ default: return name;
24766
+ }
24767
+ }
24768
+ var PURL_TYPES = /* @__PURE__ */ new Map([
24769
+ ["npm", "npm"],
24770
+ ["pypi", "PyPI"],
24771
+ ["maven", "Maven"],
24772
+ ["golang", "Go"],
24773
+ ["cargo", "crates.io"],
24774
+ ["gem", "RubyGems"],
24775
+ ["composer", "Packagist"],
24776
+ ["nuget", "NuGet"]
24777
+ ]);
24778
+ /** The ecosystem of a package URL type (`pkg:<type>/…`), or null when it is not covered. */
24779
+ function ecosystemOfPurlType(type) {
24780
+ return PURL_TYPES.get(type.toLowerCase()) ?? null;
24781
+ }
24782
+ /**
24783
+ * packages.json and packages-older.json as one index for the matcher: rows of both, and per ecosystem
24784
+ * and package key the entries of both. `older` may be null (an older data tree, or a failed load): the
24785
+ * result then is `tracked` as is. When the two come from different runs, a CVE in both keeps its
24786
+ * tracked row and entries only. Objects are built with Object.fromEntries, so a package key such as
24787
+ * `__proto__` stays a plain own key. `sources` (health) comes from `tracked`, with `matched` added up.
24788
+ */
24789
+ function mergePackageFiles(tracked, older) {
24790
+ if (!older) return tracked;
24791
+ const idCol = tracked.cves.cols.indexOf("id");
24792
+ const trackedIds = new Set(tracked.cves.rows.map((r) => r[idCol]));
24793
+ const olderIdCol = older.cves.cols.indexOf("id");
24794
+ const packages = {};
24795
+ for (const eco of PACKAGE_ECOSYSTEMS) {
24796
+ const a = tracked.packages[eco];
24797
+ const b = older.packages[eco];
24798
+ if (!a && !b) continue;
24799
+ const merged = new Map(Object.entries(a ?? {}));
24800
+ for (const [key, list] of Object.entries(b ?? {})) {
24801
+ const extra = Array.isArray(list) ? list.filter((e) => !trackedIds.has(e[0])) : [];
24802
+ if (extra.length) merged.set(key, [...merged.get(key) ?? [], ...extra]);
24803
+ }
24804
+ packages[eco] = Object.fromEntries(merged);
24805
+ }
24806
+ const olderMatched = new Map(older.sources.map((s) => [s.ecosystem, s.matched]));
24807
+ const cols = tracked.cves.cols;
24808
+ const order = cols.map((c) => older.cves.cols.indexOf(c));
24809
+ const rows = older.cves.rows.filter((r) => !trackedIds.has(r[olderIdCol])).map((r) => order.map((j) => j < 0 ? null : r[j]));
24810
+ return {
24811
+ ...tracked,
24812
+ sources: tracked.sources.map((s) => ({
24813
+ ...s,
24814
+ matched: s.matched + (olderMatched.get(s.ecosystem) ?? 0)
24815
+ })),
24816
+ distinct: {
24817
+ advisories: Math.max(tracked.distinct.advisories, older.distinct.advisories),
24818
+ matched: tracked.distinct.matched + older.distinct.matched
24819
+ },
24820
+ cves: {
24821
+ cols,
24822
+ rows: [...tracked.cves.rows, ...rows]
24823
+ },
24824
+ packages
24825
+ };
24826
+ }
24827
+ // cli/src/data.ts
24828
+ /** A packages.json that matches the contract well enough to match against; else the reason it does not. */
24829
+ function checkPackagesFile(doc) {
24830
+ if (typeof doc !== "object" || doc === null || Array.isArray(doc)) return "not a JSON object";
24831
+ const d = doc;
24832
+ if (d.schema_version !== 1) return `schema_version ${String(d.schema_version)}, this tool reads 1`;
24833
+ if (typeof d.generated_at !== "string" || Number.isNaN(Date.parse(d.generated_at))) return "no generated_at";
24834
+ if (!Array.isArray(d.sources)) return "no sources";
24835
+ if (!d.cves || !Array.isArray(d.cves.cols) || d.cves.cols.join() !== ROW_COLS.join() || !Array.isArray(d.cves.rows)) return "cves columns do not match";
24836
+ if (typeof d.packages !== "object" || d.packages === null) return "no packages";
24837
+ return d;
24838
+ }
24261
24839
  // mcp/src/data.ts
24262
24840
  /**
24263
24841
  * Reads the published data tree (shared/contract.ts) for the MCP tools.
@@ -24271,7 +24849,7 @@ function rowsFromTable(table) {
24271
24849
  * - Files are checked before use: schema_version, generated_at, and the exact ROW_COLS of row
24272
24850
  * tables, so no `__proto__` column can reach rowFromColumns.
24273
24851
  * - Parsed files are cached per pipeline run. meta.json is refetched after 300 s (raw and the site
24274
- * cache for 300 s anyway); any other file is reused while its generated_at matches meta's, and
24852
+ * cache for 300 s anyway); any other file is reused while its generated_at names meta's instant, and
24275
24853
  * otherwise refetched at most once per 300 s. When a refresh fails, the last good copy answers
24276
24854
  * and the answer's data.warning says so.
24277
24855
  * - Nothing runs between calls: no polling, and every timer is cleared when its call ends.
@@ -24301,10 +24879,17 @@ var DEFAULTS = {
24301
24879
  now: Date.now
24302
24880
  };
24303
24881
  var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
24882
+ var TIER_SET = new Set(TIERS);
24883
+ /** A short string: ids, types and sources are tens of characters. */
24884
+ var short = (v) => typeof v === "string" && v.length <= 200;
24885
+ /** Every EventItem field with its type, so the tool never trips over a mirror's file. */
24886
+ function isEvent(i) {
24887
+ return short(i.id) && short(i.type) && short(i.cve) && short(i.via) && typeof i.title === "string" && typeof i.detail === "string" && (i.url === null || typeof i.url === "string") && TIER_SET.has(i.tier_after) && (i.tier_before === null || TIER_SET.has(i.tier_before)) && Number.isFinite(i.score) && typeof i.backfill === "boolean";
24888
+ }
24304
24889
  function need(ok, why) {
24305
24890
  if (!ok) throw new BadData(why);
24306
24891
  }
24307
- var parse = {
24892
+ var parse$1 = {
24308
24893
  meta: (j) => {
24309
24894
  need(isObject(j.window) && Array.isArray(j.sources) && typeof j.knob_default === "number", "missing window, sources or knob_default");
24310
24895
  return j;
@@ -24334,6 +24919,18 @@ var parse = {
24334
24919
  need(Array.isArray(j.items) && isObject(j.tracking), "items or tracking missing");
24335
24920
  return j;
24336
24921
  },
24922
+ events: (j) => {
24923
+ need(Array.isArray(j.items) && Number.isInteger(j.days) && Number.isInteger(j.max_items) && Number.isFinite(Date.parse(j.generated_at)), "items, days, max_items or generated_at missing");
24924
+ need(j.items.every((i) => isObject(i) && typeof i.at === "string" && Number.isFinite(Date.parse(i.at)) && typeof i.vendor === "string" && typeof i.product === "string"), "an item has no valid at, vendor or product");
24925
+ need(j.items.every(isEvent), "an item has a field of the wrong type");
24926
+ return j;
24927
+ },
24928
+ /** packages.json and packages-older.json: the shape the matcher needs, with the exact row columns. */
24929
+ packages: (j) => {
24930
+ const checked = checkPackagesFile(j);
24931
+ need(typeof checked !== "string", typeof checked === "string" ? checked : "");
24932
+ return checked;
24933
+ },
24337
24934
  receipts: (j) => {
24338
24935
  need(isObject(j.forward) && Array.isArray(j.forward.items), "forward log missing");
24339
24936
  return j;
@@ -24396,6 +24993,11 @@ var DataClient = class {
24396
24993
  /** Fetches in progress, shared by concurrent calls, with the signal of the call that started each. */
24397
24994
  inflight = /* @__PURE__ */ new Map();
24398
24995
  skipUntil = /* @__PURE__ */ new Map();
24996
+ /** Each running call's deadline, for the messages that name it. */
24997
+ deadlines = /* @__PURE__ */ new WeakMap();
24998
+ deadlineOf(signal) {
24999
+ return this.deadlines.get(signal) ?? this.o.callTimeoutMs;
25000
+ }
24399
25001
  /** Requests sent, for tests and measurements. */
24400
25002
  requests = 0;
24401
25003
  constructor(opts) {
@@ -24419,9 +25021,11 @@ var DataClient = class {
24419
25021
  * Runs one tool call under its deadline. When the call ends, anything it left in flight (a
24420
25022
  * shard fetch after another one failed) is aborted, so nothing keeps running between calls.
24421
25023
  */
24422
- async run(fn) {
25024
+ /** Run one tool call under a deadline: callTimeoutMs, or `timeoutMs` for a tool that reads larger files. */
25025
+ async run(fn, timeoutMs = this.o.callTimeoutMs) {
24423
25026
  const ac = new AbortController();
24424
- const timer = setTimeout(() => ac.abort(new Deadline()), this.o.callTimeoutMs);
25027
+ this.deadlines.set(ac.signal, timeoutMs);
25028
+ const timer = setTimeout(() => ac.abort(new Deadline()), timeoutMs);
24425
25029
  try {
24426
25030
  return await fn(new DataCall(this, ac.signal));
24427
25031
  } finally {
@@ -24508,7 +25112,7 @@ var DataClient = class {
24508
25112
  };
24509
25113
  } catch (e) {
24510
25114
  if (e instanceof DataError) throw e;
24511
- if (signal.aborted) throw new DataError(MCP_MSG.deadline([...reasons, `${host(url)}: no answer within ${this.o.callTimeoutMs / 1e3} s for ${path}`]), reasons);
25115
+ if (signal.aborted) throw new DataError(MCP_MSG.deadline([...reasons, `${host(url)}: no answer within ${this.deadlineOf(signal) / 1e3} s for ${path}`]), reasons);
24512
25116
  if (e instanceof AttemptTimeout) this.skipUntil.set(base, this.o.now() + this.o.skipMs);
24513
25117
  reasons.push(`${host(url)}: ${e instanceof SyntaxError ? "not valid JSON" : why(e)} for ${path}`);
24514
25118
  }
@@ -24523,7 +25127,7 @@ var DataClient = class {
24523
25127
  const cache = path.startsWith("cve/") ? this.shardCache : this.files;
24524
25128
  const hit = cache.get(path);
24525
25129
  const now = this.o.now();
24526
- if (hit && (gen !== null && hit.gen === gen || now - hit.checkedAt < this.o.metaTtlMs)) return hit;
25130
+ if (hit && (gen !== null && Date.parse(hit.gen) === Date.parse(gen) || now - hit.checkedAt < this.o.metaTtlMs)) return hit;
24527
25131
  let f = this.inflight.get(path);
24528
25132
  if (!f) {
24529
25133
  const mine = {
@@ -24547,7 +25151,7 @@ var DataClient = class {
24547
25151
  return await (stop ? Promise.race([f.p, stop.promise]) : f.p);
24548
25152
  } catch (err) {
24549
25153
  if (joined && f.signal.aborted && !signal.aborted && !(err instanceof DataUnavailable) && !(err instanceof SchemaMismatch)) return this.load(path, parser, gen, signal);
24550
- const e = joined && signal.aborted && !(err instanceof DataError) ? new DataError(MCP_MSG.deadline([`no answer within ${this.o.callTimeoutMs / 1e3} s for ${path}`])) : err;
25154
+ const e = joined && signal.aborted && !(err instanceof DataError) ? new DataError(MCP_MSG.deadline([`no answer within ${this.deadlineOf(signal) / 1e3} s for ${path}`])) : err;
24551
25155
  if (!hit || e instanceof DataUnavailable || e instanceof SchemaMismatch || !(e instanceof DataError)) throw e;
24552
25156
  hit.checkedAt = this.o.now();
24553
25157
  hit.warning = MCP_MSG.refreshFailed(e.reasons.length ? e.reasons : ["no answer in time"], new Date(hit.loadedAt).toISOString());
@@ -24578,7 +25182,7 @@ var DataCall = class {
24578
25182
  return e.value;
24579
25183
  }
24580
25184
  async meta() {
24581
- this.metaEntry ??= await this.dc.load("meta.json", parse.meta, null, this.signal);
25185
+ this.metaEntry ??= await this.dc.load("meta.json", parse$1.meta, null, this.signal);
24582
25186
  return this.use("meta.json", this.metaEntry);
24583
25187
  }
24584
25188
  async file(path, parser) {
@@ -24592,7 +25196,7 @@ var DataCall = class {
24592
25196
  const queue = [...new Set(names)];
24593
25197
  const entries = /* @__PURE__ */ new Map();
24594
25198
  const worker = async () => {
24595
- for (let name = queue.shift(); name !== void 0; name = queue.shift()) entries.set(name, await this.dc.load(`cve/${name}.json`, parse.shard, meta.generated_at, this.signal));
25199
+ for (let name = queue.shift(); name !== void 0; name = queue.shift()) entries.set(name, await this.dc.load(`cve/${name}.json`, parse$1.shard, meta.generated_at, this.signal));
24596
25200
  };
24597
25201
  await Promise.all(Array.from({ length: Math.min(this.dc.shardConcurrency, queue.length) }, worker));
24598
25202
  for (const name of [...new Set(names)]) {
@@ -24654,8 +25258,10 @@ var CHIPS = [
24654
25258
  c("vendor.functional", "X", "up", 24, "cvelist", "Vendor: working exploit", "The CNA’s CVSS v3 vector says functional or autonomous exploit code exists (E:F/E:H). That is weaponization, not proof of attacks: about a quarter of such CVEs reach KEV. VulDB vectors are ignored."),
24655
25259
  c("vendor.poc", "X", "up", 10, "cvelist", "Vendor: PoC", "The CNA’s CVSS vector says a proof of concept exists (E:P). VulDB vectors are ignored."),
24656
25260
  c("epss.mid", "X", "up", 8, "epss", "EPSS 1–10%", "EPSS between 1% and 10% (only trusted after 14 days)."),
25261
+ c("fast.lane", "X", "up", 12, "computed", "Fast lane", "Less than 14 days old, attack vector Network with no user interaction, CISA SSVC automatable with total impact (or CVSS 9.0 or more while SSVC is not in yet), on an internet-facing edge device or a product already in CISA KEV. Attack tools can now turn a public reproducer into an exploit within hours for some bugs, before exploit feeds see it, so this stands in for an exploit sign. It is not evidence of attacks. The strongest X chip counts, so a real exploit replaces it."),
24657
25262
  c("x.none", "X", "down", -14, "computed", "No exploit yet", "Two weeks after publication there is still no public exploit and EPSS is below 1%."),
24658
- c("x.too_new", "X", "unknown", 0, "computed", "Too new", "No exploit chip, but absence is not settled: the CVE is less than 14 days old, a PoC repo is too new to vet, or an exploit source could not be loaded this run."),
25263
+ c("x.early", "X", "down", -3, "computed", "No exploit yet (early)", "Less than 14 days old and no exploit signal yet. Weak evidence, so a small penalty: severity, SSVC and KEV history alone stay under the default evidence bar. Not applied to internet-facing edge devices, and replaced by the fast lane when that fires."),
25264
+ c("x.too_new", "X", "unknown", 0, "computed", "Too new", "No exploit chip, but absence is not settled: a PoC repo is too new to vet, an exploit source could not be loaded this run, or the CVE is an internet-facing edge device under 14 days old."),
24659
25265
  c("sev.crit_net", "SEV", "up", 13, "cvelist", "Critical · network", "CVSS ≥ 9.0 and attack vector Network."),
24660
25266
  c("sev.crit", "SEV", "up", 6, "cvelist", "Critical", "CVSS ≥ 9.0, not network-reachable."),
24661
25267
  c("sev.high", "SEV", "up", 1, "cvelist", "High", "CVSS 7.0–8.9. Half of all new CVEs are High or Critical, so this barely moves the needle."),
@@ -24685,6 +25291,7 @@ var CHIPS = [
24685
25291
  c("circl.suspected", "INFO", "info", 0, "circl-kev", "CIRCL: suspected", "CIRCL lists exploitation as suspected, not confirmed (CC0-1.0). Information only."),
24686
25292
  c("circl.attempts", "INFO", "info", 0, "circl-kev", "CIRCL: attempts", "CIRCL lists it as confirmed in its known-exploited catalog (CC0-1.0), but the only evidence is exploitation attempts, such as hits on a sinkhole. Attempts are not proof that an attack worked: information only."),
24687
25293
  c("honeypot.siberkapan", "INFO", "info", 0, "siberkapan", "Honeypot attempts", "SiberKapan’s honeypot and web sensors in Turkey saw exploitation attempts (CC-BY-4.0). Attempts are not proof that an attack worked, and one sensor network gives too little data to set points: information only."),
25294
+ c("edge.device", "INFO", "info", 0, "computed", "Edge device", "An internet-facing edge device: VPN, firewall, load balancer, email gateway, file transfer, webmail, remote support, SD-WAN or edge router (curated list in shared/edge.ts, explained in docs/SCORING.md). These are often attacked before any exploit is public, so the early no-exploit penalty does not apply."),
24688
25295
  c("tag.eol", "INFO", "info", 0, "cvelist", "Unsupported product", "The product was unsupported when the CVE was assigned: there may be no patch. Replace or mitigate.")
24689
25296
  ];
24690
25297
  Object.fromEntries(CHIPS.map((d) => [d.id, d]));
@@ -24702,9 +25309,1504 @@ function shardOf(cveId) {
24702
25309
  return (fnv1a(cveId.trim().toUpperCase()) % 256).toString(16).padStart(2, "0");
24703
25310
  }
24704
25311
  var CVE_ID_RE = /^CVE-\d{4}-\d{4,}$/;
25312
+ /**
25313
+ * Slug of a vendor or product name: NFKD, accents dropped, lower case, every run of other
25314
+ * characters becomes one hyphen, no hyphen at either end, at most SLUG_MAX characters. "" when
25315
+ * nothing is left (a name with no ASCII letters or digits).
25316
+ */
25317
+ function slugify(name) {
25318
+ return name.normalize("NFKD").replace(/\p{M}+/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64).replace(/-+$/, "");
25319
+ }
25320
+ // shared/watch.ts
25321
+ var normalizeName = (s) => s.trim().toLowerCase().replace(/\s+/g, " ");
25322
+ /** True when a normalized name in `list` equals the vendor or the product. */
25323
+ function matchesName(list, vendor, product) {
25324
+ if (list.length === 0) return false;
25325
+ return vendor !== "" && list.includes(normalizeName(vendor)) || product !== "" && list.includes(normalizeName(product));
25326
+ }
25327
+ // site/src/check/match.ts
25328
+ /**
25329
+ * Matches parsed packages against v1/packages.json: which tracked CVEs affect which versions.
25330
+ *
25331
+ * The rule is OSV's, through shared/versions.ts (the pipeline uses the same code): a version is
25332
+ * affected when an advisory lists it or one of its ranges contains it. Anything that cannot be
25333
+ * compared is "possibly affected", never clean. Lookups go through Maps built once from the file,
25334
+ * so a package named `__proto__` or `constructor` cannot reach Object.prototype.
25335
+ */
25336
+ var NOT_CHECKED_ORDER = [
25337
+ "eco-down",
25338
+ "ecosystem",
25339
+ "no-purl",
25340
+ "bad-purl",
25341
+ "not-registry",
25342
+ "dev-branch",
25343
+ "go-stdlib"
25344
+ ];
25345
+ /** The fixed version the matching range names next above `version`, if any. */
25346
+ function fixedIn(eco, version, ranges) {
25347
+ const c = COMPARATORS[eco];
25348
+ const v = c.parse(version);
25349
+ if (v === null) return null;
25350
+ for (const range of ranges) {
25351
+ if (compileRanges(eco, [range])(version) !== true) continue;
25352
+ let best = null;
25353
+ for (const e of range) {
25354
+ const p = parseEvent(e);
25355
+ if (p?.op !== "<") continue;
25356
+ const key = c.parse(p.v);
25357
+ if (key !== null && c.cmp(key, v) > 0 && (best === null || c.cmp(key, best.key) < 0)) best = {
25358
+ key,
25359
+ text: p.v
25360
+ };
25361
+ }
25362
+ if (best) return best.text;
25363
+ }
25364
+ return null;
25365
+ }
25366
+ var isAffect = (a) => Array.isArray(a) && typeof a[0] === "string" && typeof a[1] === "string" && Array.isArray(a[2]);
25367
+ var GO_MAJOR = /^v[0-9]+$/;
25368
+ /**
25369
+ * Go paths an advisory names that may belong to a module in the file: the same path in other
25370
+ * letter case, and paths inside the module. A path belongs to the longest module of the file that
25371
+ * is a prefix of it (Go's rule), never across a /vN major-version element, which starts another
25372
+ * module. Prefixes compare in any letter case, so a lowercased package URL of a module owns the
25373
+ * paths inside it too. Built once per check from the file's own Go modules.
25374
+ */
25375
+ function goLookups(go, modules) {
25376
+ const lower = /* @__PURE__ */ new Map();
25377
+ const inside = /* @__PURE__ */ new Map();
25378
+ const add = (m, k, v) => {
25379
+ const list = m.get(k);
25380
+ if (list) list.push(v);
25381
+ else m.set(k, [v]);
25382
+ };
25383
+ const byLower = /* @__PURE__ */ new Map();
25384
+ for (const m of modules) add(byLower, m.toLowerCase(), m);
25385
+ for (const [key, list] of go) {
25386
+ if (!Array.isArray(list)) continue;
25387
+ add(lower, key.toLowerCase(), {
25388
+ key,
25389
+ list,
25390
+ reason: "name-case"
25391
+ });
25392
+ if (byLower.has(key.toLowerCase())) continue;
25393
+ const parts = key.split("/");
25394
+ for (let i = parts.length - 1; i > 0; i--) {
25395
+ if (GO_MAJOR.test(parts[i])) break;
25396
+ const owners = byLower.get(parts.slice(0, i).join("/").toLowerCase());
25397
+ if (owners) {
25398
+ for (const owner of owners) add(inside, owner, {
25399
+ key,
25400
+ list,
25401
+ reason: "go-package"
25402
+ });
25403
+ break;
25404
+ }
25405
+ }
25406
+ }
25407
+ return {
25408
+ lower,
25409
+ inside
25410
+ };
25411
+ }
25412
+ /** Check every package of `parsed` against the index. Pure: no I/O. */
25413
+ function checkComponents(parsed, file) {
25414
+ const rows = new Map(rowsFromTable(file.cves).map((r) => [r.id, r]));
25415
+ const index = /* @__PURE__ */ new Map();
25416
+ const ok = new Set(file.sources.filter((s) => s.ok).map((s) => s.ecosystem));
25417
+ for (const eco of PACKAGE_ECOSYSTEMS) {
25418
+ const pkgs = file.packages?.[eco];
25419
+ if (ok.has(eco) && typeof pkgs === "object" && pkgs !== null) index.set(eco, new Map(Object.entries(pkgs)));
25420
+ }
25421
+ const distinct = /* @__PURE__ */ new Map();
25422
+ for (const c of parsed.components) {
25423
+ const k = [
25424
+ c.eco ?? `~${c.type ?? ""}`,
25425
+ c.eco ? packageKey(c.eco, c.name) : c.name,
25426
+ c.version ?? "",
25427
+ c.skip ?? c.noVersion ?? ""
25428
+ ].join("\0");
25429
+ if (!distinct.has(k)) distinct.set(k, c);
25430
+ }
25431
+ const goIndex = index.get("Go");
25432
+ const goModules = /* @__PURE__ */ new Set();
25433
+ for (const c of distinct.values()) if (c.eco === "Go" && !c.skip) goModules.add(packageKey("Go", c.name));
25434
+ const go = goIndex ? goLookups(goIndex, goModules) : null;
25435
+ const notChecked = /* @__PURE__ */ new Map();
25436
+ const skip = (reason, c, eco) => {
25437
+ const k = `${reason}:${eco ?? ""}`;
25438
+ let g = notChecked.get(k);
25439
+ if (!g) notChecked.set(k, g = {
25440
+ reason,
25441
+ eco,
25442
+ items: []
25443
+ });
25444
+ g.items.push(c);
25445
+ };
25446
+ const byCve = /* @__PURE__ */ new Map();
25447
+ const clean = [];
25448
+ const affectedKeys = /* @__PURE__ */ new Set();
25449
+ const possibleKeys = /* @__PURE__ */ new Set();
25450
+ for (const c of distinct.values()) {
25451
+ if (c.skip || !c.eco) {
25452
+ skip(c.skip ?? "ecosystem", c);
25453
+ continue;
25454
+ }
25455
+ const eco = c.eco;
25456
+ const pkgs = index.get(eco);
25457
+ if (!pkgs) {
25458
+ skip("eco-down", c, eco);
25459
+ continue;
25460
+ }
25461
+ const key = packageKey(eco, c.name);
25462
+ const found = pkgs.get(key);
25463
+ const exact = Array.isArray(found) ? found : void 0;
25464
+ const lookups = exact ? [{
25465
+ key,
25466
+ list: exact,
25467
+ reason: null
25468
+ }] : [];
25469
+ if (eco === "Go" && go) {
25470
+ if (!exact) lookups.push(...go.lower.get(key.toLowerCase()) ?? []);
25471
+ lookups.push(...go.inside.get(key) ?? []);
25472
+ }
25473
+ const named = new Set((exact ?? []).filter(isAffect).map((a) => a[0]));
25474
+ const perCve = /* @__PURE__ */ new Map();
25475
+ for (const via of lookups) for (const a of via.list) {
25476
+ if (!isAffect(a)) continue;
25477
+ const [cve, id, ranges, versions = []] = a;
25478
+ if (via.reason && named.has(cve)) continue;
25479
+ const verdict = matchAffect(eco, c.version, ranges, versions);
25480
+ if (verdict === "not_affected") continue;
25481
+ let e = perCve.get(cve);
25482
+ if (e && e.via !== via) continue;
25483
+ if (!e) perCve.set(cve, e = {
25484
+ affected: [],
25485
+ unchecked: [],
25486
+ via
25487
+ });
25488
+ const listed = c.version !== null && versions.includes(c.version);
25489
+ const hit = {
25490
+ id,
25491
+ ranges,
25492
+ versions,
25493
+ listed,
25494
+ fixedIn: verdict === "affected" && c.version !== null && !listed ? fixedIn(eco, c.version, ranges) : null
25495
+ };
25496
+ (verdict === "affected" ? e.affected : e.unchecked).push(hit);
25497
+ }
25498
+ const id = `${eco}\u0000${key}\u0000${c.version ?? ""}`;
25499
+ let any = false;
25500
+ for (const [cve, e] of perCve) {
25501
+ if (!rows.has(cve)) continue;
25502
+ any = true;
25503
+ const inRange = e.affected.length > 0;
25504
+ const affected = inRange && e.via.reason === null;
25505
+ const unchecked = affected ? null : e.via.reason ?? c.noVersion ?? (c.version !== null && COMPARATORS[eco].parse(c.version) === null ? "version" : "range");
25506
+ let hits = byCve.get(cve);
25507
+ if (!hits) byCve.set(cve, hits = []);
25508
+ const hit = {
25509
+ eco,
25510
+ name: c.name,
25511
+ version: c.version,
25512
+ unchecked,
25513
+ advisories: inRange ? e.affected : e.unchecked
25514
+ };
25515
+ if (e.via.reason) hit.named = e.via.key;
25516
+ hits.push(hit);
25517
+ (affected ? affectedKeys : possibleKeys).add(id);
25518
+ }
25519
+ if (!any) clean.push(c);
25520
+ }
25521
+ const cves = [];
25522
+ for (const [cve, packages] of byCve) {
25523
+ const row = rows.get(cve);
25524
+ if (row) cves.push({
25525
+ row,
25526
+ affected: packages.some((p) => p.unchecked === null),
25527
+ packages
25528
+ });
25529
+ }
25530
+ for (const k of affectedKeys) possibleKeys.delete(k);
25531
+ const groups = [...notChecked.values()].sort((a, b) => NOT_CHECKED_ORDER.indexOf(a.reason) - NOT_CHECKED_ORDER.indexOf(b.reason) || (a.eco ?? "").localeCompare(b.eco ?? ""));
25532
+ const skipped = groups.reduce((n, g) => n + g.items.length, 0);
25533
+ return {
25534
+ format: parsed.format,
25535
+ total: parsed.components.length,
25536
+ distinct: distinct.size,
25537
+ checked: distinct.size - skipped,
25538
+ indexCves: rows.size,
25539
+ cves,
25540
+ affectedPackages: affectedKeys.size,
25541
+ possiblePackages: possibleKeys.size,
25542
+ notChecked: groups,
25543
+ clean,
25544
+ notes: parsed.notes
25545
+ };
25546
+ }
25547
+ var GROUP_ORDER = [
25548
+ "exploited",
25549
+ "likely",
25550
+ "watch",
25551
+ "quiet",
25552
+ "possible"
25553
+ ];
25554
+ /** CVEs grouped by tier at `knob` (possibly affected ones apart), each group by score, then newest. */
25555
+ function groupByTier(cves, knob) {
25556
+ const out = new Map(GROUP_ORDER.map((g) => [g, []]));
25557
+ for (const c of cves) out.get(c.affected ? tierFor(c.row.s, c.row.x === 1, c.row.w === 1, knob) : "possible").push(c);
25558
+ for (const list of out.values()) list.sort((a, b) => b.row.s - a.row.s || b.row.pub.localeCompare(a.row.pub) || a.row.id.localeCompare(b.row.id));
25559
+ return out;
25560
+ }
25561
+ /** Why a file could not be read. `detail` quotes the file (the JSON error), so it is rendered as file text. */
25562
+ var ParseError = class extends Error {
25563
+ kind;
25564
+ detail;
25565
+ constructor(kind, detail = "") {
25566
+ super(parseErrorText(kind, detail));
25567
+ this.kind = kind;
25568
+ this.detail = detail;
25569
+ this.name = "ParseError";
25570
+ }
25571
+ };
25572
+ /** Build files people try first, which name the versions asked for, not the ones installed. */
25573
+ var MANIFEST_TEXT = /* @__PURE__ */ new Map([
25574
+ ["pom", "pom.xml lists the versions you ask for, not the ones your build resolves. Make an SBOM instead: mvn org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom (it writes target/bom.json)."],
25575
+ ["gradle", "build.gradle lists the versions you ask for, not the ones your build resolves. Make an SBOM with the CycloneDX Gradle plugin (gradle cyclonedxBom), or check gradle.lockfile with dependency locking turned on."],
25576
+ ["npm", "package.json lists version ranges, not the versions you install. Check package-lock.json, yarn.lock or pnpm-lock.yaml instead, or make an SBOM: npm sbom --sbom-format cyclonedx."]
25577
+ ]);
25578
+ function parseErrorText(kind, detail = "") {
25579
+ if (kind === "json") return `This looks like JSON, but it could not be read: ${detail}. Check that the whole file was pasted.`;
25580
+ if (kind === "manifest") return MANIFEST_TEXT.get(detail) ?? parseErrorText("unknown");
25581
+ if (kind === "unknown") return "We could not tell what kind of file this is. Pick it under Read as, or see the accepted files below.";
25582
+ return "No packages found in this file.";
25583
+ }
25584
+ var MAX_PURL = 2048;
25585
+ var GO_SUM_NOTE = "go.sum can list module versions your build does not use, so this may show versions you do not run. go.mod is more exact.";
25586
+ var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
25587
+ var str = (v) => typeof v === "string" && v.trim() !== "" ? v.trim() : null;
25588
+ var entries = (v) => isObj(v) ? Object.entries(v) : [];
25589
+ function decode(s) {
25590
+ try {
25591
+ return decodeURIComponent(s);
25592
+ } catch {
25593
+ return s;
25594
+ }
25595
+ }
25596
+ function unquote(s) {
25597
+ const t = s.trim();
25598
+ return t.length >= 2 && (t[0] === "\"" || t[0] === "'") && t[t.length - 1] === t[0] ? t.slice(1, -1) : t;
25599
+ }
25600
+ /** Lines of a line-oriented format; lines over MAX_LINE are skipped and counted. */
25601
+ function lines(text, notes) {
25602
+ const out = [];
25603
+ let long = 0;
25604
+ for (const raw of text.split("\n")) {
25605
+ const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
25606
+ if (line.length > 65536) long++;
25607
+ else out.push(line);
25608
+ }
25609
+ if (long) notes.push(`Skipped ${long === 1 ? "a line" : `${long} lines`} longer than 64 KB.`);
25610
+ return out;
25611
+ }
25612
+ /** A package URL (`pkg:type/namespace/name@version?qualifiers#subpath`) as a component; null when malformed. */
25613
+ function purlComponent(raw) {
25614
+ const full = raw.trim();
25615
+ if (full.length > MAX_PURL || full.slice(0, 4).toLowerCase() !== "pkg:") return null;
25616
+ let s = full.slice(4);
25617
+ while (s.startsWith("/")) s = s.slice(1);
25618
+ const hash = s.indexOf("#");
25619
+ if (hash >= 0) s = s.slice(0, hash);
25620
+ const query = s.indexOf("?");
25621
+ if (query >= 0) s = s.slice(0, query);
25622
+ const slash = s.indexOf("/");
25623
+ if (slash <= 0) return null;
25624
+ const type = s.slice(0, slash).toLowerCase();
25625
+ if (!/^[a-z][a-z0-9.+-]{0,31}$/.test(type)) return null;
25626
+ let rest = s.slice(slash + 1);
25627
+ while (rest.endsWith("/")) rest = rest.slice(0, -1);
25628
+ let version = null;
25629
+ const at = rest.lastIndexOf("@");
25630
+ if (at > 0 && at > rest.lastIndexOf("/")) {
25631
+ version = str(decode(rest.slice(at + 1)));
25632
+ rest = rest.slice(0, at);
25633
+ }
25634
+ const parts = rest.split("/").filter(Boolean).map(decode);
25635
+ if (parts.length === 0) return null;
25636
+ const name = parts[parts.length - 1];
25637
+ const ns = parts.slice(0, -1);
25638
+ const eco = ecosystemOfPurlType(type);
25639
+ if (!eco) return {
25640
+ eco: null,
25641
+ type,
25642
+ name: parts.join("/"),
25643
+ version,
25644
+ skip: "ecosystem"
25645
+ };
25646
+ let pkgName;
25647
+ if (eco === "npm") pkgName = ns.length ? `${ns[0].startsWith("@") ? "" : "@"}${ns.join("/")}/${name}` : name;
25648
+ else if (eco === "Maven") pkgName = ns.length ? `${ns.join(".")}:${name}` : name;
25649
+ else pkgName = parts.join("/");
25650
+ if (eco === "Go" && (pkgName === "stdlib" || pkgName === "toolchain") && version?.startsWith("go")) version = version.slice(2);
25651
+ return version === null ? {
25652
+ eco,
25653
+ name: pkgName,
25654
+ version: null,
25655
+ noVersion: "no-version"
25656
+ } : {
25657
+ eco,
25658
+ name: pkgName,
25659
+ version
25660
+ };
25661
+ }
25662
+ /** An SBOM entry: its package URL when there is one, otherwise "not checked" under its own name. */
25663
+ function sbomEntry(purl, name, version) {
25664
+ const ver = str(version);
25665
+ const p = str(purl);
25666
+ if (p) {
25667
+ const c = purlComponent(p);
25668
+ if (c) {
25669
+ if (c.version === null && c.eco && ver) return {
25670
+ eco: c.eco,
25671
+ name: c.name,
25672
+ version: ver
25673
+ };
25674
+ return c;
25675
+ }
25676
+ return {
25677
+ eco: null,
25678
+ name: str(name) ?? p,
25679
+ version: ver,
25680
+ skip: "bad-purl"
25681
+ };
25682
+ }
25683
+ return {
25684
+ eco: null,
25685
+ name: str(name) ?? "(no name)",
25686
+ version: ver,
25687
+ skip: "no-purl"
25688
+ };
25689
+ }
25690
+ function cyclonedxJson(doc) {
25691
+ const out = [];
25692
+ const meta = isObj(doc.metadata) ? doc.metadata : null;
25693
+ const stack = [doc.components, meta && isObj(meta.component) ? [meta.component] : null];
25694
+ while (stack.length) {
25695
+ const list = stack.pop();
25696
+ if (!Array.isArray(list)) continue;
25697
+ for (const c of list) {
25698
+ if (!isObj(c)) continue;
25699
+ const group = str(c.group);
25700
+ const name = str(c.name);
25701
+ out.push(sbomEntry(c.purl, group && name ? `${group}/${name}` : name, c.version));
25702
+ if (c.components) stack.push(c.components);
25703
+ }
25704
+ }
25705
+ return out;
25706
+ }
25707
+ function spdxJson(doc) {
25708
+ const out = [];
25709
+ if (Array.isArray(doc.packages)) for (const p of doc.packages) {
25710
+ if (!isObj(p)) continue;
25711
+ const ref = (Array.isArray(p.externalRefs) ? p.externalRefs : []).find((r) => isObj(r) && typeof r.referenceType === "string" && r.referenceType.toLowerCase() === "purl");
25712
+ out.push(sbomEntry(isObj(ref) ? ref.referenceLocator : null, p.name, p.versionInfo));
25713
+ }
25714
+ if (Array.isArray(doc["@graph"])) for (const e of doc["@graph"]) {
25715
+ if (!isObj(e)) continue;
25716
+ if ((str(e.type) ?? str(e["@type"])) !== "software_Package") continue;
25717
+ const id = (Array.isArray(e.externalIdentifier) ? e.externalIdentifier : []).find((x) => isObj(x) && x.externalIdentifierType === "packageUrl");
25718
+ out.push(sbomEntry(e.software_packageUrl ?? (isObj(id) ? id.identifier : null), e.name, e.software_packageVersion));
25719
+ }
25720
+ return out;
25721
+ }
25722
+ function spdxTag(text, notes) {
25723
+ const out = [];
25724
+ let cur = null;
25725
+ let inText = false;
25726
+ const flush = () => cur && out.push(sbomEntry(cur.purl, cur.name, cur.version));
25727
+ for (const line of lines(text, notes)) {
25728
+ if (inText) {
25729
+ if (line.includes("</text>")) inText = false;
25730
+ continue;
25731
+ }
25732
+ const colon = line.indexOf(":");
25733
+ if (colon <= 0) continue;
25734
+ const tag = line.slice(0, colon).trim();
25735
+ const value = line.slice(colon + 1).trim();
25736
+ if (value.startsWith("<text>") && !value.includes("</text>")) {
25737
+ inText = true;
25738
+ continue;
25739
+ }
25740
+ if (tag === "PackageName") {
25741
+ flush();
25742
+ cur = {
25743
+ name: value,
25744
+ version: null,
25745
+ purl: null
25746
+ };
25747
+ } else if (cur && tag === "PackageVersion") cur.version = value;
25748
+ else if (cur && tag === "ExternalRef") {
25749
+ const [, type, locator] = value.split(/\s+/);
25750
+ if (type?.toLowerCase() === "purl" && locator) cur.purl = locator;
25751
+ }
25752
+ }
25753
+ flush();
25754
+ return out;
25755
+ }
25756
+ var XML_ENTITIES = /* @__PURE__ */ new Map([
25757
+ ["amp", "&"],
25758
+ ["lt", "<"],
25759
+ ["gt", ">"],
25760
+ ["quot", "\""],
25761
+ ["apos", "'"]
25762
+ ]);
25763
+ /** The five predefined XML entities and numeric references; nothing else is expanded. */
25764
+ function xmlText(s) {
25765
+ return s.replace(/&(#x[0-9a-fA-F]{1,6}|#[0-9]{1,7}|[a-z]{2,4});/g, (whole, ref) => {
25766
+ if (ref[0] !== "#") return XML_ENTITIES.get(ref) ?? whole;
25767
+ const code = ref[1] === "x" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
25768
+ return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : whole;
25769
+ });
25770
+ }
25771
+ var XML_TAG = /<(\/?)(?:[A-Za-z_][\w.-]{0,31}:)?([A-Za-z_][\w.-]{0,63})((?:\s[^<>]*?)?)(\/?)>|<!--|<!\[CDATA\[/g;
25772
+ var XML_FIELDS = /* @__PURE__ */ new Set([
25773
+ "group",
25774
+ "name",
25775
+ "version",
25776
+ "purl"
25777
+ ]);
25778
+ var XML_MAX_DEPTH = 256;
25779
+ /**
25780
+ * The same components as CycloneDX JSON: those under the top-level <components> (nested ones
25781
+ * included) and the subject in <metadata>, not the tools in <metadata><tools> or the build
25782
+ * components in <formulation>. Each component's own <group>, <name>, <version> and <purl> are read.
25783
+ */
25784
+ function cyclonedxXml(text) {
25785
+ const found = [];
25786
+ const stack = [];
25787
+ const open = [];
25788
+ let field = null;
25789
+ XML_TAG.lastIndex = 0;
25790
+ for (let m = XML_TAG.exec(text); m; m = XML_TAG.exec(text)) {
25791
+ const [whole, close, local, , self] = m;
25792
+ if (local === void 0) {
25793
+ const end = text.indexOf(whole === "<!--" ? "-->" : "]]>", XML_TAG.lastIndex);
25794
+ if (end < 0) break;
25795
+ XML_TAG.lastIndex = end + 3;
25796
+ continue;
25797
+ }
25798
+ if (close) {
25799
+ const at = stack.lastIndexOf(local);
25800
+ if (at < 0) continue;
25801
+ if (field && field.depth === at && field.name === local) {
25802
+ const value = text.slice(field.start, m.index);
25803
+ const into = open[at - 1];
25804
+ if (into && value.length <= 2048 && !value.includes("<")) into[local] = xmlText(value).trim();
25805
+ }
25806
+ if (field && field.depth >= at) field = null;
25807
+ stack.length = at;
25808
+ open.length = at;
25809
+ continue;
25810
+ }
25811
+ if (self || stack.length >= XML_MAX_DEPTH) continue;
25812
+ const depth = stack.length;
25813
+ stack.push(local);
25814
+ let comp = null;
25815
+ if (local === "component") {
25816
+ let i = depth - 1;
25817
+ while (i >= 0 && (stack[i] === "component" || stack[i] === "components")) i--;
25818
+ if (i < 0 || stack[i] === "bom" || stack[i] === "metadata") found.push(comp = { depth });
25819
+ } else if (XML_FIELDS.has(local) && open[depth - 1]) field = {
25820
+ name: local,
25821
+ start: m.index + whole.length,
25822
+ depth
25823
+ };
25824
+ open.push(comp);
25825
+ }
25826
+ return found.map((c) => sbomEntry(c.purl, c.group && c.name ? `${c.group}/${c.name}` : c.name, c.version));
25827
+ }
25828
+ function purlList(text, notes) {
25829
+ const out = [];
25830
+ let other = 0;
25831
+ for (const line of lines(text, notes)) {
25832
+ const t = line.trim();
25833
+ if (t === "" || t.startsWith("#")) continue;
25834
+ if (t.slice(0, 4).toLowerCase() !== "pkg:") {
25835
+ other++;
25836
+ continue;
25837
+ }
25838
+ out.push(purlComponent(t) ?? {
25839
+ eco: null,
25840
+ name: t,
25841
+ version: null,
25842
+ skip: "bad-purl"
25843
+ });
25844
+ }
25845
+ if (other) notes.push(`Ignored ${other === 1 ? "a line" : `${other} lines`} that ${other === 1 ? "is not a package URL" : "are not package URLs"}.`);
25846
+ return out;
25847
+ }
25848
+ var isRegistryTarball = (url) => /^https?:\/\//i.test(url) && url.split(/[?#]/)[0].toLowerCase().endsWith(".tgz");
25849
+ function npmEntry(name, version, resolved) {
25850
+ const ver = str(version);
25851
+ if (ver === null) return {
25852
+ eco: "npm",
25853
+ name,
25854
+ version: null,
25855
+ noVersion: "no-version"
25856
+ };
25857
+ if (ver.startsWith("npm:")) {
25858
+ const real = ver.slice(4);
25859
+ const at = real.lastIndexOf("@");
25860
+ if (at > 0) return npmEntry(real.slice(0, at), real.slice(at + 1), resolved);
25861
+ }
25862
+ if (/^[a-z][a-z+]*:/i.test(ver) || ver.includes("/") || typeof resolved === "string" && resolved !== "" && !isRegistryTarball(resolved)) return {
25863
+ eco: "npm",
25864
+ name,
25865
+ version: null,
25866
+ skip: "not-registry"
25867
+ };
25868
+ return {
25869
+ eco: "npm",
25870
+ name,
25871
+ version: ver
25872
+ };
25873
+ }
25874
+ function npmLock(doc) {
25875
+ const out = [];
25876
+ if (isObj(doc.packages)) {
25877
+ for (const [path, v] of entries(doc.packages)) {
25878
+ if (path === "" || !isObj(v) || v.link === true) continue;
25879
+ const i = path.lastIndexOf("node_modules/");
25880
+ const name = str(v.name) ?? (i >= 0 ? path.slice(i + 13) : path);
25881
+ if (i < 0) out.push({
25882
+ eco: "npm",
25883
+ name,
25884
+ version: str(v.version),
25885
+ skip: "not-registry"
25886
+ });
25887
+ else out.push(npmEntry(name, v.version, v.resolved));
25888
+ }
25889
+ return out;
25890
+ }
25891
+ const stack = [doc.dependencies];
25892
+ while (stack.length) for (const [name, v] of entries(stack.pop())) {
25893
+ if (!isObj(v)) continue;
25894
+ out.push(npmEntry(name, v.version, v.resolved));
25895
+ if (v.dependencies) stack.push(v.dependencies);
25896
+ }
25897
+ return out;
25898
+ }
25899
+ /** yarn.lock v1 ("version \"1.2.3\"") and Berry ("version: 1.2.3", "resolution: \"name@npm:1.2.3\""). */
25900
+ function yarnLock(text, notes) {
25901
+ const out = [];
25902
+ let head = null;
25903
+ let version = null;
25904
+ let resolution = null;
25905
+ const flush = () => {
25906
+ if (head !== null && head !== "__metadata") out.push(yarnEntry(head, version, resolution));
25907
+ head = version = resolution = null;
25908
+ };
25909
+ for (const line of lines(text, notes)) {
25910
+ if (line === "" || line.startsWith("#")) continue;
25911
+ if (line[0] !== " ") {
25912
+ flush();
25913
+ if (line.endsWith(":")) head = line.slice(0, -1);
25914
+ continue;
25915
+ }
25916
+ if (head === null || line[2] === " ") continue;
25917
+ const m = /^ {2}(version|resolution):? +(\S.*)$/.exec(line);
25918
+ if (!m) continue;
25919
+ if (m[1] === "version") version = unquote(m[2]);
25920
+ else resolution = unquote(m[2]);
25921
+ }
25922
+ flush();
25923
+ return out;
25924
+ }
25925
+ /** "name@range" → [name, range]; the name may start with "@". */
25926
+ function splitDescriptor(d) {
25927
+ const at = d.indexOf("@", 1);
25928
+ return at > 0 ? [d.slice(0, at), d.slice(at + 1)] : [d, ""];
25929
+ }
25930
+ function yarnEntry(head, version, resolution) {
25931
+ if (resolution !== null) {
25932
+ const [name, ref] = splitDescriptor(resolution);
25933
+ if (!(ref.startsWith("npm:") || ref.startsWith("patch:") && (ref.includes("@npm%3A") || ref.includes("@npm:")))) return {
25934
+ eco: "npm",
25935
+ name,
25936
+ version: null,
25937
+ skip: "not-registry"
25938
+ };
25939
+ return version ? {
25940
+ eco: "npm",
25941
+ name,
25942
+ version
25943
+ } : {
25944
+ eco: "npm",
25945
+ name,
25946
+ version: null,
25947
+ noVersion: "no-version"
25948
+ };
25949
+ }
25950
+ let [name, range] = splitDescriptor(unquote(head.split(",")[0]));
25951
+ if (range.startsWith("npm:")) [name, range] = splitDescriptor(range.slice(4));
25952
+ if (/^[a-z][a-z+]*:/i.test(range) || range.includes("/")) return {
25953
+ eco: "npm",
25954
+ name,
25955
+ version: null,
25956
+ skip: "not-registry"
25957
+ };
25958
+ return version ? {
25959
+ eco: "npm",
25960
+ name,
25961
+ version
25962
+ } : {
25963
+ eco: "npm",
25964
+ name,
25965
+ version: null,
25966
+ noVersion: "no-version"
25967
+ };
25968
+ }
25969
+ /** pnpm-lock.yaml v5 ("/name/1.0.0_peer"), v6 ("/name@1.0.0(peer)") and v9 ("name@1.0.0"). */
25970
+ function pnpmLock(text, notes) {
25971
+ const out = [];
25972
+ const seen = /* @__PURE__ */ new Set();
25973
+ let section = "";
25974
+ let major = 9;
25975
+ for (const line of lines(text, notes)) {
25976
+ if (line === "" || line.trimStart().startsWith("#")) continue;
25977
+ if (line[0] !== " ") {
25978
+ section = line.trim();
25979
+ if (section.startsWith("lockfileVersion:")) major = parseFloat(unquote(section.slice(16))) || 9;
25980
+ continue;
25981
+ }
25982
+ if (section !== "packages:" && section !== "snapshots:" || line[2] === " ") continue;
25983
+ let body = line.trim();
25984
+ if (body.endsWith(" {}")) body = body.slice(0, -3);
25985
+ if (!body.endsWith(":")) continue;
25986
+ let key = unquote(body.slice(0, -1));
25987
+ const fromRegistry = major >= 9 || key.startsWith("/");
25988
+ if (key.startsWith("/")) key = key.slice(1);
25989
+ const paren = key.indexOf("(");
25990
+ if (paren > 0) key = key.slice(0, paren);
25991
+ let name;
25992
+ let version;
25993
+ if (major < 6) {
25994
+ const slash = key.lastIndexOf("/");
25995
+ name = key.slice(0, Math.max(0, slash));
25996
+ version = key.slice(slash + 1);
25997
+ const u = version.indexOf("_");
25998
+ if (u > 0) version = version.slice(0, u);
25999
+ } else [name, version] = splitDescriptor(key);
26000
+ if (!name || !fromRegistry || /[:/]/.test(version)) {
26001
+ const id = `?${key}`;
26002
+ if (!seen.has(id)) out.push({
26003
+ eco: "npm",
26004
+ name: name || key,
26005
+ version: null,
26006
+ skip: "not-registry"
26007
+ });
26008
+ seen.add(id);
26009
+ continue;
26010
+ }
26011
+ const id = `${name}@${version}`;
26012
+ if (seen.has(id)) continue;
26013
+ seen.add(id);
26014
+ out.push(version ? {
26015
+ eco: "npm",
26016
+ name,
26017
+ version
26018
+ } : {
26019
+ eco: "npm",
26020
+ name,
26021
+ version: null,
26022
+ noVersion: "no-version"
26023
+ });
26024
+ }
26025
+ return out;
26026
+ }
26027
+ function requirements(text, notes) {
26028
+ const out = [];
26029
+ let includes = 0;
26030
+ let ignored = 0;
26031
+ const joined = [];
26032
+ let buf = "";
26033
+ for (const line of lines(text, notes)) {
26034
+ if (line.endsWith("\\")) {
26035
+ buf += `${line.slice(0, -1)} `;
26036
+ if (buf.length > 65536) buf = "";
26037
+ continue;
26038
+ }
26039
+ joined.push(buf + line);
26040
+ buf = "";
26041
+ }
26042
+ if (buf) joined.push(buf);
26043
+ for (const raw of joined) {
26044
+ const hash = raw.search(/(?:^|\s)#/);
26045
+ const line = (hash >= 0 ? raw.slice(0, hash) : raw).trim();
26046
+ if (line === "") continue;
26047
+ if (line.startsWith("-")) {
26048
+ if (/^(?:-r|-c|--requirement|--constraint)\b/.test(line)) includes++;
26049
+ else if (/^(?:-e|--editable)\b/.test(line)) {
26050
+ const egg = /[#&]egg=([A-Za-z0-9._-]{1,200})/.exec(raw);
26051
+ out.push({
26052
+ eco: "PyPI",
26053
+ name: egg ? egg[1] : line.replace(/^(?:-e|--editable)[\s=]*/, ""),
26054
+ version: null,
26055
+ skip: "not-registry"
26056
+ });
26057
+ }
26058
+ continue;
26059
+ }
26060
+ const m = /^[A-Za-z0-9][A-Za-z0-9._-]*/.exec(line);
26061
+ if (!m) {
26062
+ ignored++;
26063
+ continue;
26064
+ }
26065
+ const name = m[0];
26066
+ let rest = line.slice(name.length).trimStart();
26067
+ if (rest.startsWith("[")) {
26068
+ const close = rest.indexOf("]");
26069
+ rest = close >= 0 ? rest.slice(close + 1).trimStart() : "";
26070
+ }
26071
+ if (rest !== "" && !/^[=<>!~;@]/.test(rest)) {
26072
+ ignored++;
26073
+ continue;
26074
+ }
26075
+ if (rest.startsWith("@")) {
26076
+ out.push({
26077
+ eco: "PyPI",
26078
+ name,
26079
+ version: null,
26080
+ skip: "not-registry"
26081
+ });
26082
+ continue;
26083
+ }
26084
+ const semi = rest.indexOf(";");
26085
+ let spec = semi >= 0 ? rest.slice(0, semi) : rest;
26086
+ const option = spec.search(/\s-/);
26087
+ if (option >= 0) spec = spec.slice(0, option);
26088
+ spec = spec.replace(/\s+/g, "");
26089
+ const exact = /^===?([^,*=<>!~]+)$/.exec(spec);
26090
+ out.push(exact ? {
26091
+ eco: "PyPI",
26092
+ name,
26093
+ version: exact[1]
26094
+ } : {
26095
+ eco: "PyPI",
26096
+ name,
26097
+ version: null,
26098
+ noVersion: "not-exact"
26099
+ });
26100
+ }
26101
+ if (includes) notes.push(`${includes === 1 ? "A line includes" : `${includes} lines include`} another requirements file (-r or -c). Check that file too.`);
26102
+ if (ignored) notes.push(`Ignored ${ignored === 1 ? "a line" : `${ignored} lines`} that ${ignored === 1 ? "is not a requirement" : "are not requirements"}.`);
26103
+ return out;
26104
+ }
26105
+ function pipfileLock(doc) {
26106
+ const out = [];
26107
+ for (const group of ["default", "develop"]) for (const [name, v] of entries(doc[group])) {
26108
+ if (!isObj(v)) continue;
26109
+ if (v.git || v.path || v.file || v.editable) out.push({
26110
+ eco: "PyPI",
26111
+ name,
26112
+ version: null,
26113
+ skip: "not-registry"
26114
+ });
26115
+ else {
26116
+ const spec = str(v.version);
26117
+ const exact = spec && /^===?([^,*=<>!~\s]+)$/.exec(spec);
26118
+ out.push(exact ? {
26119
+ eco: "PyPI",
26120
+ name,
26121
+ version: exact[1]
26122
+ } : {
26123
+ eco: "PyPI",
26124
+ name,
26125
+ version: null,
26126
+ noVersion: "not-exact"
26127
+ });
26128
+ }
26129
+ }
26130
+ return out;
26131
+ }
26132
+ function tomlString(v) {
26133
+ const q = v[0];
26134
+ if (q !== "\"" && q !== "'") return null;
26135
+ const end = v.indexOf(q, 1);
26136
+ return end > 0 ? v.slice(1, end) : null;
26137
+ }
26138
+ function tomlPackages(text, notes, kind) {
26139
+ const eco = kind === "cargo" ? "crates.io" : "PyPI";
26140
+ const pkgs = [];
26141
+ let cur = null;
26142
+ let sub = "";
26143
+ for (const line of lines(text, notes)) {
26144
+ if (line.startsWith("[")) {
26145
+ const h = line.trim();
26146
+ if (h === "[[package]]") {
26147
+ cur = {
26148
+ name: null,
26149
+ version: null,
26150
+ source: null,
26151
+ type: null
26152
+ };
26153
+ pkgs.push(cur);
26154
+ sub = "";
26155
+ } else if (cur && (h.startsWith("[package.") || h.startsWith("[[package."))) sub = h;
26156
+ else cur = null;
26157
+ continue;
26158
+ }
26159
+ if (!cur) continue;
26160
+ const m = /^([A-Za-z0-9_-]+) *= *(\S.*)$/.exec(line);
26161
+ if (!m) continue;
26162
+ const value = m[2].trim();
26163
+ if (sub === "") {
26164
+ if (m[1] === "name") cur.name = tomlString(value);
26165
+ else if (m[1] === "version") cur.version = tomlString(value);
26166
+ else if (m[1] === "source") cur.source = value;
26167
+ } else if (sub === "[package.source]" && m[1] === "type") cur.type = tomlString(value);
26168
+ }
26169
+ const out = [];
26170
+ for (const p of pkgs) {
26171
+ if (!p.name) continue;
26172
+ let registry;
26173
+ if (kind === "cargo") {
26174
+ const src = p.source === null ? null : tomlString(p.source);
26175
+ registry = src !== null && (src.startsWith("registry+https://github.com/rust-lang/crates.io-index") || src.startsWith("sparse+https://index.crates.io/"));
26176
+ } else if (kind === "uv") registry = p.source === null || /^\{ *registry *=/.test(p.source);
26177
+ else registry = p.type === null || p.type === "legacy";
26178
+ if (!registry) out.push({
26179
+ eco,
26180
+ name: p.name,
26181
+ version: null,
26182
+ skip: "not-registry"
26183
+ });
26184
+ else if (!p.version) out.push({
26185
+ eco,
26186
+ name: p.name,
26187
+ version: null,
26188
+ noVersion: "no-version"
26189
+ });
26190
+ else out.push({
26191
+ eco,
26192
+ name: p.name,
26193
+ version: p.version
26194
+ });
26195
+ }
26196
+ return out;
26197
+ }
26198
+ var goToken = (s) => s.length >= 2 && (s[0] === "\"" || s[0] === "`") && s[s.length - 1] === s[0] ? s.slice(1, -1) : s;
26199
+ var isLocalPath = (p) => p.startsWith("./") || p.startsWith("../") || p === "." || p === ".." || p.startsWith("/") || /^[A-Za-z]:[\\/]/.test(p);
26200
+ function goMod(text, notes) {
26201
+ const requires = [];
26202
+ const replaces = [];
26203
+ let block = null;
26204
+ const handle = (verb, args) => {
26205
+ if (verb === "require" && args.length >= 2) requires.push([goToken(args[0]), args[1]]);
26206
+ else if (verb === "replace") {
26207
+ const arrow = args.indexOf("=>");
26208
+ if (arrow < 1 || arrow + 1 >= args.length) return;
26209
+ replaces.push({
26210
+ from: goToken(args[0]),
26211
+ fromVersion: arrow > 1 ? args[1] : null,
26212
+ to: goToken(args[arrow + 1]),
26213
+ toVersion: args[arrow + 2] ?? null
26214
+ });
26215
+ }
26216
+ };
26217
+ for (const line of lines(text, notes)) {
26218
+ const comment = line.indexOf("//");
26219
+ const t = (comment >= 0 ? line.slice(0, comment) : line).trim();
26220
+ if (t === "") continue;
26221
+ if (block !== null) {
26222
+ if (t === ")") block = null;
26223
+ else handle(block, t.split(/\s+/));
26224
+ continue;
26225
+ }
26226
+ const [verb, ...args] = t.split(/\s+/);
26227
+ if (args.length === 1 && args[0] === "(") block = verb;
26228
+ else handle(verb, args);
26229
+ }
26230
+ const out = requires.map(([path, version]) => {
26231
+ let r;
26232
+ for (const x of replaces) if (x.from === path && (x.fromVersion === null || x.fromVersion === version)) r = x;
26233
+ if (!r) return {
26234
+ eco: "Go",
26235
+ name: path,
26236
+ version
26237
+ };
26238
+ if (isLocalPath(r.to)) return {
26239
+ eco: "Go",
26240
+ name: path,
26241
+ version: null,
26242
+ noVersion: "go-local"
26243
+ };
26244
+ return {
26245
+ eco: "Go",
26246
+ name: r.to,
26247
+ version: r.toVersion ?? version
26248
+ };
26249
+ });
26250
+ out.push({
26251
+ eco: "Go",
26252
+ name: "stdlib",
26253
+ version: null,
26254
+ skip: "go-stdlib"
26255
+ });
26256
+ return out;
26257
+ }
26258
+ function goSum(text, notes) {
26259
+ const out = [];
26260
+ const seen = /* @__PURE__ */ new Set();
26261
+ for (const line of lines(text, notes)) {
26262
+ const [path, version, hash] = line.trim().split(/\s+/);
26263
+ if (!path || !version || !hash || version.endsWith("/go.mod")) continue;
26264
+ const id = `${path} ${version}`;
26265
+ if (seen.has(id)) continue;
26266
+ seen.add(id);
26267
+ out.push({
26268
+ eco: "Go",
26269
+ name: path,
26270
+ version
26271
+ });
26272
+ }
26273
+ notes.push(GO_SUM_NOTE);
26274
+ return out;
26275
+ }
26276
+ /** Platform gems ("nokogiri (1.15.4-x86_64-linux)"): the platform is not part of the version. */
26277
+ var GEM_PLATFORM = /^(?:x86_64|x86|x64|i[3-6]86|aarch64|arm64|arm|armv\d\w*|universal|java|jruby|mingw|mswin|mswin64|darwin|linux|powerpc|ppc64le|s390x|riscv64|wasm32)(?:-|$)/i;
26278
+ function gemfileLock(text, notes) {
26279
+ const out = [];
26280
+ let section = "";
26281
+ let specs = false;
26282
+ for (const line of lines(text, notes)) {
26283
+ if (line.trim() === "") continue;
26284
+ if (line[0] !== " ") {
26285
+ section = line.trim();
26286
+ specs = false;
26287
+ continue;
26288
+ }
26289
+ if (line === " specs:") {
26290
+ specs = true;
26291
+ continue;
26292
+ }
26293
+ if (line[2] !== " ") {
26294
+ specs = false;
26295
+ continue;
26296
+ }
26297
+ if (!specs) continue;
26298
+ const m = /^ {4}([^\s(]+) \(([^)\s]+)\)$/.exec(line);
26299
+ if (!m) continue;
26300
+ let version = m[2];
26301
+ const dash = version.indexOf("-");
26302
+ if (dash > 0 && GEM_PLATFORM.test(version.slice(dash + 1))) version = version.slice(0, dash);
26303
+ out.push(section === "GEM" ? {
26304
+ eco: "RubyGems",
26305
+ name: m[1],
26306
+ version
26307
+ } : {
26308
+ eco: "RubyGems",
26309
+ name: m[1],
26310
+ version: null,
26311
+ skip: "not-registry"
26312
+ });
26313
+ }
26314
+ return out;
26315
+ }
26316
+ function composerLock(doc) {
26317
+ const out = [];
26318
+ for (const list of [doc.packages, doc["packages-dev"]]) {
26319
+ if (!Array.isArray(list)) continue;
26320
+ for (const p of list) {
26321
+ if (!isObj(p)) continue;
26322
+ const name = str(p.name);
26323
+ if (!name) continue;
26324
+ const version = str(p.version);
26325
+ if (isObj(p.dist) && p.dist.type === "path") out.push({
26326
+ eco: "Packagist",
26327
+ name,
26328
+ version: null,
26329
+ skip: "not-registry"
26330
+ });
26331
+ else if (version && (version.startsWith("dev-") || version.endsWith("-dev"))) out.push({
26332
+ eco: "Packagist",
26333
+ name,
26334
+ version: null,
26335
+ skip: "dev-branch"
26336
+ });
26337
+ else out.push(version ? {
26338
+ eco: "Packagist",
26339
+ name,
26340
+ version
26341
+ } : {
26342
+ eco: "Packagist",
26343
+ name,
26344
+ version: null,
26345
+ noVersion: "no-version"
26346
+ });
26347
+ }
26348
+ }
26349
+ return out;
26350
+ }
26351
+ function nugetLock(doc) {
26352
+ const out = [];
26353
+ for (const [, deps] of entries(doc.dependencies)) for (const [name, v] of entries(deps)) {
26354
+ if (!isObj(v)) continue;
26355
+ const version = str(v.resolved);
26356
+ if (v.type === "Project") out.push({
26357
+ eco: "NuGet",
26358
+ name,
26359
+ version: null,
26360
+ skip: "not-registry"
26361
+ });
26362
+ else out.push(version ? {
26363
+ eco: "NuGet",
26364
+ name,
26365
+ version
26366
+ } : {
26367
+ eco: "NuGet",
26368
+ name,
26369
+ version: null,
26370
+ noVersion: "no-version"
26371
+ });
26372
+ }
26373
+ return out;
26374
+ }
26375
+ function gradleLock(text, notes) {
26376
+ const out = [];
26377
+ for (const line of lines(text, notes)) {
26378
+ const m = /^([^#\s:=]+):([^:=\s]+):([^:=\s]+)=/.exec(line);
26379
+ if (m) out.push({
26380
+ eco: "Maven",
26381
+ name: `${m[1]}:${m[2]}`,
26382
+ version: m[3]
26383
+ });
26384
+ }
26385
+ return out;
26386
+ }
26387
+ var BY_FILENAME = [
26388
+ [/^(?:package-lock|npm-shrinkwrap)\.json$/, "npm-lock"],
26389
+ [/^yarn\.lock$/, "yarn"],
26390
+ [/^pnpm-lock\.ya?ml$/, "pnpm"],
26391
+ [/^poetry\.lock$/, "poetry"],
26392
+ [/^uv\.lock$/, "uv"],
26393
+ [/^pipfile\.lock$/, "pipfile"],
26394
+ [/^go\.mod$/, "gomod"],
26395
+ [/^go\.sum$/, "gosum"],
26396
+ [/^cargo\.lock$/, "cargo"],
26397
+ [/^(?:gemfile\.lock|gems\.locked)$/, "gemfile"],
26398
+ [/^composer\.lock$/, "composer"],
26399
+ [/^packages\.lock\.json$/, "nuget"],
26400
+ [/\.lockfile$/, "gradle"],
26401
+ [/^(?:requirements|constraints)[\w.-]*\.txt$/, "requirements"]
26402
+ ];
26403
+ var JSON_PARSERS = /* @__PURE__ */ new Map([
26404
+ ["cyclonedx-json", cyclonedxJson],
26405
+ ["spdx-json", spdxJson],
26406
+ ["npm-lock", npmLock],
26407
+ ["pipfile", pipfileLock],
26408
+ ["composer", composerLock],
26409
+ ["nuget", nugetLock]
26410
+ ]);
26411
+ var TEXT_PARSERS = /* @__PURE__ */ new Map([
26412
+ ["cyclonedx-xml", (text) => cyclonedxXml(text)],
26413
+ ["spdx-tag", spdxTag],
26414
+ ["purl", purlList],
26415
+ ["yarn", yarnLock],
26416
+ ["pnpm", pnpmLock],
26417
+ ["requirements", requirements],
26418
+ ["poetry", (t, n) => tomlPackages(t, n, "poetry")],
26419
+ ["uv", (t, n) => tomlPackages(t, n, "uv")],
26420
+ ["cargo", (t, n) => tomlPackages(t, n, "cargo")],
26421
+ ["gomod", goMod],
26422
+ ["gosum", goSum],
26423
+ ["gemfile", gemfileLock],
26424
+ ["gradle", gradleLock]
26425
+ ]);
26426
+ /** The format a file name alone says (lockfiles; SBOMs are told by content), or null. Also used by the CLI. */
26427
+ function formatOfFilename(filename) {
26428
+ return byFilename(filename);
26429
+ }
26430
+ function byFilename(filename) {
26431
+ const base = filename.split(/[\\/]/).pop()?.toLowerCase().slice(0, 255) ?? "";
26432
+ for (const [re, f] of BY_FILENAME) if (re.test(base)) return f;
26433
+ return null;
26434
+ }
26435
+ /**
26436
+ * SPDX 3 JSON-LD names its context by URL: a string, an array holding it, or an inline object. Only
26437
+ * that shallow shape is read: a context nested a million levels deep must not overflow the stack.
26438
+ */
26439
+ function spdxContext(ctx) {
26440
+ return (Array.isArray(ctx) ? ctx : [ctx]).flatMap((c) => isObj(c) ? [...Object.keys(c), ...Object.values(c)] : [c]).some((c) => typeof c === "string" && c.toLowerCase().includes("spdx"));
26441
+ }
26442
+ function jsonFormat(doc) {
26443
+ if (!isObj(doc)) return null;
26444
+ if (doc.bomFormat === "CycloneDX") return "cyclonedx-json";
26445
+ if (typeof doc.spdxVersion === "string" || Array.isArray(doc["@graph"]) && spdxContext(doc["@context"])) return "spdx-json";
26446
+ if ("lockfileVersion" in doc && (isObj(doc.packages) || isObj(doc.dependencies))) return "npm-lock";
26447
+ if (isObj(doc._meta) && (isObj(doc.default) || isObj(doc.develop))) return "pipfile";
26448
+ if (Array.isArray(doc.packages) && ("content-hash" in doc || "packages-dev" in doc || "_readme" in doc)) return "composer";
26449
+ if (typeof doc.version === "number" && isObj(doc.dependencies)) return "nuget";
26450
+ return null;
26451
+ }
26452
+ /** The format of a text file, from its first 64 KB. */
26453
+ function textFormat(head) {
26454
+ if (head.trimStart().startsWith("<")) return /cyclonedx|<(?:[\w.-]{1,32}:)?purl>/i.test(head) ? "cyclonedx-xml" : null;
26455
+ if (/^SPDXVersion:/m.test(head)) return "spdx-tag";
26456
+ if (/^# yarn lockfile v1|^__metadata:/m.test(head)) return "yarn";
26457
+ if (/^lockfileVersion:/m.test(head)) return "pnpm";
26458
+ if (/^\[\[package\]\]/m.test(head)) {
26459
+ if (/^# This file is automatically @generated by Cargo|^source = "(?:registry|sparse|git)\+|^checksum = "/m.test(head)) return "cargo";
26460
+ if (/^requires-python = |^source = \{ ?(?:registry|editable|virtual|path|directory|git|url) = /m.test(head)) return "uv";
26461
+ return "poetry";
26462
+ }
26463
+ if (/^module\s+\S/m.test(head)) return "gomod";
26464
+ if (/^\S+ v\S+ h1:/m.test(head)) return "gosum";
26465
+ if (/^(?:GEM|GIT|PATH)\r?$/m.test(head) && /^ {2}specs:\r?$/m.test(head)) return "gemfile";
26466
+ if (/^[^\s#:=]+:[^\s:=]+:[^\s:=]+=/m.test(head)) return "gradle";
26467
+ if (/^[ \t]*pkg:[a-z]/im.test(head)) return "purl";
26468
+ if (/^(?:-[rce] |--[a-z]|[A-Za-z0-9][A-Za-z0-9._-]*[ \t]*(?:\[[^\]\n]{0,200}\][ \t]*)?(?:===?|~=|>=|<=|!=|<|>|;|@ ))/m.test(head)) return "requirements";
26469
+ return null;
26470
+ }
26471
+ /** A Maven POM: a <project> element in the POM namespace, before any CycloneDX <bom> element. */
26472
+ function isPom(head) {
26473
+ const project = head.search(/<project[\s>]/);
26474
+ if (project < 0 || !head.includes("maven.apache.org/POM")) return false;
26475
+ const bom = head.search(/<(?:[A-Za-z_][\w.-]{0,31}:)?bom[\s>]/);
26476
+ return bom < 0 || project < bom;
26477
+ }
26478
+ /** A top-level block of a Gradle build script, Groovy or Kotlin; no accepted text format has one. */
26479
+ var GRADLE_BLOCK = /^(?:plugins|dependencies|buildscript|repositories|allprojects|subprojects)[ \t]*\{/m;
26480
+ /** A build manifest the page does not read, from the file name or the content; null otherwise. */
26481
+ function manifest(filename, head, doc) {
26482
+ const base = filename.split(/[\\/]/).pop()?.toLowerCase() ?? "";
26483
+ if (base === "pom.xml" || isPom(head)) return "pom";
26484
+ if (/^build\.gradle(?:\.kts)?$/.test(base) || GRADLE_BLOCK.test(head)) return "gradle";
26485
+ if (base === "package.json" || isObj(doc) && typeof doc.name === "string" && !("lockfileVersion" in doc) && (isObj(doc.dependencies) || isObj(doc.devDependencies))) return "npm";
26486
+ return null;
26487
+ }
26488
+ function parseJson(text) {
26489
+ try {
26490
+ return JSON.parse(text);
26491
+ } catch (e) {
26492
+ throw new ParseError("json", e instanceof RangeError ? "it is nested too deeply" : e instanceof Error ? e.message.replace(/\.$/, "").slice(0, 300) : "unknown error");
26493
+ }
26494
+ }
26495
+ /**
26496
+ * Read `text` as the format `forced` names, or detect it from the file name and the content. Throws
26497
+ * ParseError when the format cannot be told or the file holds no packages. Names longer than
26498
+ * MAX_NAME are dropped (with a note); everything else is kept, including duplicates.
26499
+ */
26500
+ function parse(input, filename = "", forced = null) {
26501
+ const text = input.charCodeAt(0) === 65279 ? input.slice(1) : input;
26502
+ if (text.trim() === "") throw new ParseError("empty");
26503
+ const head = text.slice(0, 65536);
26504
+ const looksJson = /^\s*\{/.test(head);
26505
+ let doc;
26506
+ let format = forced ?? byFilename(filename);
26507
+ const decided = format !== null;
26508
+ if (format === null && looksJson) {
26509
+ doc = parseJson(text);
26510
+ format = jsonFormat(doc);
26511
+ } else if (format === null) format = textFormat(head);
26512
+ if (!decided && (format === null || format === "cyclonedx-xml" || format === "requirements")) {
26513
+ const m = manifest(filename, head, doc);
26514
+ if (m) throw new ParseError("manifest", m);
26515
+ }
26516
+ if (format === null) throw new ParseError("unknown");
26517
+ const notes = [];
26518
+ let components;
26519
+ const fromJson = JSON_PARSERS.get(format);
26520
+ if (fromJson) {
26521
+ doc ??= parseJson(text);
26522
+ components = fromJson(isObj(doc) ? doc : {});
26523
+ } else components = (TEXT_PARSERS.get(format) ?? gradleLock)(text, notes);
26524
+ const kept = components.filter((c) => c.name !== "" && c.name.length <= 512);
26525
+ if (kept.length < components.length) {
26526
+ const n = components.length - kept.length;
26527
+ notes.push(`Skipped ${n === 1 ? "an entry" : `${n} entries`} with no name or a name longer than 512 characters.`);
26528
+ }
26529
+ if (kept.every((c) => c.skip === "go-stdlib")) throw new ParseError("empty");
26530
+ return {
26531
+ format,
26532
+ components: kept,
26533
+ notes
26534
+ };
26535
+ }
26536
+ // cli/src/check.ts
26537
+ /**
26538
+ * Checks files against packages.json with the Check Deps page's own parser and matcher, and turns
26539
+ * the results into findings: one per (CVE, package, file), with the line the package is on.
26540
+ */
26541
+ /** The Check page reads files up to this size. */
26542
+ var MAX_FILE_BYTES = 52428800;
26543
+ var RANK = {
26544
+ exploited: 4,
26545
+ likely: 3,
26546
+ watch: 2,
26547
+ quiet: 1,
26548
+ possible: 0
26549
+ };
26550
+ /**
26551
+ * 1-based line numbers by package, found once per file. The best line names the package as a whole
26552
+ * name (so "lodash" is not found in "lodash.merge") together with its version; then one naming it
26553
+ * alone; then any line holding the text. Lines with a URL are passed over for the first two, as a
26554
+ * download URL repeats the name and version (npm's "resolved").
26555
+ */
26556
+ function lineFinder(text) {
26557
+ const lines = text.split("\n");
26558
+ const cache = /* @__PURE__ */ new Map();
26559
+ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
26560
+ return (name, version) => {
26561
+ const key = `${name}\u0000${version ?? ""}`;
26562
+ if (cache.has(key)) return cache.get(key);
26563
+ const whole = new RegExp(`(?<![\\w.-])${esc(name)}(?![\\w-]|\\.[\\w])`);
26564
+ let both = null;
26565
+ let named = null;
26566
+ let any = null;
26567
+ for (let i = 0; i < lines.length && both === null; i++) {
26568
+ const l = lines[i];
26569
+ if (!l.includes(name)) continue;
26570
+ any ??= i + 1;
26571
+ if (l.includes("://") || !whole.test(l)) continue;
26572
+ named ??= i + 1;
26573
+ if (version && l.includes(version)) both = i + 1;
26574
+ }
26575
+ const at = both ?? named ?? any;
26576
+ cache.set(key, at);
26577
+ return at;
26578
+ };
26579
+ }
26580
+ /**
26581
+ * The lowest version that fixes every matching advisory: the highest of their next fixed versions, by
26582
+ * the ecosystem's own version order. Null when an advisory names no fix (the package needs another
26583
+ * way out), or a fix cannot be compared.
26584
+ */
26585
+ function lowestFix(pkg) {
26586
+ const c = COMPARATORS[pkg.eco];
26587
+ let best = null;
26588
+ for (const a of pkg.advisories) {
26589
+ if (a.fixedIn === null) return null;
26590
+ const key = c.parse(a.fixedIn);
26591
+ if (key === null) return null;
26592
+ if (best === null || c.cmp(key, best.key) > 0) best = {
26593
+ key,
26594
+ text: a.fixedIn
26595
+ };
26596
+ }
26597
+ return best?.text ?? null;
26598
+ }
26599
+ /** Group order for findings: Exploited first, possibly affected last; within a group by score, then CVE. */
26600
+ var compareFindings = (a, b) => RANK[b.group] - RANK[a.group] || b.row.s - a.row.s || a.row.id.localeCompare(b.row.id) || a.file.localeCompare(b.file) || a.pkg.name.localeCompare(b.pkg.name);
26601
+ /** Check `files` (relative to `cwd`) at evidence bar `knob`. Reads files; no network. */
26602
+ function checkFiles(files, cwd, index, knob = 50, older = {
26603
+ olderIds: /* @__PURE__ */ new Set(),
26604
+ olderError: null
26605
+ }) {
26606
+ const reports = [];
26607
+ const findings = [];
26608
+ const notes = [];
26609
+ let packages = 0;
26610
+ let checked = 0;
26611
+ for (const path of files) {
26612
+ const abs = resolve(cwd, path);
26613
+ let text;
26614
+ try {
26615
+ if (statSync(abs).size > 52428800) {
26616
+ reports.push({
26617
+ path,
26618
+ format: null,
26619
+ error: `larger than ${MAX_FILE_BYTES / 1024 / 1024} MB`,
26620
+ result: null
26621
+ });
26622
+ continue;
26623
+ }
26624
+ text = readFileSync(abs, "utf8");
26625
+ } catch (e) {
26626
+ reports.push({
26627
+ path,
26628
+ format: null,
26629
+ error: `could not be read: ${e.message}`,
26630
+ result: null
26631
+ });
26632
+ continue;
26633
+ }
26634
+ let result;
26635
+ try {
26636
+ result = checkComponents(parse(text, path), index);
26637
+ } catch (e) {
26638
+ reports.push({
26639
+ path,
26640
+ format: null,
26641
+ error: e instanceof ParseError ? e.message : `could not be read: ${e.message}`,
26642
+ result: null
26643
+ });
26644
+ continue;
26645
+ }
26646
+ reports.push({
26647
+ path,
26648
+ format: result.format,
26649
+ error: null,
26650
+ result
26651
+ });
26652
+ packages += result.distinct;
26653
+ checked += result.checked;
26654
+ for (const n of result.notes) notes.push({
26655
+ file: path,
26656
+ text: n
26657
+ });
26658
+ const line = lineFinder(text);
26659
+ for (const [group, hits] of groupByTier(result.cves, knob)) for (const hit of hits) for (const pkg of hit.packages) {
26660
+ const g = group !== "possible" && pkg.unchecked !== null ? "possible" : group;
26661
+ findings.push({
26662
+ group: g,
26663
+ row: hit.row,
26664
+ pkg,
26665
+ file: path,
26666
+ line: line(pkg.name, pkg.version),
26667
+ fixedIn: lowestFix(pkg),
26668
+ tracked: !older.olderIds.has(hit.row.id)
26669
+ });
26670
+ }
26671
+ }
26672
+ findings.sort(compareFindings);
26673
+ return {
26674
+ generatedAt: index.generated_at,
26675
+ knob,
26676
+ files: reports,
26677
+ findings,
26678
+ packages,
26679
+ checked,
26680
+ indexCves: index.cves.rows.length,
26681
+ ecosystemsDown: index.sources.filter((s) => !s.ok).map((s) => s.ecosystem),
26682
+ coverage: {
26683
+ tracked: index.cves.rows.length - older.olderIds.size,
26684
+ older: older.olderIds.size,
26685
+ advisories: index.distinct?.advisories ?? 0,
26686
+ olderError: older.olderError
26687
+ },
26688
+ notes
26689
+ };
26690
+ }
26691
+ /** Distinct CVEs per group. */
26692
+ function countByGroup(findings) {
26693
+ const out = {
26694
+ exploited: /* @__PURE__ */ new Set(),
26695
+ likely: /* @__PURE__ */ new Set(),
26696
+ watch: /* @__PURE__ */ new Set(),
26697
+ quiet: /* @__PURE__ */ new Set(),
26698
+ possible: /* @__PURE__ */ new Set()
26699
+ };
26700
+ for (const f of findings) out[f.group].add(f.row.id);
26701
+ return {
26702
+ exploited: out.exploited.size,
26703
+ likely: out.likely.size,
26704
+ watch: out.watch.size,
26705
+ quiet: out.quiet.size,
26706
+ possible: out.possible.size
26707
+ };
26708
+ }
26709
+ // cli/src/discover.ts
26710
+ /**
26711
+ * Finds the lockfiles and SBOMs to check under the paths given on the command line.
26712
+ *
26713
+ * A file named on the command line is always read (its format is told by its content if its name
26714
+ * says nothing). A directory is walked for the file names the Check Deps page knows, plus common
26715
+ * SBOM names, skipping dependency, build and VCS directories. The walk never follows symbolic
26716
+ * links, so a link cannot lead it out of the repository or round in a loop.
26717
+ */
26718
+ /** Directories never walked: installed dependencies, build output, virtualenvs, VCS metadata. */
26719
+ var SKIP_DIRS = /* @__PURE__ */ new Set([
26720
+ ".git",
26721
+ ".hg",
26722
+ ".svn",
26723
+ "node_modules",
26724
+ "bower_components",
26725
+ "jspm_packages",
26726
+ "vendor",
26727
+ "Pods",
26728
+ ".venv",
26729
+ "venv",
26730
+ "__pycache__",
26731
+ ".tox",
26732
+ ".nox",
26733
+ ".gradle",
26734
+ ".terraform",
26735
+ "dist",
26736
+ "build",
26737
+ "out",
26738
+ "target",
26739
+ "coverage",
26740
+ ".next",
26741
+ ".nuxt",
26742
+ ".cache"
26743
+ ]);
26744
+ /** CycloneDX and SPDX files as tools usually name them. */
26745
+ var SBOM_NAME = /^(?:bom\.(?:json|xml)|sbom(?:[\w.-]{0,64})?\.json|[\w.-]{1,128}\.(?:cdx\.(?:json|xml)|spdx(?:\.json)?))$/i;
26746
+ /** True when the walk picks a file of this name. */
26747
+ var isCheckable = (name) => formatOfFilename(name) !== null || SBOM_NAME.test(name);
26748
+ /** The files to check under `paths` (relative to `cwd`). */
26749
+ function discover(paths, cwd, limits = {
26750
+ depth: 12,
26751
+ files: 500
26752
+ }) {
26753
+ const files = [];
26754
+ const seen = /* @__PURE__ */ new Set();
26755
+ const missing = [];
26756
+ let truncated = false;
26757
+ const add = (p) => {
26758
+ if (seen.has(p)) return;
26759
+ if (files.length >= limits.files) {
26760
+ truncated = true;
26761
+ return;
26762
+ }
26763
+ seen.add(p);
26764
+ files.push(p);
26765
+ };
26766
+ const walk = (dir, depth) => {
26767
+ if (depth > limits.depth || truncated) return;
26768
+ let entries;
26769
+ try {
26770
+ entries = readdirSync(dir, { withFileTypes: true });
26771
+ } catch {
26772
+ return;
26773
+ }
26774
+ entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
26775
+ for (const e of entries) if (e.isFile() && isCheckable(e.name)) add(join(dir, e.name));
26776
+ for (const e of entries) if (e.isDirectory() && !SKIP_DIRS.has(e.name)) walk(join(dir, e.name), depth + 1);
26777
+ };
26778
+ for (const raw of paths.length ? paths : ["."]) {
26779
+ const p = resolve(cwd, raw);
26780
+ let st;
26781
+ try {
26782
+ st = lstatSync(p).isSymbolicLink() ? statSync(p) : lstatSync(p);
26783
+ } catch {
26784
+ missing.push(raw);
26785
+ continue;
26786
+ }
26787
+ if (st.isDirectory()) walk(p, 0);
26788
+ else if (st.isFile()) add(p);
26789
+ }
26790
+ const goMods = new Set(files.filter((f) => basename(f) === "go.mod").map(dirname));
26791
+ const skipped = files.filter((f) => basename(f) === "go.sum" && goMods.has(dirname(f)));
26792
+ const kept = files.filter((f) => !skipped.includes(f));
26793
+ const rel = (f) => {
26794
+ const r = relative(cwd, f);
26795
+ return r === "" ? basename(f) : r.startsWith("..") ? f : r.split(sep).join("/");
26796
+ };
26797
+ return {
26798
+ files: kept.map(rel),
26799
+ skipped: skipped.map(rel),
26800
+ missing,
26801
+ truncated
26802
+ };
26803
+ }
26804
+ var cveUrl = (id) => `${BRAND.siteUrl}/cve/${encodeURIComponent(id)}`;
26805
+ /** Where a finding's CVE is explained: its CVE page when tracked, else its record on cve.org (older CVEs have no page). */
26806
+ var findingUrl = (f) => f.tracked ? cveUrl(f.row.id) : `https://www.cve.org/CVERecord?id=${encodeURIComponent(f.row.id)}`;
24705
26807
  // mcp/src/tools.ts
24706
26808
  /**
24707
- * The six MCP tools as plain functions over the published files: (call, args, now) -> result.
26809
+ * The MCP tools as plain functions over the published files: (call, args, now) -> result.
24708
26810
  * No SDK imports, so they are unit-tested with a fake fetch. Every result starts with `data`, which
24709
26811
  * names the run and every file the answer came from (McpData in shared/contract.ts).
24710
26812
  */
@@ -24717,10 +26819,17 @@ var LIMITS = {
24717
26819
  offset: 1e5,
24718
26820
  queryWords: 8,
24719
26821
  withinDays: 60,
24720
- overdueDays: 14
26822
+ overdueDays: 14,
26823
+ names: 200,
26824
+ nameChars: 80,
26825
+ perName: 25
24721
26826
  };
26827
+ /** Bytes of JSON check_inventory answers with at most (about 17,000 tokens); the least urgent CVEs are left out to fit. */
26828
+ var INVENTORY_BUDGET = 61440;
24722
26829
  var DAY_MS = 864e5;
24723
26830
  var TITLE_MAX = 160;
26831
+ /** Pipeline event details run to about 120 characters; a mirror may send more. */
26832
+ var DETAIL_MAX = 300;
24724
26833
  /** UTC date or date-time: anchored, no nested quantifiers; applied after a length cap of 30. */
24725
26834
  var DATE_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?Z)?$/;
24726
26835
  /** Milliseconds for a DATE_RE string, or NaN when it does not match or does not exist (2026-02-30). */
@@ -24886,7 +26995,7 @@ async function listSignal(call, a, now) {
24886
26995
  const since = a.published_since === void 0 ? null : dateArg("published_since", a.published_since);
24887
26996
  const vendor = a.vendor?.trim().toLowerCase() ?? "";
24888
26997
  const file = knob >= 35 && tiers.every((t) => t === "exploited" || t === "likely") ? "signal.json" : "index.json";
24889
- const { rows } = await call.file(file, parse.rows);
26998
+ const { rows } = await call.file(file, parse$1.rows);
24890
26999
  const want = new Set(tiers);
24891
27000
  const p = page(rows.filter((r) => want.has(tierFor(r.s, r.x === 1, r.w === 1, knob)) && (!vendor || `${r.v} ${r.p}`.toLowerCase().includes(vendor)) && (since === null || Date.parse(r.pub) >= since) && (!a.kev_only || r.k === 1)).sort(byScore), a.offset, a.limit ?? 25);
24892
27001
  return {
@@ -24899,7 +27008,7 @@ async function listSignal(call, a, now) {
24899
27008
  };
24900
27009
  }
24901
27010
  async function kevDue(call, a, now) {
24902
- const kev = await call.file("kev.json", parse.kev);
27011
+ const kev = await call.file("kev.json", parse$1.kev);
24903
27012
  const day = (ms) => new Date(ms).toISOString().slice(0, 10);
24904
27013
  const today = day(now);
24905
27014
  const from = day(Date.parse(today) - (a.overdue_days ?? 7) * DAY_MS);
@@ -24929,7 +27038,7 @@ async function kevDue(call, a, now) {
24929
27038
  };
24930
27039
  }
24931
27040
  async function wokeUp(call, a, now) {
24932
- const woke = await call.file("woke.json", parse.woke);
27041
+ const woke = await call.file("woke.json", parse$1.woke);
24933
27042
  const knob = (await call.meta()).knob_default;
24934
27043
  const sinceMs = a.since === void 0 ? Date.parse(woke.generated_at) - 7 * DAY_MS : dateArg("since", a.since);
24935
27044
  const since = new Date(sinceMs).toISOString();
@@ -24956,7 +27065,7 @@ async function wokeUp(call, a, now) {
24956
27065
  async function receipts(call, a, now) {
24957
27066
  const id = a.id?.trim().toUpperCase();
24958
27067
  if (id !== void 0 && !CVE_ID_RE.test(id)) throw new InputError(MCP_MSG.notCveId);
24959
- const r = await call.file("receipts.json", parse.receipts);
27068
+ const r = await call.file("receipts.json", parse$1.receipts);
24960
27069
  const { items, uncounted, gaps: _gaps, ...forward } = r.forward;
24961
27070
  const b = r.backtest;
24962
27071
  const withRow = (x) => x ? {
@@ -25000,7 +27109,7 @@ async function searchCves(call, a, now) {
25000
27109
  if (terms.length === 0) throw new InputError("query needs at least one word.");
25001
27110
  if (terms.length > LIMITS.queryWords) throw new InputError(MCP_MSG.tooManyWords(LIMITS.queryWords));
25002
27111
  const tiers = a.tiers?.length ? new Set(a.tiers) : null;
25003
- const { rows, hay } = await call.file("index.json", parse.rows);
27112
+ const { rows, hay } = await call.file("index.json", parse$1.rows);
25004
27113
  const meta = await call.meta();
25005
27114
  const hits = [];
25006
27115
  for (let i = 0; i < rows.length; i++) {
@@ -25018,14 +27127,309 @@ async function searchCves(call, a, now) {
25018
27127
  items: p.items.map((r) => mcpRow(r, knob))
25019
27128
  };
25020
27129
  }
27130
+ /** Control, format and lone surrogate characters: no vendor name has them, and JSON escapes each in 6 bytes. */
27131
+ var ODD_CHAR_RE = /[\p{Cc}\p{Cf}\p{Cs}]/u;
27132
+ /** Names as the watchlist keeps them (shared/watch.ts): normalized, deduped, 1 to WATCH_NAME_MAX characters. */
27133
+ function watchNames(raw) {
27134
+ const out = [];
27135
+ for (const s of raw) {
27136
+ const n = normalizeName(s);
27137
+ if (!n || n.length > LIMITS.nameChars) throw new InputError(MCP_MSG.badName(LIMITS.nameChars));
27138
+ if (ODD_CHAR_RE.test(n)) throw new InputError(MCP_MSG.oddName);
27139
+ if (!out.includes(n)) out.push(n);
27140
+ }
27141
+ if (out.length > LIMITS.names) throw new InputError(`names takes at most ${LIMITS.names} names.`);
27142
+ if (Buffer.byteLength(JSON.stringify(out)) > 20480) throw new InputError(MCP_MSG.namesTooLong);
27143
+ return out;
27144
+ }
27145
+ var TIER_RANK = {
27146
+ exploited: 0,
27147
+ likely: 1,
27148
+ watch: 2,
27149
+ quiet: 3
27150
+ };
27151
+ /** Soonest KEV due date first, none last. */
27152
+ var byDue = (a, b) => a === b ? 0 : a === null ? 1 : b === null ? -1 : a.localeCompare(b);
27153
+ /** Most urgent first: tier, then the soonest KEV due date, then score, newest, id. */
27154
+ var byUrgency = (a, b) => TIER_RANK[a.tier] - TIER_RANK[b.tier] || byDue(a.kev_due, b.kev_due) || b.score - a.score || b.published.localeCompare(a.published) || a.id.localeCompare(b.id);
27155
+ async function checkInventory(call, a, now) {
27156
+ const knob = a.knob ?? 50;
27157
+ const names = watchNames(a.names);
27158
+ const tiers = a.tiers?.length ? [...new Set(a.tiers)] : [...TIERS];
27159
+ const want = new Set(tiers);
27160
+ const { rows } = await call.file("index.json", parse$1.rows);
27161
+ const woke = await call.file("woke.json", parse$1.woke);
27162
+ const seen = new Set(rows.map((r) => r.id));
27163
+ const tracked = [...rows, ...woke.items.map((i) => i.row).filter((r) => !seen.has(r.id))];
27164
+ const matched = new Map(names.map((n) => [n, []]));
27165
+ for (const r of tracked) {
27166
+ if (!matchesName(names, r.v, r.p)) continue;
27167
+ for (const n of names) if (matchesName([n], r.v, r.p)) matched.get(n).push(r);
27168
+ }
27169
+ const all = names.map((name) => {
27170
+ const rs = matched.get(name);
27171
+ const items = rs.map((r) => {
27172
+ const m = mcpRow(r, knob);
27173
+ return {
27174
+ id: m.id,
27175
+ tier: m.tier,
27176
+ verdict: VERDICT[m.tier],
27177
+ score: m.score,
27178
+ kev_due: m.kev_due,
27179
+ in_kev: m.in_kev,
27180
+ exploited: m.exploited,
27181
+ weaponized: m.weaponized,
27182
+ published: m.published,
27183
+ vendor: m.vendor,
27184
+ product: m.product,
27185
+ title: m.title
27186
+ };
27187
+ }).filter((i) => want.has(i.tier)).sort(byUrgency);
27188
+ const slug = slugify(name);
27189
+ return {
27190
+ name,
27191
+ feed: slug ? `${BRAND.siteUrl}/feeds/v/${slug}.xml` : null,
27192
+ matched: rs.length,
27193
+ items
27194
+ };
27195
+ });
27196
+ const meta = await call.meta();
27197
+ const data = await dataBlock(call, now);
27198
+ const scope = `CVEs published in the ${meta.window.days}-day window (index.json) and old CVEs that woke up (woke.json). A name matches a CVE whose vendor or product equals it, ignoring case and extra spaces. Older CISA KEV CVEs are not listed here: use kev_due or get_verdict.`;
27199
+ const asked = a.per_name ?? 10;
27200
+ const queue = all.flatMap(({ items }, n) => items.slice(0, asked).map((item, k) => ({
27201
+ item,
27202
+ k,
27203
+ n
27204
+ }))).sort((x, y) => byUrgency(x.item, y.item) || x.k - y.k || x.n - y.n);
27205
+ const build = (shown) => {
27206
+ const count = new Array(all.length).fill(0);
27207
+ for (const { n } of queue.slice(0, shown)) count[n]++;
27208
+ return {
27209
+ data,
27210
+ knob,
27211
+ tiers,
27212
+ per_name: asked,
27213
+ note: shown < queue.length ? MCP_MSG.inventoryCut(shown, queue.length) : null,
27214
+ scope,
27215
+ names: all.map(({ name, feed, matched, items }, n) => {
27216
+ const kept = items.slice(0, count[n]);
27217
+ return {
27218
+ name,
27219
+ feed,
27220
+ matched,
27221
+ total: items.length,
27222
+ omitted: items.length - kept.length,
27223
+ no_match: matched === 0,
27224
+ items: kept
27225
+ };
27226
+ })
27227
+ };
27228
+ };
27229
+ const fits = (r) => Buffer.byteLength(JSON.stringify(r)) <= INVENTORY_BUDGET;
27230
+ let out = build(queue.length);
27231
+ if (!fits(out)) {
27232
+ let lo = 0;
27233
+ let hi = queue.length - 1;
27234
+ out = build(0);
27235
+ if (!fits(out)) throw new InputError(MCP_MSG.namesTooLong);
27236
+ while (lo < hi) {
27237
+ const mid = Math.ceil((lo + hi) / 2);
27238
+ const r = build(mid);
27239
+ if (fits(r)) [lo, out] = [mid, r];
27240
+ else hi = mid - 1;
27241
+ }
27242
+ }
27243
+ return out;
27244
+ }
27245
+ /** An event as the agent gets it: only EventItem's fields, upstream text on one line and capped. */
27246
+ function eventOut(e) {
27247
+ return {
27248
+ id: e.id,
27249
+ at: e.at,
27250
+ type: e.type,
27251
+ cve: e.cve,
27252
+ vendor: cut(oneLine(e.vendor), TITLE_MAX),
27253
+ product: cut(oneLine(e.product), TITLE_MAX),
27254
+ tier_before: e.tier_before,
27255
+ tier_after: e.tier_after,
27256
+ score: e.score,
27257
+ title: cut(oneLine(e.title), TITLE_MAX),
27258
+ via: e.via,
27259
+ url: e.url,
27260
+ detail: cut(oneLine(e.detail), DETAIL_MAX),
27261
+ backfill: e.backfill
27262
+ };
27263
+ }
27264
+ async function changesSince(call, a, now) {
27265
+ const sinceMs = dateArg("since", a.since);
27266
+ const after = a.since.length === 10 ? (ms) => ms >= sinceMs : (ms) => ms > sinceMs;
27267
+ const untilMs = a.until === void 0 ? null : dateArg("until", a.until);
27268
+ const names = a.names?.length ? watchNames(a.names) : null;
27269
+ const types = a.types?.length ? [...new Set(a.types)] : null;
27270
+ const ev = await call.file("events.json", parse$1.events);
27271
+ const genMs = Date.parse(ev.generated_at);
27272
+ const to = new Date(genMs).toISOString();
27273
+ const from = (/* @__PURE__ */ new Date(genMs - ev.days * DAY_MS)).toISOString();
27274
+ if (sinceMs < Date.parse(from)) throw new InputError(MCP_MSG.beforeLog(from, to, ev.days));
27275
+ const want = types && new Set(types);
27276
+ const p = page(ev.items.filter((e) => {
27277
+ const at = Date.parse(e.at);
27278
+ return after(at) && (untilMs === null || at <= untilMs) && (!want || want.has(e.type)) && (!names || matchesName(names, e.vendor, e.product));
27279
+ }).sort((x, y) => Date.parse(y.at) - Date.parse(x.at)), a.offset, a.limit ?? 25);
27280
+ return {
27281
+ data: await dataBlock(call, now),
27282
+ since: new Date(sinceMs).toISOString(),
27283
+ until: untilMs === null ? null : new Date(untilMs).toISOString(),
27284
+ log: {
27285
+ from,
27286
+ to,
27287
+ days: ev.days,
27288
+ previous_at: ev.previous_at ?? null,
27289
+ max_items: ev.max_items,
27290
+ capped: ev.items.length >= ev.max_items
27291
+ },
27292
+ next_since: new Date(untilMs === null ? genMs : Math.min(untilMs, genMs)).toISOString(),
27293
+ names,
27294
+ types,
27295
+ ...p,
27296
+ items: p.items.map(eventOut)
27297
+ };
27298
+ }
27299
+ /** Bytes of JSON check_dependencies answers with at most (about 17,000 tokens); the least urgent findings are left out to fit. */
27300
+ var DEPENDENCIES_BUDGET = 61440;
27301
+ var DEPENDENCY_LIMITS = {
27302
+ paths: 20,
27303
+ pathChars: 1024
27304
+ };
27305
+ /** check_dependencies reads up to two larger files (packages-older.json is about 2 MB gzip): a longer deadline than other tools. */
27306
+ var DEPENDENCIES_TIMEOUT_MS = 3e4;
27307
+ /**
27308
+ * Paths inside `root` to hand to discover(): each must resolve, through any symbolic link, to a place
27309
+ * inside root, and a file must have a lockfile or SBOM name. That keeps an agent that was talked into
27310
+ * it from reading other files: nothing else is opened, and file errors never quote file content.
27311
+ */
27312
+ function dependencyPaths(raw, root) {
27313
+ const realRoot = realpathSync(root);
27314
+ const inside = (p) => {
27315
+ const r = relative(realRoot, p);
27316
+ return r === "" || !r.startsWith("..") && !isAbsolute(r);
27317
+ };
27318
+ return raw.map((p) => {
27319
+ const abs = resolve(root, p);
27320
+ let real;
27321
+ try {
27322
+ real = realpathSync(abs);
27323
+ } catch {
27324
+ return p;
27325
+ }
27326
+ if (!inside(real)) throw new InputError(MCP_MSG.outsideRoot(p));
27327
+ if (statSync(real).isFile() && !isCheckable(basename(real))) throw new InputError(MCP_MSG.notCheckable(p));
27328
+ return relative(root, abs) || ".";
27329
+ });
27330
+ }
27331
+ /** A file error as the agent sees it: the parser's fixed messages, and never a quote from the file. */
27332
+ function fileError(e) {
27333
+ if (e === null) return null;
27334
+ if (e.startsWith("This looks like JSON")) return "This looks like JSON, but it could not be read.";
27335
+ return e.startsWith("could not be read") ? "could not be read" : e;
27336
+ }
27337
+ var groupRank = {
27338
+ exploited: 0,
27339
+ likely: 1,
27340
+ watch: 2,
27341
+ quiet: 3,
27342
+ possible: 4
27343
+ };
27344
+ async function checkDependencies(call, a, now, root = process.cwd()) {
27345
+ const knob = a.knob ?? 50;
27346
+ const found = discover(dependencyPaths(a.paths?.length ? a.paths : ["."], root), root);
27347
+ if (!found.files.length) throw new InputError(MCP_MSG.noDependencyFiles((a.paths?.length ? a.paths : ["."]).join(", ")));
27348
+ const tracked = await call.file("packages.json", parse$1.packages);
27349
+ let older = null;
27350
+ let olderMissing = null;
27351
+ try {
27352
+ older = await call.file("packages-older.json", parse$1.packages);
27353
+ } catch (e) {
27354
+ if (!(e instanceof DataError)) throw e;
27355
+ olderMissing = e instanceof DataUnavailable ? "packages-older.json is not published in this data" : e.message;
27356
+ }
27357
+ const trackedIds = new Set(rowsFromTable(tracked.cves).map((r) => r.id));
27358
+ const olderIds = new Set(older ? rowsFromTable(older.cves).map((r) => r.id).filter((id) => !trackedIds.has(id)) : []);
27359
+ const report = checkFiles(found.files, root, mergePackageFiles(tracked, older), knob, {
27360
+ olderIds,
27361
+ olderError: olderMissing
27362
+ });
27363
+ const counts = countByGroup(report.findings);
27364
+ const items = report.findings.filter((f) => a.include_quiet || f.group !== "quiet").sort((x, y) => groupRank[x.group] - groupRank[y.group]).map((f) => ({
27365
+ cve: f.row.id,
27366
+ group: f.group,
27367
+ verdict: f.group === "possible" ? "Possibly affected: the version in the file could not be compared with the advisory." : VERDICT[f.group],
27368
+ score: f.row.s,
27369
+ in_kev: f.row.k === 1,
27370
+ kev_due: f.row.kd,
27371
+ exploited: f.row.x === 1,
27372
+ weaponized: f.row.w === 1,
27373
+ ecosystem: f.pkg.eco,
27374
+ package: cut(oneLine(f.pkg.name), TITLE_MAX),
27375
+ named: f.pkg.named ? cut(oneLine(f.pkg.named), TITLE_MAX) : null,
27376
+ version: f.pkg.version === null ? null : cut(oneLine(f.pkg.version), 64),
27377
+ fixed_in: f.fixedIn,
27378
+ advisories: f.pkg.advisories.map((x) => x.id),
27379
+ file: f.file,
27380
+ line: f.line,
27381
+ tracked: f.tracked,
27382
+ url: findingUrl(f),
27383
+ title: cut(oneLine(f.row.t), TITLE_MAX)
27384
+ }));
27385
+ const data = await dataBlock(call, now);
27386
+ const scope = `${olderMissing === null ? `Every CVE that one of ${report.coverage.advisories.toLocaleString("en-US")} OSV.dev advisories ties to a package version, in npm, PyPI, Maven, Go, crates.io, RubyGems, Packagist and NuGet` : "Tracked CVEs only"}. Not checked: advisories without a CVE ID (malware reports among them), other ecosystems (deb, rpm, apk, containers), and bugs no advisory names yet. Tracked CVEs (tracked: true) have a page and get_verdict knows them; older ones link to cve.org.`;
27387
+ const build = (n) => ({
27388
+ data,
27389
+ knob,
27390
+ scope,
27391
+ note: [n < items.length ? MCP_MSG.dependenciesCut(n, items.length) : null, olderMissing === null ? null : MCP_MSG.olderMissing(olderMissing)].filter(Boolean).join(" ") || null,
27392
+ files: report.files.map((f) => ({
27393
+ path: f.path,
27394
+ format: f.format,
27395
+ packages: f.result?.distinct ?? 0,
27396
+ error: fileError(f.error)
27397
+ })),
27398
+ counts,
27399
+ packages_checked: report.checked,
27400
+ coverage: {
27401
+ tracked_cves: report.coverage.tracked,
27402
+ older_cves: report.coverage.older,
27403
+ advisories: report.coverage.advisories,
27404
+ older_missing: olderMissing
27405
+ },
27406
+ total: items.length,
27407
+ omitted: items.length - n,
27408
+ items: items.slice(0, n)
27409
+ });
27410
+ const fits = (r) => Buffer.byteLength(JSON.stringify(r)) <= DEPENDENCIES_BUDGET;
27411
+ let out = build(items.length);
27412
+ if (!fits(out)) {
27413
+ let lo = 0;
27414
+ let hi = items.length - 1;
27415
+ out = build(0);
27416
+ while (lo < hi) {
27417
+ const mid = Math.ceil((lo + hi) / 2);
27418
+ const r = build(mid);
27419
+ if (fits(r)) [lo, out] = [mid, r];
27420
+ else hi = mid - 1;
27421
+ }
27422
+ }
27423
+ return out;
27424
+ }
25021
27425
  // mcp/src/server.ts
25022
27426
  /**
25023
- * The MCP server factory: one McpServer with the six read-only tools over a DataClient. It knows
27427
+ * The MCP server factory: one McpServer with the read-only tools over a DataClient. It knows
25024
27428
  * nothing about transports, so the same factory serves stdio (mcp/src/stdio.ts) and would serve a
25025
27429
  * web-standard handler (createMcpHandler) unchanged. Inputs are bounded by zod schemas; every
25026
27430
  * failure comes back as a tool result with isError: true, never as a thrown protocol error.
25027
27431
  */
25028
- /** Every tool reads one published dataset and changes nothing. */
27432
+ /** Every tool reads published data (check_dependencies also the project's lockfiles) and changes nothing. */
25029
27433
  var ANNOTATIONS = {
25030
27434
  readOnlyHint: true,
25031
27435
  destructiveHint: false,
@@ -25036,8 +27440,10 @@ var tiers = array(_enum(TIERS)).min(1).max(4);
25036
27440
  var knob = number$1().int().min(30).max(80).optional().describe(`The evidence bar: the minimum score (out of 100) to flag a CVE as likely exploited next (the Likely next tier), 30 to 80. Default 50, as on the site. Exploited CVEs and those with a Metasploit module or Nuclei template pass at any value.`);
25037
27441
  var limit = (def) => number$1().int().min(1).max(LIMITS.page).optional().describe(`Items per page, 1 to ${LIMITS.page}. Default ${def}.`);
25038
27442
  var offset = number$1().int().min(0).max(LIMITS.offset).optional().describe("Items to skip: next_offset of the previous page.");
25039
- var date = (what) => string().max(30).regex(DATE_RE, "expected a UTC date (2026-10-01) or date-time (2026-10-01T06:00Z)").refine((s) => !Number.isNaN(parseUtc(s)), "not a real date").optional().describe(what);
27443
+ var utc = string().max(30).regex(DATE_RE, "expected a UTC date (2026-10-01) or date-time (2026-10-01T06:00Z)").refine((s) => !Number.isNaN(parseUtc(s)), "not a real date");
27444
+ var date = (what) => utc.optional().describe(what);
25040
27445
  var cveId = string().min(1).max(32);
27446
+ var names = array(string().min(1).max(LIMITS.nameChars * 2)).min(1).max(LIMITS.names);
25041
27447
  var SCHEMAS = {
25042
27448
  get_verdict: object({
25043
27449
  ids: array(cveId).min(1).max(LIMITS.ids).describe("CVE IDs, e.g. [\"CVE-2026-96951\"]."),
@@ -25072,6 +27478,25 @@ var SCHEMAS = {
25072
27478
  knob,
25073
27479
  limit: limit(20),
25074
27480
  offset
27481
+ }),
27482
+ check_inventory: object({
27483
+ names: names.describe(`Vendor or product names, each up to ${LIMITS.nameChars} characters, e.g. ["fortinet","vmware"].`),
27484
+ tiers: tiers.optional().describe("Default: all four."),
27485
+ knob: knob.describe(`The evidence bar, 30 to 80 (default 50), as in get_verdict.`),
27486
+ per_name: number$1().int().min(1).max(LIMITS.perName).optional().describe(`CVEs per name, 1 to ${LIMITS.perName} (default 10). If the answer would be too large, the least urgent across all names are left out, with a note.`)
27487
+ }),
27488
+ check_dependencies: object({
27489
+ paths: array(string().min(1).max(DEPENDENCY_LIMITS.pathChars)).min(1).max(DEPENDENCY_LIMITS.paths).optional().describe(`Files or folders inside the working directory, 1 to ${DEPENDENCY_LIMITS.paths}. Default ["."].`),
27490
+ knob: knob.describe(`The evidence bar, 30 to 80 (default 50), as in get_verdict.`),
27491
+ include_quiet: boolean().optional().describe("Also list Quiet findings (always counted). Default false.")
27492
+ }),
27493
+ changes_since: object({
27494
+ since: utc.describe("Events after this UTC date-time (next_since of an earlier answer), or from 00:00Z of this date, within the log's 7 days."),
27495
+ until: date("Only events at or before this time. On later pages, pass next_since of the first page."),
27496
+ names: names.optional().describe("Only events whose vendor or product is one of these names."),
27497
+ types: array(_enum(EVENT_TYPES)).min(1).max(EVENT_TYPES.length).optional().describe(`Only these event types: ${EVENT_TYPES.join(", ")}.`),
27498
+ limit: limit(25),
27499
+ offset
25075
27500
  })
25076
27501
  };
25077
27502
  var HANDLERS = {
@@ -25080,7 +27505,10 @@ var HANDLERS = {
25080
27505
  kev_due: kevDue,
25081
27506
  woke_up: wokeUp,
25082
27507
  receipts,
25083
- search_cves: searchCves
27508
+ search_cves: searchCves,
27509
+ check_inventory: checkInventory,
27510
+ check_dependencies: checkDependencies,
27511
+ changes_since: changesSince
25084
27512
  };
25085
27513
  /** structuredContent plus the same JSON as one text block (spec: SHOULD), or an isError text. */
25086
27514
  function answer(value) {
@@ -25129,7 +27557,7 @@ function createServer(dc) {
25129
27557
  annotations: ANNOTATIONS
25130
27558
  }, async (args) => {
25131
27559
  try {
25132
- return answer(await dc.run((call) => handler(call, args, dc.now())));
27560
+ return answer(await dc.run((call) => handler(call, args, dc.now()), name === "check_dependencies" ? DEPENDENCIES_TIMEOUT_MS : void 0));
25133
27561
  } catch (e) {
25134
27562
  if (e instanceof DataError || e instanceof InputError) return failure(e.message);
25135
27563
  return failure(`${MCP_SERVER.title} could not answer: ${e instanceof Error ? e.message : String(e)}`);