nulladrift 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -1
- package/dist/index.js +588 -47
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { parseArgs } from "util";
|
|
5
|
-
import { resolve as
|
|
5
|
+
import { resolve as resolve4 } from "path";
|
|
6
6
|
|
|
7
7
|
// ../core/src/changes.ts
|
|
8
8
|
var CHANGE_KINDS = [
|
|
@@ -11,6 +11,17 @@ var CHANGE_KINDS = [
|
|
|
11
11
|
"server.renamed",
|
|
12
12
|
"server.transport.changed",
|
|
13
13
|
"server.identity.changed",
|
|
14
|
+
/*
|
|
15
|
+
* Two kinds rather than one, because they call for opposite defaults.
|
|
16
|
+
*
|
|
17
|
+
* A version moving is the ordinary life of a dependency: most of them are patch releases that
|
|
18
|
+
* nobody needs to read, and a policy blocking on them would fail every build in the week a
|
|
19
|
+
* popular package ships. A version *not* moving while its contents do has no innocent
|
|
20
|
+
* explanation -- a registry or mirror serving different bytes under a published version, or an
|
|
21
|
+
* image tag repointed -- and that one should stop a build on the default policy.
|
|
22
|
+
*/
|
|
23
|
+
"server.artifact.changed",
|
|
24
|
+
"server.artifact.substituted",
|
|
14
25
|
"server.protocol.changed",
|
|
15
26
|
"server.instructions.changed",
|
|
16
27
|
"server.capabilities.widened",
|
|
@@ -44,6 +55,8 @@ var SEVERITY = {
|
|
|
44
55
|
"server.renamed": "low",
|
|
45
56
|
"server.transport.changed": "high",
|
|
46
57
|
"server.identity.changed": "medium",
|
|
58
|
+
"server.artifact.changed": "medium",
|
|
59
|
+
"server.artifact.substituted": "high",
|
|
47
60
|
"server.protocol.changed": "medium",
|
|
48
61
|
"server.instructions.changed": "high",
|
|
49
62
|
"server.capabilities.widened": "medium",
|
|
@@ -683,9 +696,40 @@ function compareMembers(name, before, after, spec, deep) {
|
|
|
683
696
|
}
|
|
684
697
|
return changes;
|
|
685
698
|
}
|
|
699
|
+
function compareProvenance(name, before, after) {
|
|
700
|
+
const was = before.provenance;
|
|
701
|
+
const now = after.provenance;
|
|
702
|
+
if (!was || !now) return [];
|
|
703
|
+
if (was.ecosystem !== now.ecosystem || was.name !== now.name) return [];
|
|
704
|
+
const surfaceHeld = before.digest === after.digest;
|
|
705
|
+
const unexplained = surfaceHeld ? ", and the declared surface did not change: nothing else in this report describes what the new code does" : "";
|
|
706
|
+
const integrityMoved = was.integrity !== void 0 && now.integrity !== void 0 && was.integrity !== now.integrity;
|
|
707
|
+
if (was.version !== void 0 && was.version === now.version) {
|
|
708
|
+
if (!integrityMoved) return [];
|
|
709
|
+
if (was.ecosystem === "npm") {
|
|
710
|
+
return [
|
|
711
|
+
change(
|
|
712
|
+
"server.artifact.substituted",
|
|
713
|
+
name,
|
|
714
|
+
`${was.name}@${was.version} now has different contents than when it was pinned: the same version, different bytes`,
|
|
715
|
+
{ before: was, after: now }
|
|
716
|
+
)
|
|
717
|
+
];
|
|
718
|
+
}
|
|
719
|
+
return [change("server.artifact.changed", name, `the files published for ${was.name}@${was.version} are not the ones that were pinned${unexplained}`, { before: was, after: now })];
|
|
720
|
+
}
|
|
721
|
+
if (was.version !== now.version) {
|
|
722
|
+
const moved = `the package behind this server moved from ${was.version ?? "an unknown version"} to ${now.version ?? "an unknown version"}`;
|
|
723
|
+
return [change("server.artifact.changed", name, `${moved}${unexplained}`, { before: was, after: now })];
|
|
724
|
+
}
|
|
725
|
+
if (!integrityMoved) return [];
|
|
726
|
+
const what = was.ecosystem === "oci" ? `the image ${was.name}:${was.requested ?? "latest"} now resolves to a different digest` : "the file this server runs from has different contents than when it was pinned";
|
|
727
|
+
return [change("server.artifact.changed", name, `${what}${unexplained}`, { before: was, after: now })];
|
|
728
|
+
}
|
|
686
729
|
function compareServer(name, before, after) {
|
|
687
|
-
|
|
688
|
-
|
|
730
|
+
const provenance2 = compareProvenance(name, before, after);
|
|
731
|
+
if (before.digest === after.digest) return provenance2;
|
|
732
|
+
const changes = [...provenance2];
|
|
689
733
|
if (!same(before.transport, after.transport)) {
|
|
690
734
|
changes.push(change("server.transport.changed", name, "the server is reached differently than when it was pinned", { before: before.transport, after: after.transport }));
|
|
691
735
|
}
|
|
@@ -1455,31 +1499,428 @@ function buildLockedServer(server2, surface, policy) {
|
|
|
1455
1499
|
return { kind: "mcp-server", ...entry, digest: digest(toJson(covered)) };
|
|
1456
1500
|
}
|
|
1457
1501
|
|
|
1502
|
+
// src/lock/provenance.ts
|
|
1503
|
+
import { createHash as createHash2 } from "crypto";
|
|
1504
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1505
|
+
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
1506
|
+
|
|
1507
|
+
// src/lib/version.ts
|
|
1508
|
+
var VERSION = "0.6.0";
|
|
1509
|
+
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
1510
|
+
|
|
1511
|
+
// src/lock/provenance.ts
|
|
1512
|
+
var NPM_NAME = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i;
|
|
1513
|
+
var NPM_EXACT = /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
|
|
1514
|
+
var NPM_TAG = /^[a-z][\w.-]*$/i;
|
|
1515
|
+
function splitNpmSpec(spec) {
|
|
1516
|
+
const at = spec.lastIndexOf("@");
|
|
1517
|
+
const name = at > 0 ? spec.slice(0, at) : spec;
|
|
1518
|
+
const requested = at > 0 ? spec.slice(at + 1) : void 0;
|
|
1519
|
+
if (!NPM_NAME.test(name)) return void 0;
|
|
1520
|
+
if (requested !== void 0 && requested.length === 0) return void 0;
|
|
1521
|
+
return requested === void 0 ? { name } : { name, requested };
|
|
1522
|
+
}
|
|
1523
|
+
function normalizePypi(name) {
|
|
1524
|
+
return name.replace(/[-_.]+/g, "-").toLowerCase();
|
|
1525
|
+
}
|
|
1526
|
+
var PYPI_EXACT = /^\d[\w.!+-]*$/;
|
|
1527
|
+
function splitPypiSpec(spec) {
|
|
1528
|
+
const text = spec.trim();
|
|
1529
|
+
if (/^(git\+|hg\+|svn\+|bzr\+|https?:|file:|\.|\/|~)/.test(text)) return void 0;
|
|
1530
|
+
const match = /^([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)(?:\[[^\]]*\])?\s*(?:(===?|>=|<=|~=|!=|>|<|@)\s*(\S.*))?$/.exec(text);
|
|
1531
|
+
if (!match) return void 0;
|
|
1532
|
+
const name = normalizePypi(match[1]);
|
|
1533
|
+
const operator = match[2];
|
|
1534
|
+
const value = match[3]?.trim();
|
|
1535
|
+
if (operator === void 0) return { name };
|
|
1536
|
+
if (value === void 0 || value.length === 0) return void 0;
|
|
1537
|
+
return operator === "==" || operator === "===" || operator === "@" ? { name, requested: value } : { name, requested: `${operator}${value}` };
|
|
1538
|
+
}
|
|
1539
|
+
function splitImage(reference) {
|
|
1540
|
+
let rest = reference;
|
|
1541
|
+
let digest2;
|
|
1542
|
+
const at = rest.indexOf("@");
|
|
1543
|
+
if (at >= 0) {
|
|
1544
|
+
digest2 = rest.slice(at + 1);
|
|
1545
|
+
rest = rest.slice(0, at);
|
|
1546
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(digest2)) return void 0;
|
|
1547
|
+
}
|
|
1548
|
+
let tag;
|
|
1549
|
+
const colon = rest.lastIndexOf(":");
|
|
1550
|
+
if (colon > rest.lastIndexOf("/")) {
|
|
1551
|
+
tag = rest.slice(colon + 1);
|
|
1552
|
+
rest = rest.slice(0, colon);
|
|
1553
|
+
if (!/^[\w][\w.-]{0,127}$/.test(tag)) return void 0;
|
|
1554
|
+
}
|
|
1555
|
+
if (!/^[a-z0-9]+(?:[._:-][a-z0-9]+)*(?:\/[a-z0-9]+(?:[._-][a-z0-9]+)*)*$/i.test(rest)) return void 0;
|
|
1556
|
+
return { name: rest, ...tag === void 0 ? {} : { tag }, ...digest2 === void 0 ? {} : { digest: digest2 } };
|
|
1557
|
+
}
|
|
1558
|
+
var NPM_VALUE_FLAGS = /* @__PURE__ */ new Set(["-p", "--package", "-c", "--call", "--registry", "--cache", "--userconfig", "--prefix", "-w", "--workspace", "--node-options"]);
|
|
1559
|
+
var UV_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
1560
|
+
"--from",
|
|
1561
|
+
"--with",
|
|
1562
|
+
"--with-editable",
|
|
1563
|
+
"--with-requirements",
|
|
1564
|
+
"--python",
|
|
1565
|
+
"-p",
|
|
1566
|
+
"--index",
|
|
1567
|
+
"--index-url",
|
|
1568
|
+
"--extra-index-url",
|
|
1569
|
+
"--default-index",
|
|
1570
|
+
"--find-links",
|
|
1571
|
+
"-f",
|
|
1572
|
+
"--constraint",
|
|
1573
|
+
"-c",
|
|
1574
|
+
"--override",
|
|
1575
|
+
"--build-constraint",
|
|
1576
|
+
"--refresh-package",
|
|
1577
|
+
"--reinstall-package",
|
|
1578
|
+
"--upgrade-package",
|
|
1579
|
+
"-P",
|
|
1580
|
+
"--directory",
|
|
1581
|
+
"--project",
|
|
1582
|
+
"--config-file",
|
|
1583
|
+
"--cache-dir",
|
|
1584
|
+
"--color",
|
|
1585
|
+
"--resolution",
|
|
1586
|
+
"--prerelease",
|
|
1587
|
+
"--exclude-newer",
|
|
1588
|
+
"--link-mode",
|
|
1589
|
+
"--env-file",
|
|
1590
|
+
"--spec",
|
|
1591
|
+
"--pip-args",
|
|
1592
|
+
"--keyring-provider",
|
|
1593
|
+
"--index-strategy"
|
|
1594
|
+
]);
|
|
1595
|
+
var DOCKER_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
1596
|
+
"-a",
|
|
1597
|
+
"--attach",
|
|
1598
|
+
"--add-host",
|
|
1599
|
+
"--annotation",
|
|
1600
|
+
"--blkio-weight",
|
|
1601
|
+
"--blkio-weight-device",
|
|
1602
|
+
"--cap-add",
|
|
1603
|
+
"--cap-drop",
|
|
1604
|
+
"--cgroup-parent",
|
|
1605
|
+
"--cgroupns",
|
|
1606
|
+
"--cidfile",
|
|
1607
|
+
"-c",
|
|
1608
|
+
"--cpu-shares",
|
|
1609
|
+
"--cpu-period",
|
|
1610
|
+
"--cpu-quota",
|
|
1611
|
+
"--cpu-rt-period",
|
|
1612
|
+
"--cpu-rt-runtime",
|
|
1613
|
+
"--cpus",
|
|
1614
|
+
"--cpuset-cpus",
|
|
1615
|
+
"--cpuset-mems",
|
|
1616
|
+
"--device",
|
|
1617
|
+
"--device-cgroup-rule",
|
|
1618
|
+
"--device-read-bps",
|
|
1619
|
+
"--device-read-iops",
|
|
1620
|
+
"--device-write-bps",
|
|
1621
|
+
"--device-write-iops",
|
|
1622
|
+
"--dns",
|
|
1623
|
+
"--dns-option",
|
|
1624
|
+
"--dns-search",
|
|
1625
|
+
"--domainname",
|
|
1626
|
+
"--entrypoint",
|
|
1627
|
+
"-e",
|
|
1628
|
+
"--env",
|
|
1629
|
+
"--env-file",
|
|
1630
|
+
"--expose",
|
|
1631
|
+
"--gpus",
|
|
1632
|
+
"--group-add",
|
|
1633
|
+
"--health-cmd",
|
|
1634
|
+
"--health-interval",
|
|
1635
|
+
"--health-retries",
|
|
1636
|
+
"--health-start-period",
|
|
1637
|
+
"--health-start-interval",
|
|
1638
|
+
"--health-timeout",
|
|
1639
|
+
"-h",
|
|
1640
|
+
"--hostname",
|
|
1641
|
+
"--ip",
|
|
1642
|
+
"--ip6",
|
|
1643
|
+
"--ipc",
|
|
1644
|
+
"--isolation",
|
|
1645
|
+
"--kernel-memory",
|
|
1646
|
+
"-l",
|
|
1647
|
+
"--label",
|
|
1648
|
+
"--label-file",
|
|
1649
|
+
"--link",
|
|
1650
|
+
"--link-local-ip",
|
|
1651
|
+
"--log-driver",
|
|
1652
|
+
"--log-opt",
|
|
1653
|
+
"--mac-address",
|
|
1654
|
+
"-m",
|
|
1655
|
+
"--memory",
|
|
1656
|
+
"--memory-reservation",
|
|
1657
|
+
"--memory-swap",
|
|
1658
|
+
"--memory-swappiness",
|
|
1659
|
+
"--mount",
|
|
1660
|
+
"--name",
|
|
1661
|
+
"--network",
|
|
1662
|
+
"--net",
|
|
1663
|
+
"--network-alias",
|
|
1664
|
+
"--net-alias",
|
|
1665
|
+
"--oom-score-adj",
|
|
1666
|
+
"--pid",
|
|
1667
|
+
"--pids-limit",
|
|
1668
|
+
"--platform",
|
|
1669
|
+
"-p",
|
|
1670
|
+
"--publish",
|
|
1671
|
+
"--pull",
|
|
1672
|
+
"--restart",
|
|
1673
|
+
"--runtime",
|
|
1674
|
+
"--security-opt",
|
|
1675
|
+
"--shm-size",
|
|
1676
|
+
"--stop-signal",
|
|
1677
|
+
"--stop-timeout",
|
|
1678
|
+
"--storage-opt",
|
|
1679
|
+
"--sysctl",
|
|
1680
|
+
"--tmpfs",
|
|
1681
|
+
"--ulimit",
|
|
1682
|
+
"-u",
|
|
1683
|
+
"--user",
|
|
1684
|
+
"--userns",
|
|
1685
|
+
"--uts",
|
|
1686
|
+
"-v",
|
|
1687
|
+
"--volume",
|
|
1688
|
+
"--volume-driver",
|
|
1689
|
+
"--volumes-from",
|
|
1690
|
+
"-w",
|
|
1691
|
+
"--workdir",
|
|
1692
|
+
"--detach-keys"
|
|
1693
|
+
]);
|
|
1694
|
+
var DOCKER_VALUE_SHORT = /* @__PURE__ */ new Set(["a", "c", "e", "h", "l", "m", "p", "u", "v", "w"]);
|
|
1695
|
+
function firstPositional(args, valueFlags, explicitFlags, shortValues) {
|
|
1696
|
+
let explicit;
|
|
1697
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
1698
|
+
const arg = args[index];
|
|
1699
|
+
if (arg === "--") return { positional: args[index + 1], explicit };
|
|
1700
|
+
const equals = arg.indexOf("=");
|
|
1701
|
+
if (arg.startsWith("--") && equals > 0) {
|
|
1702
|
+
if (explicitFlags.includes(arg.slice(0, equals))) explicit = arg.slice(equals + 1);
|
|
1703
|
+
continue;
|
|
1704
|
+
}
|
|
1705
|
+
if (explicitFlags.includes(arg)) {
|
|
1706
|
+
explicit = args[index + 1];
|
|
1707
|
+
index += 1;
|
|
1708
|
+
continue;
|
|
1709
|
+
}
|
|
1710
|
+
if (arg.startsWith("-") && arg.length > 1) {
|
|
1711
|
+
if (valueFlags.has(arg)) index += 1;
|
|
1712
|
+
else if (shortValues && !arg.startsWith("--") && arg.length > 2 && shortValues.has(arg.at(-1))) index += 1;
|
|
1713
|
+
continue;
|
|
1714
|
+
}
|
|
1715
|
+
return { positional: arg, explicit };
|
|
1716
|
+
}
|
|
1717
|
+
return { explicit };
|
|
1718
|
+
}
|
|
1719
|
+
function commandName(command) {
|
|
1720
|
+
return (command.split(/[\\/]/).pop() ?? command).replace(/\.(cmd|exe|bat|ps1)$/i, "").toLowerCase();
|
|
1721
|
+
}
|
|
1722
|
+
var SCRIPT_FILE = /\.(?:[cm]?[jt]s|tsx?|py|pyw)$/i;
|
|
1723
|
+
function looksLikePath(value) {
|
|
1724
|
+
return isAbsolute2(value) || value.startsWith("./") || value.startsWith("../") || value.startsWith("~/") || /[\\/]/.test(value);
|
|
1725
|
+
}
|
|
1726
|
+
var SCRIPT_RUNNERS = /* @__PURE__ */ new Set(["node", "nodejs", "deno", "bun", "tsx", "ts-node", "python", "python3"]);
|
|
1727
|
+
function referenceOf(transport2, projectRoot) {
|
|
1728
|
+
const name = commandName(transport2.command);
|
|
1729
|
+
const args = transport2.args;
|
|
1730
|
+
const base = transport2.cwd ?? projectRoot;
|
|
1731
|
+
const npm = (rest) => {
|
|
1732
|
+
const { positional, explicit } = firstPositional(rest, NPM_VALUE_FLAGS, ["-p", "--package"]);
|
|
1733
|
+
if (explicit === void 0 && rest.some((arg) => arg === "-c" || arg === "--call" || arg.startsWith("--call="))) return void 0;
|
|
1734
|
+
const spec = explicit ?? positional;
|
|
1735
|
+
const parsed = spec === void 0 ? void 0 : splitNpmSpec(spec);
|
|
1736
|
+
return parsed ? { ecosystem: "npm", ...parsed } : void 0;
|
|
1737
|
+
};
|
|
1738
|
+
const pypi = (rest) => {
|
|
1739
|
+
const { positional, explicit } = firstPositional(rest, UV_VALUE_FLAGS, ["--from", "--spec"]);
|
|
1740
|
+
const spec = explicit ?? positional;
|
|
1741
|
+
const parsed = spec === void 0 ? void 0 : splitPypiSpec(spec);
|
|
1742
|
+
return parsed ? { ecosystem: "pypi", ...parsed } : void 0;
|
|
1743
|
+
};
|
|
1744
|
+
if (name === "npx" || name === "bunx" || name === "pnpx") return npm(args);
|
|
1745
|
+
if ((name === "pnpm" || name === "yarn") && args[0] === "dlx") return npm(args.slice(1));
|
|
1746
|
+
if (name === "npm" && (args[0] === "exec" || args[0] === "x")) return npm(args.slice(1));
|
|
1747
|
+
if (name === "uvx") return pypi(args);
|
|
1748
|
+
if (name === "uv" && args[0] === "tool" && args[1] === "run") return pypi(args.slice(2));
|
|
1749
|
+
if (name === "pipx" && args[0] === "run") return pypi(args.slice(1));
|
|
1750
|
+
if ((name === "docker" || name === "podman") && args[0] === "run") {
|
|
1751
|
+
const { positional } = firstPositional(args.slice(1), DOCKER_VALUE_FLAGS, [], DOCKER_VALUE_SHORT);
|
|
1752
|
+
const image = positional === void 0 ? void 0 : splitImage(positional);
|
|
1753
|
+
if (!image) return void 0;
|
|
1754
|
+
return {
|
|
1755
|
+
ecosystem: "oci",
|
|
1756
|
+
name: image.name,
|
|
1757
|
+
// A digest is the most specific thing the invocation can ask for, and the one that does not move.
|
|
1758
|
+
...image.digest ? { requested: image.digest, digest: image.digest } : { requested: image.tag ?? "latest" }
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
if (SCRIPT_RUNNERS.has(name)) {
|
|
1762
|
+
if (args.includes("-m")) return void 0;
|
|
1763
|
+
const runArgs = (name === "deno" || name === "bun") && args[0] === "run" ? args.slice(1) : args;
|
|
1764
|
+
const { positional } = firstPositional(runArgs, /* @__PURE__ */ new Set(["-r", "--require", "--import", "--loader", "-e", "--eval", "-c"]), []);
|
|
1765
|
+
if (positional === void 0 || /^[a-z]+:\/\//i.test(positional)) return void 0;
|
|
1766
|
+
if (!looksLikePath(positional) && !SCRIPT_FILE.test(positional)) return void 0;
|
|
1767
|
+
const path = resolve3(base, positional);
|
|
1768
|
+
return { ecosystem: "file", name: portablePath(path, projectRoot), path };
|
|
1769
|
+
}
|
|
1770
|
+
if (looksLikePath(transport2.command)) {
|
|
1771
|
+
const path = resolve3(base, transport2.command);
|
|
1772
|
+
return { ecosystem: "file", name: portablePath(path, projectRoot), path };
|
|
1773
|
+
}
|
|
1774
|
+
return void 0;
|
|
1775
|
+
}
|
|
1776
|
+
function isExact(reference) {
|
|
1777
|
+
switch (reference.ecosystem) {
|
|
1778
|
+
case "npm":
|
|
1779
|
+
return reference.requested !== void 0 && NPM_EXACT.test(reference.requested);
|
|
1780
|
+
case "pypi":
|
|
1781
|
+
return reference.requested !== void 0 && PYPI_EXACT.test(reference.requested);
|
|
1782
|
+
case "oci":
|
|
1783
|
+
return reference.digest !== void 0;
|
|
1784
|
+
case "file":
|
|
1785
|
+
return false;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
1789
|
+
async function getJson(url, options) {
|
|
1790
|
+
const response = await (options.fetch ?? fetch)(url, {
|
|
1791
|
+
// Identified, like every other request this tool makes: see USER_AGENT.
|
|
1792
|
+
headers: { accept: "application/json", "user-agent": USER_AGENT },
|
|
1793
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
|
|
1794
|
+
});
|
|
1795
|
+
if (!response.ok) return void 0;
|
|
1796
|
+
return response.json();
|
|
1797
|
+
}
|
|
1798
|
+
async function resolveNpm(reference, options) {
|
|
1799
|
+
const asked = reference.requested ?? "latest";
|
|
1800
|
+
if (!NPM_EXACT.test(asked) && !NPM_TAG.test(asked)) return void 0;
|
|
1801
|
+
const registry = (process.env["npm_config_registry"] ?? "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
1802
|
+
const body = await getJson(`${registry}/${reference.name.replace("/", "%2F")}/${encodeURIComponent(asked)}`, options);
|
|
1803
|
+
if (typeof body?.version !== "string") return void 0;
|
|
1804
|
+
const integrity = typeof body.dist?.integrity === "string" ? body.dist.integrity : typeof body.dist?.shasum === "string" ? `sha1:${body.dist.shasum}` : void 0;
|
|
1805
|
+
return { ecosystem: "npm", name: reference.name, version: body.version, ...integrity ? { integrity } : {}, ...requestedOf(reference) };
|
|
1806
|
+
}
|
|
1807
|
+
async function resolvePypi(reference, options) {
|
|
1808
|
+
if (reference.requested !== void 0 && !PYPI_EXACT.test(reference.requested)) return void 0;
|
|
1809
|
+
const base = (process.env["NULLADRIFT_PYPI_URL"] ?? "https://pypi.org/pypi").replace(/\/+$/, "");
|
|
1810
|
+
const url = reference.requested ? `${base}/${reference.name}/${encodeURIComponent(reference.requested)}/json` : `${base}/${reference.name}/json`;
|
|
1811
|
+
const body = await getJson(url, options);
|
|
1812
|
+
if (typeof body?.info?.version !== "string") return void 0;
|
|
1813
|
+
const files = (body.urls ?? []).filter((file) => typeof file.filename === "string");
|
|
1814
|
+
const chosen = files.find((file) => file.packagetype === "sdist") ?? files.filter((file) => /-none-any\.whl$/.test(file.filename)).sort((a, b) => a.filename.localeCompare(b.filename))[0];
|
|
1815
|
+
const sha = chosen?.digests?.sha256;
|
|
1816
|
+
return {
|
|
1817
|
+
ecosystem: "pypi",
|
|
1818
|
+
name: reference.name,
|
|
1819
|
+
version: body.info.version,
|
|
1820
|
+
...typeof sha === "string" && /^[a-f0-9]{64}$/.test(sha) ? { integrity: `sha256:${sha}` } : {},
|
|
1821
|
+
...requestedOf(reference)
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
function imageLocation(name) {
|
|
1825
|
+
const parts = name.split("/");
|
|
1826
|
+
const first = parts[0];
|
|
1827
|
+
const hasHost = parts.length > 1 && (first.includes(".") || first.includes(":") || first === "localhost");
|
|
1828
|
+
let host = hasHost ? first : "registry-1.docker.io";
|
|
1829
|
+
if (host === "docker.io" || host === "index.docker.io") host = "registry-1.docker.io";
|
|
1830
|
+
let repository = hasHost ? parts.slice(1).join("/") : name;
|
|
1831
|
+
if (host === "registry-1.docker.io" && !repository.includes("/")) repository = `library/${repository}`;
|
|
1832
|
+
return { host, repository };
|
|
1833
|
+
}
|
|
1834
|
+
function bearerChallenge(header) {
|
|
1835
|
+
if (!header || !/^bearer\s/i.test(header)) return void 0;
|
|
1836
|
+
const fields = {};
|
|
1837
|
+
for (const match of header.slice(7).matchAll(/(\w+)="([^"]*)"/g)) fields[match[1].toLowerCase()] = match[2];
|
|
1838
|
+
if (!fields["realm"]?.startsWith("https://")) return void 0;
|
|
1839
|
+
return { realm: fields["realm"], service: fields["service"], scope: fields["scope"] };
|
|
1840
|
+
}
|
|
1841
|
+
var MANIFEST_TYPES = [
|
|
1842
|
+
"application/vnd.oci.image.index.v1+json",
|
|
1843
|
+
"application/vnd.docker.distribution.manifest.list.v2+json",
|
|
1844
|
+
"application/vnd.oci.image.manifest.v1+json",
|
|
1845
|
+
"application/vnd.docker.distribution.manifest.v2+json"
|
|
1846
|
+
].join(", ");
|
|
1847
|
+
async function resolveOci(reference, options) {
|
|
1848
|
+
if (reference.digest) return { ecosystem: "oci", name: reference.name, integrity: reference.digest, ...requestedOf(reference) };
|
|
1849
|
+
const doFetch = options.fetch ?? fetch;
|
|
1850
|
+
const { host, repository } = imageLocation(reference.name);
|
|
1851
|
+
const url = `https://${host}/v2/${repository}/manifests/${encodeURIComponent(reference.requested ?? "latest")}`;
|
|
1852
|
+
const ask = (authorization) => doFetch(url, {
|
|
1853
|
+
method: "HEAD",
|
|
1854
|
+
headers: { accept: MANIFEST_TYPES, "user-agent": USER_AGENT, ...authorization ? { authorization } : {} },
|
|
1855
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
|
|
1856
|
+
});
|
|
1857
|
+
let response = await ask();
|
|
1858
|
+
if (response.status === 401) {
|
|
1859
|
+
const challenge = bearerChallenge(response.headers.get("www-authenticate"));
|
|
1860
|
+
if (!challenge) return void 0;
|
|
1861
|
+
const tokenUrl = new URL(challenge.realm);
|
|
1862
|
+
if (challenge.service) tokenUrl.searchParams.set("service", challenge.service);
|
|
1863
|
+
tokenUrl.searchParams.set("scope", challenge.scope ?? `repository:${repository}:pull`);
|
|
1864
|
+
const grant = await getJson(tokenUrl.toString(), options);
|
|
1865
|
+
const token = typeof grant?.token === "string" ? grant.token : typeof grant?.access_token === "string" ? grant.access_token : void 0;
|
|
1866
|
+
if (!token) return void 0;
|
|
1867
|
+
response = await ask(`Bearer ${token}`);
|
|
1868
|
+
}
|
|
1869
|
+
if (!response.ok) return void 0;
|
|
1870
|
+
const digest2 = response.headers.get("docker-content-digest");
|
|
1871
|
+
if (!digest2 || !/^sha256:[a-f0-9]{64}$/.test(digest2)) return void 0;
|
|
1872
|
+
return { ecosystem: "oci", name: reference.name, integrity: digest2, ...requestedOf(reference) };
|
|
1873
|
+
}
|
|
1874
|
+
async function resolveFile(reference) {
|
|
1875
|
+
if (!reference.path) return void 0;
|
|
1876
|
+
const bytes = await readFile3(reference.path);
|
|
1877
|
+
return { ecosystem: "file", name: reference.name, integrity: `sha256:${createHash2("sha256").update(bytes).digest("hex")}` };
|
|
1878
|
+
}
|
|
1879
|
+
function requestedOf(reference) {
|
|
1880
|
+
return reference.requested === void 0 ? {} : { requested: reference.requested };
|
|
1881
|
+
}
|
|
1882
|
+
async function resolveReference(reference, options = {}) {
|
|
1883
|
+
try {
|
|
1884
|
+
switch (reference.ecosystem) {
|
|
1885
|
+
case "npm":
|
|
1886
|
+
return await resolveNpm(reference, options);
|
|
1887
|
+
case "pypi":
|
|
1888
|
+
return await resolvePypi(reference, options);
|
|
1889
|
+
case "oci":
|
|
1890
|
+
return await resolveOci(reference, options);
|
|
1891
|
+
case "file":
|
|
1892
|
+
return await resolveFile(reference);
|
|
1893
|
+
}
|
|
1894
|
+
} catch {
|
|
1895
|
+
return void 0;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
function carriedForward(previous, reference) {
|
|
1899
|
+
if (!previous) return void 0;
|
|
1900
|
+
if (previous.ecosystem !== reference.ecosystem || previous.name !== reference.name) return void 0;
|
|
1901
|
+
if (previous.requested !== reference.requested || !isExact(reference)) return void 0;
|
|
1902
|
+
return previous;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1458
1905
|
// src/mcp/connect.ts
|
|
1459
1906
|
import { Client, SSEClientTransport, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
1460
1907
|
import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
1461
1908
|
|
|
1462
1909
|
// src/mcp/oauth.ts
|
|
1463
1910
|
import { spawn } from "child_process";
|
|
1464
|
-
import { createHash as
|
|
1911
|
+
import { createHash as createHash3, randomUUID } from "crypto";
|
|
1465
1912
|
import { readFileSync } from "fs";
|
|
1466
|
-
import { mkdir, readFile as
|
|
1913
|
+
import { mkdir, readFile as readFile4, rm, writeFile } from "fs/promises";
|
|
1467
1914
|
import { homedir as homedir3, platform as platform2 } from "os";
|
|
1468
1915
|
import { dirname, join as join2 } from "path";
|
|
1469
1916
|
import { ClientCredentialsProvider, UnauthorizedError } from "@modelcontextprotocol/client";
|
|
1470
|
-
|
|
1471
|
-
// src/lib/version.ts
|
|
1472
|
-
var VERSION = "0.4.0";
|
|
1473
|
-
var USER_AGENT = `nulladrift/${VERSION}`;
|
|
1474
|
-
|
|
1475
|
-
// src/mcp/oauth.ts
|
|
1476
1917
|
var DEFAULT_CALLBACK_PATH = "/callback";
|
|
1477
1918
|
function authDir() {
|
|
1478
1919
|
const base = process.env["XDG_CONFIG_HOME"] ?? join2(homedir3(), ".config");
|
|
1479
1920
|
return join2(base, "nulladrift", "auth");
|
|
1480
1921
|
}
|
|
1481
1922
|
function credentialPath(url) {
|
|
1482
|
-
return join2(authDir(), `${
|
|
1923
|
+
return join2(authDir(), `${createHash3("sha256").update(url).digest("hex").slice(0, 16)}.json`);
|
|
1483
1924
|
}
|
|
1484
1925
|
var InteractiveAuthRequiredError = class extends Error {
|
|
1485
1926
|
constructor(serverName) {
|
|
@@ -1500,7 +1941,7 @@ var FileTokenProvider = class {
|
|
|
1500
1941
|
options;
|
|
1501
1942
|
cache;
|
|
1502
1943
|
/** One per login attempt, held in memory and checked against what comes back on the callback. */
|
|
1503
|
-
stateValue =
|
|
1944
|
+
stateValue = createHash3("sha256").update(randomUUID()).digest("hex").slice(0, 32);
|
|
1504
1945
|
get redirectUrl() {
|
|
1505
1946
|
return this.options.redirectUrl;
|
|
1506
1947
|
}
|
|
@@ -1522,7 +1963,7 @@ var FileTokenProvider = class {
|
|
|
1522
1963
|
async read() {
|
|
1523
1964
|
if (this.cache) return this.cache;
|
|
1524
1965
|
try {
|
|
1525
|
-
this.cache = JSON.parse(await
|
|
1966
|
+
this.cache = JSON.parse(await readFile4(credentialPath(this.serverUrl), "utf8"));
|
|
1526
1967
|
} catch {
|
|
1527
1968
|
this.cache = { serverUrl: this.serverUrl };
|
|
1528
1969
|
}
|
|
@@ -1668,7 +2109,7 @@ function isAuthFailure(error) {
|
|
|
1668
2109
|
}
|
|
1669
2110
|
|
|
1670
2111
|
// src/mcp/connect.ts
|
|
1671
|
-
var
|
|
2112
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
1672
2113
|
var STDERR_KEEP_BYTES = 2e3;
|
|
1673
2114
|
function buildTransport(server2, captureStderr = () => {
|
|
1674
2115
|
}, options = {}) {
|
|
@@ -1687,7 +2128,7 @@ function buildTransport(server2, captureStderr = () => {
|
|
|
1687
2128
|
child.stderr?.on("data", (chunk) => captureStderr(chunk.toString("utf8")));
|
|
1688
2129
|
return child;
|
|
1689
2130
|
}
|
|
1690
|
-
const headers = {
|
|
2131
|
+
const headers = { "user-agent": USER_AGENT, ...transport2.headers };
|
|
1691
2132
|
const url = new URL(transport2.url);
|
|
1692
2133
|
const authProvider = createAuthProvider(server2, options);
|
|
1693
2134
|
if (transport2.type === "sse") return new SSEClientTransport(url, { requestInit: { headers }, authProvider });
|
|
@@ -1699,7 +2140,7 @@ function diagnosticLines(stderr, limit = 3) {
|
|
|
1699
2140
|
const chosen = named.length > 0 ? named : lines;
|
|
1700
2141
|
return chosen.slice(0, limit).map((line) => line.trim());
|
|
1701
2142
|
}
|
|
1702
|
-
async function connect(server2, timeoutMs =
|
|
2143
|
+
async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
1703
2144
|
let stderrBuffer = "";
|
|
1704
2145
|
const captureStderr = (chunk) => {
|
|
1705
2146
|
stderrBuffer = (stderrBuffer + chunk).slice(-STDERR_KEEP_BYTES);
|
|
@@ -1808,7 +2249,7 @@ function readServerInfo(client) {
|
|
|
1808
2249
|
websiteUrl: info.websiteUrl
|
|
1809
2250
|
};
|
|
1810
2251
|
}
|
|
1811
|
-
async function captureSurface(server2, timeoutMs =
|
|
2252
|
+
async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
1812
2253
|
const connection = await connect(server2, timeoutMs);
|
|
1813
2254
|
const { client } = connection;
|
|
1814
2255
|
try {
|
|
@@ -1836,6 +2277,20 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
|
1836
2277
|
}
|
|
1837
2278
|
|
|
1838
2279
|
// src/audit.ts
|
|
2280
|
+
async function provenanceOf(server2, options) {
|
|
2281
|
+
if (server2.transport.type !== "stdio") return { unverified: false };
|
|
2282
|
+
const reference = referenceOf(server2.transport, options.projectRoot);
|
|
2283
|
+
if (!reference) return { unverified: false };
|
|
2284
|
+
const previous = options.previous?.subjects[server2.name]?.provenance;
|
|
2285
|
+
if (options.provenance === false) {
|
|
2286
|
+
const kept2 = carriedForward(previous, reference);
|
|
2287
|
+
return { ...kept2 ? { provenance: kept2 } : {}, unverified: true };
|
|
2288
|
+
}
|
|
2289
|
+
const resolved = await resolveReference(reference, { timeoutMs: options.timeoutMs });
|
|
2290
|
+
if (resolved) return { provenance: resolved, unverified: false };
|
|
2291
|
+
const kept = carriedForward(previous, reference);
|
|
2292
|
+
return { ...kept ? { provenance: kept } : {}, unverified: true };
|
|
2293
|
+
}
|
|
1839
2294
|
async function mapWithLimit(items, limit, worker) {
|
|
1840
2295
|
const results = new Array(items.length);
|
|
1841
2296
|
let next = 0;
|
|
@@ -1869,12 +2324,14 @@ async function captureAll(options) {
|
|
|
1869
2324
|
const captured = await mapWithLimit(discovery.servers, options.concurrency ?? 4, async (server2) => {
|
|
1870
2325
|
try {
|
|
1871
2326
|
const surface = await withDeadline(
|
|
1872
|
-
options.timeoutMs ??
|
|
2327
|
+
options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
|
|
1873
2328
|
server2.name,
|
|
1874
|
-
() => captureSurface(server2, options.timeoutMs ??
|
|
2329
|
+
() => captureSurface(server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2)
|
|
1875
2330
|
);
|
|
2331
|
+
const entry = buildLockedServer(server2, surface, options.policy);
|
|
2332
|
+
const { provenance: provenance2, unverified: unverified2 } = await provenanceOf(server2, options);
|
|
1876
2333
|
options.onServerDone?.(server2.name, "captured");
|
|
1877
|
-
return { name: server2.name, entry:
|
|
2334
|
+
return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2 };
|
|
1878
2335
|
} catch (error) {
|
|
1879
2336
|
options.onServerDone?.(server2.name, "failed");
|
|
1880
2337
|
const reason = error instanceof UnreachableServerError ? error.message : error.message;
|
|
@@ -1884,9 +2341,12 @@ async function captureAll(options) {
|
|
|
1884
2341
|
});
|
|
1885
2342
|
const subjects = {};
|
|
1886
2343
|
const unreachable = [];
|
|
2344
|
+
const unverified = [];
|
|
1887
2345
|
for (const result of captured) {
|
|
1888
|
-
if ("entry" in result && result.entry)
|
|
1889
|
-
|
|
2346
|
+
if ("entry" in result && result.entry) {
|
|
2347
|
+
subjects[result.name] = result.entry;
|
|
2348
|
+
if (result.unverified) unverified.push(result.name);
|
|
2349
|
+
} else if ("failure" in result && result.failure) unreachable.push(result.failure);
|
|
1890
2350
|
}
|
|
1891
2351
|
for (const skipped of discovery.skipped) {
|
|
1892
2352
|
unreachable.push({ server: skipped.serverName, reason: skipped.message, kind: "unreachable" });
|
|
@@ -1902,12 +2362,13 @@ async function captureAll(options) {
|
|
|
1902
2362
|
subjects
|
|
1903
2363
|
},
|
|
1904
2364
|
unreachable,
|
|
1905
|
-
discovery
|
|
2365
|
+
discovery,
|
|
2366
|
+
unverified: unverified.sort()
|
|
1906
2367
|
};
|
|
1907
2368
|
}
|
|
1908
2369
|
|
|
1909
2370
|
// src/lock/io.ts
|
|
1910
|
-
import { lstat, readFile as
|
|
2371
|
+
import { lstat, readFile as readFile5, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
|
|
1911
2372
|
|
|
1912
2373
|
// src/lock/schema.ts
|
|
1913
2374
|
import { z as z2 } from "zod";
|
|
@@ -1990,6 +2451,13 @@ var transport = z2.union([
|
|
|
1990
2451
|
headerKeys: z2.array(z2.string()).optional()
|
|
1991
2452
|
})
|
|
1992
2453
|
]);
|
|
2454
|
+
var provenance = z2.object({
|
|
2455
|
+
ecosystem: z2.enum(["npm", "pypi", "oci", "file"]),
|
|
2456
|
+
name: z2.string(),
|
|
2457
|
+
version: z2.string().optional(),
|
|
2458
|
+
integrity: z2.string().optional(),
|
|
2459
|
+
requested: z2.string().optional()
|
|
2460
|
+
});
|
|
1993
2461
|
var server = z2.object({
|
|
1994
2462
|
kind: z2.literal("mcp-server"),
|
|
1995
2463
|
source: z2.object({
|
|
@@ -1998,6 +2466,7 @@ var server = z2.object({
|
|
|
1998
2466
|
scope: z2.enum(["project", "user", "local"]).optional()
|
|
1999
2467
|
}),
|
|
2000
2468
|
transport,
|
|
2469
|
+
provenance: provenance.optional(),
|
|
2001
2470
|
protocol: z2.object({
|
|
2002
2471
|
era: z2.enum(["modern", "legacy"]),
|
|
2003
2472
|
version: z2.string(),
|
|
@@ -2172,7 +2641,7 @@ function parseLockfile(text, path) {
|
|
|
2172
2641
|
async function readLockfile(path) {
|
|
2173
2642
|
let text;
|
|
2174
2643
|
try {
|
|
2175
|
-
text = await
|
|
2644
|
+
text = await readFile5(path, "utf8");
|
|
2176
2645
|
} catch (error) {
|
|
2177
2646
|
const code = error.code;
|
|
2178
2647
|
if (code === "ENOENT") throw new LockfileError(`no lockfile at ${path}. Run \`nulladrift init\` first.`);
|
|
@@ -2305,6 +2774,15 @@ function renderHumanReport(report) {
|
|
|
2305
2774
|
lines.push(` ${label} ${bold(failure.server)}`, ` ${failure.reason}`, "");
|
|
2306
2775
|
}
|
|
2307
2776
|
}
|
|
2777
|
+
const unverified = report.unverified ?? [];
|
|
2778
|
+
if (unverified.length > 0) {
|
|
2779
|
+
lines.push(
|
|
2780
|
+
yellow(`Could not establish what ${unverified.length} server(s) run:`),
|
|
2781
|
+
...unverified.map((server2) => ` ${bold(server2)}`),
|
|
2782
|
+
dim(" Their surfaces were checked; the package or file behind them was not. A pin the config names exactly is kept."),
|
|
2783
|
+
""
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2308
2786
|
lines.push(...renderSteering(report));
|
|
2309
2787
|
if (report.changes.length === 0 && report.unreachable.length === 0 && (report.violations ?? []).length === 0) {
|
|
2310
2788
|
lines.push(green(`\u2713 ${report.serversChecked} server(s) match ${report.lockPath}`));
|
|
@@ -2381,8 +2859,8 @@ function renderJsonReport(report, exitCode) {
|
|
|
2381
2859
|
}
|
|
2382
2860
|
|
|
2383
2861
|
// src/report/sarif.ts
|
|
2384
|
-
import { isAbsolute as
|
|
2385
|
-
import { createHash as
|
|
2862
|
+
import { isAbsolute as isAbsolute3, relative as relative2, sep as sep2 } from "path";
|
|
2863
|
+
import { createHash as createHash4 } from "crypto";
|
|
2386
2864
|
|
|
2387
2865
|
// src/lib/meta.ts
|
|
2388
2866
|
var BUILT_IN_DOCS_URL = void 0;
|
|
@@ -2416,15 +2894,17 @@ var RULE_HELP = {
|
|
|
2416
2894
|
"tool.input_schema.widened": "The tool accepts input it previously rejected, enlarging what the agent can be induced to send.",
|
|
2417
2895
|
"tool.header_params.changed": "x-mcp-header mirrors an argument's value into an HTTP header, where proxies and other intermediaries can read it.",
|
|
2418
2896
|
"server.transport.changed": "The configured name now points at a different command or URL. This is a different server, not a changed one.",
|
|
2419
|
-
"server.identity.changed": "The server reports a different identity or version than the one that was reviewed."
|
|
2897
|
+
"server.identity.changed": "The server reports a different identity or version than the one that was reviewed.",
|
|
2898
|
+
"server.artifact.changed": "The package, image or file behind this server is a different release than the one pinned. When the declared surface did not change, nothing else in the report describes what the new code does; read the release, not just this diff.",
|
|
2899
|
+
"server.artifact.substituted": "The same published version now has different contents. Registries treat a version as immutable, so this means a mirror, proxy or registry served different bytes, or an image tag was repointed. Treat it as a supply-chain incident until shown otherwise."
|
|
2420
2900
|
};
|
|
2421
2901
|
function fingerprint(change2) {
|
|
2422
|
-
return
|
|
2902
|
+
return createHash4("sha256").update(`${change2.kind}\0${change2.server}\0${change2.member ?? ""}`).digest("hex").slice(0, 32);
|
|
2423
2903
|
}
|
|
2424
2904
|
function sarifUri(report) {
|
|
2425
2905
|
if (report.projectRoot === void 0) return report.lockPath;
|
|
2426
2906
|
const rel = relative2(report.projectRoot, report.lockPath);
|
|
2427
|
-
if (rel === "" || rel.startsWith("..") ||
|
|
2907
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute3(rel)) return report.lockPath;
|
|
2428
2908
|
return rel.split(sep2).join("/");
|
|
2429
2909
|
}
|
|
2430
2910
|
function renderSarifReport(report, options = {}) {
|
|
@@ -2627,8 +3107,8 @@ ${body}`;
|
|
|
2627
3107
|
}
|
|
2628
3108
|
|
|
2629
3109
|
// src/telemetry/index.ts
|
|
2630
|
-
import { createHash as
|
|
2631
|
-
import { mkdir as mkdir2, readFile as
|
|
3110
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "crypto";
|
|
3111
|
+
import { mkdir as mkdir2, readFile as readFile6, rm as rm3, writeFile as writeFile3 } from "fs/promises";
|
|
2632
3112
|
import { homedir as homedir4 } from "os";
|
|
2633
3113
|
import { dirname as dirname2, join as join3 } from "path";
|
|
2634
3114
|
var PAYLOAD_SCHEMA = 2;
|
|
@@ -2643,7 +3123,7 @@ function isCi() {
|
|
|
2643
3123
|
}
|
|
2644
3124
|
async function readConfig() {
|
|
2645
3125
|
try {
|
|
2646
|
-
const parsed = JSON.parse(await
|
|
3126
|
+
const parsed = JSON.parse(await readFile6(configPath(), "utf8"));
|
|
2647
3127
|
return typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
2648
3128
|
} catch {
|
|
2649
3129
|
return {};
|
|
@@ -2691,7 +3171,7 @@ function buildPayload(report, changes, installId) {
|
|
|
2691
3171
|
}
|
|
2692
3172
|
function reportHash(payload) {
|
|
2693
3173
|
const { schema, auditVersion, context, serverCount, driftedServerCount, changes } = payload;
|
|
2694
|
-
return
|
|
3174
|
+
return createHash5("sha256").update(JSON.stringify({ schema, auditVersion, context, serverCount, driftedServerCount, changes })).digest("hex");
|
|
2695
3175
|
}
|
|
2696
3176
|
async function send(payload) {
|
|
2697
3177
|
const endpoint = telemetryEndpoint();
|
|
@@ -2730,7 +3210,9 @@ async function buildReport(options) {
|
|
|
2730
3210
|
configFiles: options.configFiles,
|
|
2731
3211
|
timeoutMs: options.timeoutMs,
|
|
2732
3212
|
// The committed policy governs the check, so every consumer of the repo audits identically.
|
|
2733
|
-
policy: committed.policy
|
|
3213
|
+
policy: committed.policy,
|
|
3214
|
+
previous: committed,
|
|
3215
|
+
provenance: options.provenance
|
|
2734
3216
|
});
|
|
2735
3217
|
const changes = diffLockfiles(committed, result.lock);
|
|
2736
3218
|
const allowUnreachable = options.allowUnreachable || committed.policy?.allowUnreachable === true;
|
|
@@ -2748,6 +3230,8 @@ async function buildReport(options) {
|
|
|
2748
3230
|
*/
|
|
2749
3231
|
violations: capabilityViolations(result.lock, committed.policy?.deniedCapabilities),
|
|
2750
3232
|
unreachable: result.unreachable,
|
|
3233
|
+
// Reported beside the verdict and never part of it; see `AuditReport.unverified`.
|
|
3234
|
+
unverified: result.unverified,
|
|
2751
3235
|
serversChecked: Object.keys(result.lock.subjects).length,
|
|
2752
3236
|
lockPath: options.lockPath,
|
|
2753
3237
|
projectRoot: options.projectRoot
|
|
@@ -2920,7 +3404,8 @@ async function runInit(options) {
|
|
|
2920
3404
|
const result = await captureAll({
|
|
2921
3405
|
projectRoot: options.projectRoot,
|
|
2922
3406
|
configFiles: options.configFiles,
|
|
2923
|
-
timeoutMs: options.timeoutMs
|
|
3407
|
+
timeoutMs: options.timeoutMs,
|
|
3408
|
+
provenance: options.provenance
|
|
2924
3409
|
});
|
|
2925
3410
|
const names = Object.keys(result.lock.subjects);
|
|
2926
3411
|
if (names.length === 0 && result.unreachable.length === 0) {
|
|
@@ -3035,8 +3520,8 @@ async function awaitCallback(expectedState) {
|
|
|
3035
3520
|
server2.listen(0, "127.0.0.1", ready);
|
|
3036
3521
|
});
|
|
3037
3522
|
const { port } = server2.address();
|
|
3038
|
-
const received = new Promise((
|
|
3039
|
-
settle =
|
|
3523
|
+
const received = new Promise((resolve5, reject) => {
|
|
3524
|
+
settle = resolve5;
|
|
3040
3525
|
fail = reject;
|
|
3041
3526
|
setTimeout(() => reject(new Error(`no callback within ${CALLBACK_TIMEOUT_MS / 1e3}s`)), CALLBACK_TIMEOUT_MS).unref();
|
|
3042
3527
|
});
|
|
@@ -3162,7 +3647,44 @@ function describeRefusal(status, body) {
|
|
|
3162
3647
|
};
|
|
3163
3648
|
}
|
|
3164
3649
|
|
|
3650
|
+
// src/lib/build-token.ts
|
|
3651
|
+
var BUILD_TOKEN_HEADER = "nulladrift-build-token";
|
|
3652
|
+
var DEFAULT_AUDIENCE = "nulladrift";
|
|
3653
|
+
async function acquireBuildToken(options = {}) {
|
|
3654
|
+
const env = options.env ?? process.env;
|
|
3655
|
+
const explicit = env["NULLADRIFT_ID_TOKEN"];
|
|
3656
|
+
if (explicit) return { token: explicit, source: "environment" };
|
|
3657
|
+
if (env["GITHUB_ACTIONS"] !== "true") return void 0;
|
|
3658
|
+
const requestUrl = env["ACTIONS_ID_TOKEN_REQUEST_URL"];
|
|
3659
|
+
const requestToken = env["ACTIONS_ID_TOKEN_REQUEST_TOKEN"];
|
|
3660
|
+
if (!requestUrl || !requestToken) {
|
|
3661
|
+
return { hint: "add `permissions: id-token: write` to this job so the reading can prove which build sent it" };
|
|
3662
|
+
}
|
|
3663
|
+
try {
|
|
3664
|
+
const url = new URL(requestUrl);
|
|
3665
|
+
url.searchParams.set("audience", env["NULLADRIFT_BUILD_AUDIENCE"] ?? DEFAULT_AUDIENCE);
|
|
3666
|
+
const response = await (options.fetch ?? fetch)(url, {
|
|
3667
|
+
headers: { authorization: `bearer ${requestToken}`, accept: "application/json" },
|
|
3668
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
|
|
3669
|
+
});
|
|
3670
|
+
if (!response.ok) return { hint: `GitHub Actions would not mint an identity token (HTTP ${response.status})` };
|
|
3671
|
+
const body = await response.json();
|
|
3672
|
+
if (typeof body.value !== "string" || body.value.length === 0) return { hint: "GitHub Actions returned no identity token" };
|
|
3673
|
+
return { token: body.value, source: "github-actions" };
|
|
3674
|
+
} catch (error) {
|
|
3675
|
+
return { hint: `could not reach GitHub Actions for an identity token: ${error.message}` };
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
|
|
3165
3679
|
// src/commands/push.ts
|
|
3680
|
+
function describeIdentity(identity2, hint) {
|
|
3681
|
+
if (identity2?.trust === "trusted") return `${green("signed")} ${dim(`${identity2.repository ?? ""}${identity2.ref ? ` @ ${identity2.ref}` : ""} \xB7 a trusted build`)}`;
|
|
3682
|
+
if (identity2?.trust === "verified") {
|
|
3683
|
+
return `${yellow("signed")} ${dim(`${identity2.repository ?? ""}${identity2.ref ? ` @ ${identity2.ref}` : ""} \xB7 not a build this organization lists as trusted`)}`;
|
|
3684
|
+
}
|
|
3685
|
+
if (identity2?.rejected) return `${red("build token refused")} ${dim(identity2.rejected)}`;
|
|
3686
|
+
return hint ? dim(`unsigned: ${hint}`) : void 0;
|
|
3687
|
+
}
|
|
3166
3688
|
function inferProject(projectRoot) {
|
|
3167
3689
|
const fromCi = process.env["GITHUB_REPOSITORY"] ?? process.env["CI_PROJECT_PATH"] ?? process.env["BUILD_REPOSITORY_NAME"];
|
|
3168
3690
|
if (fromCi) return fromCi;
|
|
@@ -3192,7 +3714,8 @@ async function runPush(options) {
|
|
|
3192
3714
|
const result = await captureAll({
|
|
3193
3715
|
projectRoot: options.projectRoot,
|
|
3194
3716
|
configFiles: options.configFiles,
|
|
3195
|
-
timeoutMs: options.timeoutMs
|
|
3717
|
+
timeoutMs: options.timeoutMs,
|
|
3718
|
+
provenance: options.provenance
|
|
3196
3719
|
});
|
|
3197
3720
|
if (Object.keys(result.lock.subjects).length === 0 && result.unreachable.length === 0) {
|
|
3198
3721
|
const looked = result.discovery.filesRead.length > 0 ? result.discovery.filesRead.join(", ") : "no client config files exist for this project";
|
|
@@ -3224,11 +3747,17 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
3224
3747
|
servers,
|
|
3225
3748
|
unreachable: result.unreachable.map((failure) => ({ server: failure.server, reason: failure.reason }))
|
|
3226
3749
|
};
|
|
3750
|
+
const build = await acquireBuildToken();
|
|
3751
|
+
const buildToken = build && "token" in build ? build.token : void 0;
|
|
3227
3752
|
let response;
|
|
3228
3753
|
try {
|
|
3229
3754
|
response = await fetch(`${apiUrl}/api/v1/ingest`, {
|
|
3230
3755
|
method: "POST",
|
|
3231
|
-
headers: {
|
|
3756
|
+
headers: {
|
|
3757
|
+
"content-type": "application/json",
|
|
3758
|
+
authorization: `Bearer ${token}`,
|
|
3759
|
+
...buildToken ? { [BUILD_TOKEN_HEADER]: buildToken } : {}
|
|
3760
|
+
},
|
|
3232
3761
|
body: JSON.stringify(body),
|
|
3233
3762
|
signal: AbortSignal.timeout(options.timeoutMs)
|
|
3234
3763
|
});
|
|
@@ -3247,6 +3776,8 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
3247
3776
|
const lines = [""];
|
|
3248
3777
|
const mark = verdict.verdict === "clean" ? green("\u2713") : verdict.verdict === "drift" ? yellow("!") : red("\u2717");
|
|
3249
3778
|
lines.push(`${mark} ${bold(verdict.verdict)} ${dim(`\xB7 ${servers.length} server(s) \xB7 reading ${verdict.readingId.slice(0, 8)}`)}`);
|
|
3779
|
+
const identity2 = describeIdentity(verdict.identity, build && "hint" in build ? build.hint : void 0);
|
|
3780
|
+
if (identity2) lines.push(` ${identity2}`);
|
|
3250
3781
|
for (const change2 of verdict.changes) {
|
|
3251
3782
|
lines.push(` ${change2.severity === "high" ? red("\u25CF") : change2.severity === "medium" ? yellow("\u25CF") : dim("\u25CF")} ${bold(change2.server)}${change2.member ? dim(`/${change2.member}`) : ""} ${change2.summary}`);
|
|
3252
3783
|
}
|
|
@@ -3300,7 +3831,14 @@ async function runReview(options) {
|
|
|
3300
3831
|
projectRoot: options.projectRoot,
|
|
3301
3832
|
configFiles: options.configFiles,
|
|
3302
3833
|
timeoutMs: options.timeoutMs,
|
|
3303
|
-
policy: committed.policy
|
|
3834
|
+
policy: committed.policy,
|
|
3835
|
+
/*
|
|
3836
|
+
* What review writes is what gets committed. Without the previous lock, accepting a change
|
|
3837
|
+
* while a registry was unreachable would drop every artifact pin in the file -- and the next
|
|
3838
|
+
* run would re-pin whatever had been published since, with nothing to compare it against.
|
|
3839
|
+
*/
|
|
3840
|
+
previous: committed,
|
|
3841
|
+
provenance: options.provenance
|
|
3304
3842
|
});
|
|
3305
3843
|
const changes = diffLockfiles(committed, result.lock);
|
|
3306
3844
|
if (changes.length === 0) {
|
|
@@ -3385,8 +3923,9 @@ ${bold("Options")}
|
|
|
3385
3923
|
--lock <path> lockfile to read or write (default: ./${DEFAULT_LOCK_FILENAME})
|
|
3386
3924
|
--cwd <path> project root to scan for client configs (default: current directory)
|
|
3387
3925
|
--config <path> audit this config file too; repeatable
|
|
3388
|
-
--timeout <ms> per-server timeout (default: ${
|
|
3926
|
+
--timeout <ms> per-server timeout (default: ${DEFAULT_TIMEOUT_MS2})
|
|
3389
3927
|
--allow-unreachable a server that cannot be reached warns instead of failing
|
|
3928
|
+
--no-provenance do not look up what each stdio server runs (air-gapped runs)
|
|
3390
3929
|
--json machine-readable output (check)
|
|
3391
3930
|
--sarif SARIF 2.1.0 output (check)
|
|
3392
3931
|
--sarif-steering also emit steering passages as SARIF notes (off: an alert is a gate)
|
|
@@ -3416,6 +3955,7 @@ async function main() {
|
|
|
3416
3955
|
config: { type: "string", multiple: true },
|
|
3417
3956
|
timeout: { type: "string" },
|
|
3418
3957
|
"allow-unreachable": { type: "boolean", default: false },
|
|
3958
|
+
"no-provenance": { type: "boolean", default: false },
|
|
3419
3959
|
json: { type: "boolean", default: false },
|
|
3420
3960
|
sarif: { type: "boolean", default: false },
|
|
3421
3961
|
"sarif-steering": { type: "boolean", default: false },
|
|
@@ -3446,22 +3986,23 @@ async function main() {
|
|
|
3446
3986
|
`);
|
|
3447
3987
|
return EXIT_INCOMPLETE;
|
|
3448
3988
|
}
|
|
3449
|
-
const timeoutMs = values.timeout === void 0 ?
|
|
3989
|
+
const timeoutMs = values.timeout === void 0 ? DEFAULT_TIMEOUT_MS2 : Number.parseInt(values.timeout, 10);
|
|
3450
3990
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
3451
3991
|
process.stderr.write(`${red(`--timeout must be a positive number of milliseconds, got "${values.timeout}".`)}
|
|
3452
3992
|
`);
|
|
3453
3993
|
return EXIT_INCOMPLETE;
|
|
3454
3994
|
}
|
|
3455
|
-
const projectRoot =
|
|
3995
|
+
const projectRoot = resolve4(values.cwd ?? process.cwd());
|
|
3456
3996
|
const options = {
|
|
3457
3997
|
projectRoot,
|
|
3458
|
-
lockPath:
|
|
3998
|
+
lockPath: resolve4(projectRoot, values.lock ?? DEFAULT_LOCK_FILENAME),
|
|
3459
3999
|
configFiles: values.config ?? [],
|
|
3460
4000
|
timeoutMs,
|
|
3461
4001
|
allowUnreachable: values["allow-unreachable"],
|
|
3462
4002
|
format: values.sarif ? "sarif" : values.json ? "json" : "human",
|
|
3463
4003
|
sarifSteering: values["sarif-steering"] === true,
|
|
3464
|
-
comment: values.comment
|
|
4004
|
+
comment: values.comment,
|
|
4005
|
+
provenance: values["no-provenance"] !== true
|
|
3465
4006
|
};
|
|
3466
4007
|
switch (command) {
|
|
3467
4008
|
case "init":
|