nulladrift 0.7.1 → 0.8.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 +39 -1
- package/dist/index.js +661 -126
- 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 resolve6 } from "path";
|
|
6
6
|
|
|
7
7
|
// ../core/src/changes.ts
|
|
8
8
|
var CHANGE_KINDS = [
|
|
@@ -312,6 +312,19 @@ function redactFormats(value) {
|
|
|
312
312
|
for (const format of ISSUER_FORMATS) out = out.replace(format, REDACTED);
|
|
313
313
|
return out;
|
|
314
314
|
}
|
|
315
|
+
var CODE_HOSTS = /* @__PURE__ */ new Set([
|
|
316
|
+
"github.com",
|
|
317
|
+
"raw.githubusercontent.com",
|
|
318
|
+
"codeload.github.com",
|
|
319
|
+
"gist.github.com",
|
|
320
|
+
"gist.githubusercontent.com",
|
|
321
|
+
"api.github.com",
|
|
322
|
+
"gitlab.com",
|
|
323
|
+
"bitbucket.org",
|
|
324
|
+
"cdn.jsdelivr.net",
|
|
325
|
+
"esm.sh",
|
|
326
|
+
"deno.land"
|
|
327
|
+
]);
|
|
315
328
|
function redactUrl(value) {
|
|
316
329
|
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) return value;
|
|
317
330
|
let url;
|
|
@@ -331,7 +344,7 @@ function redactUrl(value) {
|
|
|
331
344
|
changed = true;
|
|
332
345
|
}
|
|
333
346
|
}
|
|
334
|
-
const path = redactPath(url.pathname);
|
|
347
|
+
const path = redactPath(url.pathname, { contentAddressed: CODE_HOSTS.has(url.hostname.toLowerCase()) });
|
|
335
348
|
if (path !== url.pathname) {
|
|
336
349
|
url.pathname = path;
|
|
337
350
|
changed = true;
|
|
@@ -433,11 +446,12 @@ function redactArgs(args) {
|
|
|
433
446
|
function looksLikeAnOperand(value) {
|
|
434
447
|
return value.startsWith("@") || value.includes("/") || /\.(m?[jt]s|cjs|py|json|ya?ml|toml|sh|exe)$/i.test(value);
|
|
435
448
|
}
|
|
436
|
-
function redactPath(pathname) {
|
|
449
|
+
function redactPath(pathname, options = {}) {
|
|
437
450
|
return pathname.split("/").map((segment) => {
|
|
438
451
|
if (segment === "" || PLACEHOLDER.test(decoded(segment))) return segment;
|
|
439
452
|
if (looksRandom(segment)) return REDACTED;
|
|
440
|
-
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(segment) || /^[0-9a-f]{32,}$/i.test(segment))
|
|
453
|
+
if (!options.contentAddressed && (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(segment) || /^[0-9a-f]{32,}$/i.test(segment)))
|
|
454
|
+
return REDACTED;
|
|
441
455
|
return redactFormats(segment);
|
|
442
456
|
}).join("/");
|
|
443
457
|
}
|
|
@@ -450,6 +464,17 @@ function countRedacted(transport2) {
|
|
|
450
464
|
var MAX_REF_DEPTH = 32;
|
|
451
465
|
var MAX_VISIT_DEPTH = 12;
|
|
452
466
|
var MAX_FACTS = 5e3;
|
|
467
|
+
var MAX_RESOLUTIONS = 1e5;
|
|
468
|
+
var states = /* @__PURE__ */ new WeakMap();
|
|
469
|
+
function stateOf(root) {
|
|
470
|
+
if (root === null || typeof root !== "object") return { refs: /* @__PURE__ */ new Map(), spent: 0 };
|
|
471
|
+
let state = states.get(root);
|
|
472
|
+
if (!state) {
|
|
473
|
+
state = { refs: /* @__PURE__ */ new Map(), spent: 0 };
|
|
474
|
+
states.set(root, state);
|
|
475
|
+
}
|
|
476
|
+
return state;
|
|
477
|
+
}
|
|
453
478
|
function asObject(value) {
|
|
454
479
|
return value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
455
480
|
}
|
|
@@ -477,6 +502,9 @@ function effectiveSchema(node, root, seenRefs = /* @__PURE__ */ new Set(), depth
|
|
|
477
502
|
const object = asObject(node);
|
|
478
503
|
if (object === void 0) return void 0;
|
|
479
504
|
if (depth > MAX_REF_DEPTH) return object;
|
|
505
|
+
const state = stateOf(root);
|
|
506
|
+
if (depth === 0) state.spent = 0;
|
|
507
|
+
if (++state.spent > MAX_RESOLUTIONS) return object;
|
|
480
508
|
const out = /* @__PURE__ */ Object.create(null);
|
|
481
509
|
const merge = (source) => {
|
|
482
510
|
for (const [key, value] of Object.entries(source)) {
|
|
@@ -498,7 +526,12 @@ function effectiveSchema(node, root, seenRefs = /* @__PURE__ */ new Set(), depth
|
|
|
498
526
|
merge(object);
|
|
499
527
|
const ref = object["$ref"];
|
|
500
528
|
if (typeof ref === "string" && !seenRefs.has(ref)) {
|
|
501
|
-
|
|
529
|
+
let resolved;
|
|
530
|
+
if (state.refs.has(ref)) resolved = state.refs.get(ref);
|
|
531
|
+
else {
|
|
532
|
+
resolved = effectiveSchema(resolvePointer(root, ref), root, /* @__PURE__ */ new Set([...seenRefs, ref]), depth + 1);
|
|
533
|
+
state.refs.set(ref, resolved);
|
|
534
|
+
}
|
|
502
535
|
if (resolved) merge(resolved);
|
|
503
536
|
}
|
|
504
537
|
const allOf = object["allOf"];
|
|
@@ -536,16 +569,29 @@ function resolveBehavior(annotations2) {
|
|
|
536
569
|
function isEscalation(previous, next) {
|
|
537
570
|
return previous.readOnly && !next.readOnly || !previous.destructive && next.destructive || previous.idempotent && !next.idempotent || !previous.openWorld && next.openWorld;
|
|
538
571
|
}
|
|
572
|
+
var DATA_KEYWORDS = /* @__PURE__ */ new Set(["const", "default", "enum", "examples", "example"]);
|
|
573
|
+
var NAMED_SCHEMAS = /* @__PURE__ */ new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]);
|
|
539
574
|
function normalizeSchema(value) {
|
|
540
|
-
|
|
575
|
+
return normalizeNode(value, false);
|
|
576
|
+
}
|
|
577
|
+
function normalizeNode(value, namesOnly) {
|
|
578
|
+
if (Array.isArray(value)) return value.map((member) => normalizeNode(member, false));
|
|
541
579
|
if (value === null || typeof value !== "object") return value;
|
|
542
580
|
const out = /* @__PURE__ */ Object.create(null);
|
|
543
581
|
for (const [key, member] of Object.entries(value)) {
|
|
582
|
+
if (namesOnly) {
|
|
583
|
+
out[key] = normalizeNode(member, false);
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
544
586
|
if (key === "required" && Array.isArray(member) && member.every((entry) => typeof entry === "string")) {
|
|
545
587
|
out[key] = [...member].sort();
|
|
546
588
|
continue;
|
|
547
589
|
}
|
|
548
|
-
|
|
590
|
+
if (DATA_KEYWORDS.has(key)) {
|
|
591
|
+
out[key] = member;
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
out[key] = normalizeNode(member, NAMED_SCHEMAS.has(key));
|
|
549
595
|
}
|
|
550
596
|
return out;
|
|
551
597
|
}
|
|
@@ -849,8 +895,15 @@ function change(kind, server2, summary, extra) {
|
|
|
849
895
|
function same(a, b) {
|
|
850
896
|
return stableKey(a ?? null) === stableKey(b ?? null);
|
|
851
897
|
}
|
|
852
|
-
function
|
|
853
|
-
|
|
898
|
+
function groupBy(members, key) {
|
|
899
|
+
const groups = /* @__PURE__ */ new Map();
|
|
900
|
+
for (const member of members ?? []) {
|
|
901
|
+
const k = key(member);
|
|
902
|
+
const group = groups.get(k);
|
|
903
|
+
if (group) group.push(member);
|
|
904
|
+
else groups.set(k, [member]);
|
|
905
|
+
}
|
|
906
|
+
return groups;
|
|
854
907
|
}
|
|
855
908
|
function declaredNames(capabilities) {
|
|
856
909
|
const names = [];
|
|
@@ -884,12 +937,12 @@ var CAPABILITY_SEVERITY = {
|
|
|
884
937
|
low: "low"
|
|
885
938
|
};
|
|
886
939
|
function compareToolCapabilities(server2, before, after) {
|
|
887
|
-
const previous =
|
|
940
|
+
const previous = groupBy(before, (tool2) => tool2.name);
|
|
888
941
|
const changes = [];
|
|
889
942
|
for (const tool2 of after ?? []) {
|
|
890
943
|
const existing = previous.get(tool2.name);
|
|
891
944
|
if (!existing) continue;
|
|
892
|
-
const had = new Set(toolCapabilities(
|
|
945
|
+
const had = new Set(existing.flatMap((copy) => toolCapabilities(copy).map((capability) => capability.kind)));
|
|
893
946
|
for (const capability of toolCapabilities(tool2)) {
|
|
894
947
|
if (had.has(capability.kind)) continue;
|
|
895
948
|
changes.push(
|
|
@@ -941,10 +994,20 @@ function compareTool(name, before, after) {
|
|
|
941
994
|
);
|
|
942
995
|
}
|
|
943
996
|
if (changes.length === 0) {
|
|
944
|
-
|
|
997
|
+
const moved = [
|
|
998
|
+
!same(before.title, after.title) ? "title" : "",
|
|
999
|
+
!same(before.icons, after.icons) ? "icons" : "",
|
|
1000
|
+
!same(before.execution, after.execution) ? `how it may be run (${describeExecution(before.execution)} \u2192 ${describeExecution(after.execution)})` : "",
|
|
1001
|
+
!same(before.meta, after.meta) ? "_meta" : ""
|
|
1002
|
+
].filter(Boolean);
|
|
1003
|
+
changes.push(change("tool.changed", name, `tool definition changed: ${moved.length > 0 ? moved.join(", ") : "a field this report has no finding for"}`, { ...at, before, after }));
|
|
945
1004
|
}
|
|
946
1005
|
return changes;
|
|
947
1006
|
}
|
|
1007
|
+
function describeExecution(execution) {
|
|
1008
|
+
const support = execution?.["taskSupport"];
|
|
1009
|
+
return typeof support === "string" ? `task support ${support}` : "unstated";
|
|
1010
|
+
}
|
|
948
1011
|
function describeEscalation(before, after) {
|
|
949
1012
|
const gained = [];
|
|
950
1013
|
if (before.behavior.readOnly && !after.behavior.readOnly) gained.push("may now modify");
|
|
@@ -955,25 +1018,61 @@ function describeEscalation(before, after) {
|
|
|
955
1018
|
}
|
|
956
1019
|
function compareMembers(name, before, after, spec, deep) {
|
|
957
1020
|
const changes = [];
|
|
958
|
-
const previous =
|
|
959
|
-
const next =
|
|
960
|
-
for (const [key,
|
|
1021
|
+
const previous = groupBy(before, spec.key);
|
|
1022
|
+
const next = groupBy(after, spec.key);
|
|
1023
|
+
for (const [key, members] of next) {
|
|
961
1024
|
const existing = previous.get(key);
|
|
962
1025
|
if (!existing) {
|
|
963
|
-
const
|
|
1026
|
+
for (const member of members) {
|
|
1027
|
+
const extra = spec.arriving?.(member);
|
|
1028
|
+
changes.push(
|
|
1029
|
+
change(spec.added, name, `new ${spec.noun} ${spec.label(member)}${extra ? ` \xB7 ${extra}` : ""}`, { member: spec.label(member), after: member })
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
continue;
|
|
1033
|
+
}
|
|
1034
|
+
const unpairedBefore = [...existing];
|
|
1035
|
+
const unpairedAfter = [];
|
|
1036
|
+
for (const member of members) {
|
|
1037
|
+
const twin = unpairedBefore.findIndex((candidate) => candidate.digest === member.digest);
|
|
1038
|
+
if (twin === -1) unpairedAfter.push(member);
|
|
1039
|
+
else unpairedBefore.splice(twin, 1);
|
|
1040
|
+
}
|
|
1041
|
+
for (const [index, member] of unpairedAfter.entries()) {
|
|
1042
|
+
const counterpart = unpairedBefore[index] ?? existing[0];
|
|
1043
|
+
if (counterpart.digest === member.digest) {
|
|
1044
|
+
changes.push(
|
|
1045
|
+
change(spec.changed, name, `${spec.noun} ${spec.label(member)} is now declared ${members.length} times`, { member: spec.label(member), before: existing, after: members })
|
|
1046
|
+
);
|
|
1047
|
+
continue;
|
|
1048
|
+
}
|
|
964
1049
|
changes.push(
|
|
965
|
-
change(spec.
|
|
1050
|
+
...deep ? deep(key, counterpart, member) : [change(spec.changed, name, `${spec.noun} ${spec.label(member)} changed`, { member: spec.label(member), before: counterpart, after: member })]
|
|
966
1051
|
);
|
|
967
|
-
continue;
|
|
968
1052
|
}
|
|
969
|
-
|
|
970
|
-
|
|
1053
|
+
for (const member of unpairedBefore.slice(unpairedAfter.length)) {
|
|
1054
|
+
changes.push(change(spec.removed, name, `one of the ${spec.noun}s declared as ${spec.label(member)} is gone`, { member: spec.label(member), before: member }));
|
|
1055
|
+
}
|
|
971
1056
|
}
|
|
972
|
-
for (const [key,
|
|
973
|
-
if (
|
|
1057
|
+
for (const [key, members] of previous) {
|
|
1058
|
+
if (next.has(key)) continue;
|
|
1059
|
+
for (const member of members) changes.push(change(spec.removed, name, `${spec.noun} ${spec.label(member)} is gone`, { member: spec.label(member), before: member }));
|
|
974
1060
|
}
|
|
975
1061
|
return changes;
|
|
976
1062
|
}
|
|
1063
|
+
function filesMoved(was, now) {
|
|
1064
|
+
if (was === void 0 || now === void 0) return void 0;
|
|
1065
|
+
const added = Object.keys(now).filter((file) => !Object.hasOwn(was, file));
|
|
1066
|
+
const removed = Object.keys(was).filter((file) => !Object.hasOwn(now, file));
|
|
1067
|
+
const changed = Object.keys(now).filter((file) => Object.hasOwn(was, file) && was[file] !== now[file]);
|
|
1068
|
+
if (added.length + removed.length + changed.length === 0) return void 0;
|
|
1069
|
+
const list = (files) => `${files.slice(0, 3).join(", ")}${files.length > 3 ? ` +${files.length - 3}` : ""}`;
|
|
1070
|
+
return [
|
|
1071
|
+
added.length > 0 ? `added ${list(added)}` : "",
|
|
1072
|
+
removed.length > 0 ? `removed ${list(removed)}` : "",
|
|
1073
|
+
changed.length > 0 ? `different contents for ${list(changed)}` : ""
|
|
1074
|
+
].filter(Boolean).join("; ");
|
|
1075
|
+
}
|
|
977
1076
|
function compareProvenance(name, before, after) {
|
|
978
1077
|
const was = before.provenance;
|
|
979
1078
|
const now = after.provenance;
|
|
@@ -983,7 +1082,16 @@ function compareProvenance(name, before, after) {
|
|
|
983
1082
|
const unexplained = surfaceHeld ? ", and the declared surface did not change: nothing else in this report describes what the new code does" : "";
|
|
984
1083
|
const integrityMoved = was.integrity !== void 0 && now.integrity !== void 0 && was.integrity !== now.integrity;
|
|
985
1084
|
if (was.version !== void 0 && was.version === now.version) {
|
|
986
|
-
if (!integrityMoved)
|
|
1085
|
+
if (!integrityMoved) {
|
|
1086
|
+
const files = filesMoved(was.files, now.files);
|
|
1087
|
+
if (files) {
|
|
1088
|
+
return [change("server.artifact.changed", name, `the files published for ${was.name}@${was.version} are not the ones that were pinned (${files})${unexplained}`, { before: was, after: now })];
|
|
1089
|
+
}
|
|
1090
|
+
if (was.integrity !== void 0 && now.integrity === void 0) {
|
|
1091
|
+
return [change("server.artifact.changed", name, `the file pinned for ${was.name}@${was.version} is no longer published, so something else is installed in its place${unexplained}`, { before: was, after: now })];
|
|
1092
|
+
}
|
|
1093
|
+
return [];
|
|
1094
|
+
}
|
|
987
1095
|
if (was.ecosystem === "npm") {
|
|
988
1096
|
return [
|
|
989
1097
|
change(
|
|
@@ -1004,6 +1112,17 @@ function compareProvenance(name, before, after) {
|
|
|
1004
1112
|
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";
|
|
1005
1113
|
return [change("server.artifact.changed", name, `${what}${unexplained}`, { before: was, after: now })];
|
|
1006
1114
|
}
|
|
1115
|
+
function orderless(entry) {
|
|
1116
|
+
const { kind: _kind, source: _source, digest: _digest, provenance: _provenance, tools, resources, resourceTemplates, prompts, ...rest } = entry;
|
|
1117
|
+
const digests = (members) => (members ?? []).map((member) => member.digest).sort();
|
|
1118
|
+
return stableKey({
|
|
1119
|
+
...rest,
|
|
1120
|
+
tools: digests(tools),
|
|
1121
|
+
resources: digests(resources),
|
|
1122
|
+
resourceTemplates: digests(resourceTemplates),
|
|
1123
|
+
prompts: digests(prompts)
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1007
1126
|
function compareServer(name, before, after) {
|
|
1008
1127
|
const provenance2 = compareProvenance(name, before, after);
|
|
1009
1128
|
if (before.digest === after.digest) return provenance2;
|
|
@@ -1086,6 +1205,14 @@ function compareServer(name, before, after) {
|
|
|
1086
1205
|
noun: "prompt"
|
|
1087
1206
|
})
|
|
1088
1207
|
);
|
|
1208
|
+
if (changes.length === 0 && orderless(before) !== orderless(after)) {
|
|
1209
|
+
changes.push(
|
|
1210
|
+
change("server.capabilities.changed", name, "the server's pinned definition changed in a way no other finding describes; compare the lock entries", {
|
|
1211
|
+
before: before.digest,
|
|
1212
|
+
after: after.digest
|
|
1213
|
+
})
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1089
1216
|
return changes;
|
|
1090
1217
|
}
|
|
1091
1218
|
function detectRenames(before, after, removed, added) {
|
|
@@ -1134,6 +1261,9 @@ function diffLockfiles(before, after) {
|
|
|
1134
1261
|
}
|
|
1135
1262
|
|
|
1136
1263
|
// ../core/src/risk/steering.ts
|
|
1264
|
+
var INVISIBLE_CHARACTERS = "\\u00AD\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u2064\\u2066-\\u2069\\uFE00-\\uFE0D\\uFEFF\\u{E0000}-\\u{E007F}\\u{E0100}-\\u{E01EF}";
|
|
1265
|
+
var INVISIBLE_RUN = new RegExp(`[${INVISIBLE_CHARACTERS}]+`, "gu");
|
|
1266
|
+
var ONLY_INVISIBLE = new RegExp(`^[${INVISIBLE_CHARACTERS}]+$`, "u");
|
|
1137
1267
|
var PATTERNS = [
|
|
1138
1268
|
// Imperatives aimed at the reader of the prompt, not at a person reading documentation.
|
|
1139
1269
|
{ kind: "model-directive", pattern: /\b(ignore|disregard|override)\s+(all\s+)?(previous|prior|earlier|above)\b[^.]{0,80}/gi },
|
|
@@ -1152,7 +1282,7 @@ var PATTERNS = [
|
|
|
1152
1282
|
// Paths that only appear in a description when something wants their contents.
|
|
1153
1283
|
{ kind: "credential-path", pattern: /(~|\$HOME|\/home\/[\w.-]+|\/Users\/[\w.-]+)?[/\\]?\.(aws\/credentials|ssh\/id_[\w]+|npmrc|netrc|git-credentials|kube\/config|env)\b/gi },
|
|
1154
1284
|
{ kind: "credential-path", pattern: /\b(id_rsa|id_ed25519|authorized_keys|\.pem|service-account\.json)\b/gi },
|
|
1155
|
-
{ kind: "exfiltration", pattern: /\b(send|post|upload|transmit|forward|exfiltrate)\s+[^.]{0,40}\bto\s+(https?:\/\/|[\w.-]
|
|
1285
|
+
{ kind: "exfiltration", pattern: /\b(send|post|upload|transmit|forward|exfiltrate)\s+[^.]{0,40}\bto\s+(https?:\/\/|[\w.-]{1,253}\.[a-z]{2,24})/gi },
|
|
1156
1286
|
{ kind: "exfiltration", pattern: /\b(include|append|attach)\s+(its|the|their)\s+contents?\b[^.]{0,60}/gi },
|
|
1157
1287
|
/*
|
|
1158
1288
|
* The MCP-native form of a credential path. A server's own resource URIs are the secrets it
|
|
@@ -1160,16 +1290,16 @@ var PATTERNS = [
|
|
|
1160
1290
|
* `~/.aws/credentials`. Only when something is being told to go and read it: a description that
|
|
1161
1291
|
* merely names its own resource is documentation.
|
|
1162
1292
|
*/
|
|
1163
|
-
{ kind: "credential-path", pattern: /\b(read|fetch|load|access|retrieve|call)\b[^.]{0,40}?\b[a-z][\w+.-]
|
|
1293
|
+
{ kind: "credential-path", pattern: /\b(read|fetch|load|access|retrieve|call)\b[^.]{0,40}?\b[a-z][\w+.-]{0,31}:\/\/[\w./-]{0,200}?(secret|token|credential|key|auth|passwd|password|config)[\w./-]{0,200}/gi },
|
|
1164
1294
|
// Characters that make text render as something other than what it is.
|
|
1165
|
-
{ kind: "hidden-text", pattern:
|
|
1295
|
+
{ kind: "hidden-text", pattern: INVISIBLE_RUN },
|
|
1166
1296
|
/*
|
|
1167
1297
|
* Markup inside a tool description, which is the convention every published tool-poisoning
|
|
1168
1298
|
* sample follows: a pseudo-tag or an HTML comment is invisible wherever the description is
|
|
1169
1299
|
* rendered and plain text to the model that is given it. A description is documentation for a
|
|
1170
1300
|
* person; a section of it addressed to a reader who is not that person is the whole technique.
|
|
1171
1301
|
*/
|
|
1172
|
-
{ kind: "hidden-text", pattern:
|
|
1302
|
+
{ kind: "hidden-text", pattern: /<\/?[ \t]{0,8}(important|system(?:[\w-]{0,24}(?:[ \t]{1,8}[\w-]{1,24}){0,3})?|instructions?|secret|hidden|directive)[ \t]{0,8}>/gi },
|
|
1173
1303
|
{ kind: "hidden-text", pattern: /<!--[\s\S]{0,200}?-->/g }
|
|
1174
1304
|
];
|
|
1175
1305
|
var CONFUSABLES2 = {
|
|
@@ -1200,7 +1330,7 @@ function steeringSignals(text, field) {
|
|
|
1200
1330
|
const at = match.index ?? 0;
|
|
1201
1331
|
const raw = text.slice(at, at + match[0].length).trim();
|
|
1202
1332
|
if (raw.length === 0) continue;
|
|
1203
|
-
const quote =
|
|
1333
|
+
const quote = ONLY_INVISIBLE.test(raw) ? `${[...raw].length} invisible character(s)` : raw.length > 120 ? `${[...raw].slice(0, 119).join("")}\u2026` : raw;
|
|
1204
1334
|
const key = `${kind}\0${quote}`;
|
|
1205
1335
|
if (seen.has(key)) continue;
|
|
1206
1336
|
seen.add(key);
|
|
@@ -1312,18 +1442,22 @@ var red = wrap(31);
|
|
|
1312
1442
|
var green = wrap(32);
|
|
1313
1443
|
var yellow = wrap(33);
|
|
1314
1444
|
var blue = wrap(34);
|
|
1315
|
-
function visibleControls(text) {
|
|
1316
|
-
return text.replace(
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1445
|
+
function visibleControls(text, options = {}) {
|
|
1446
|
+
return text.replace(options.multiline ? CONTROLS_EXCEPT_LINES : CONTROLS, (character) => {
|
|
1447
|
+
const code2 = character.codePointAt(0) ?? 0;
|
|
1448
|
+
return code2 > 65535 ? `\\u{${code2.toString(16)}}` : `\\u${code2.toString(16).padStart(4, "0")}`;
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
var CONTROLS = new RegExp(`[\\u0000-\\u001F\\u007F-\\u009F${INVISIBLE_CHARACTERS}]`, "gu");
|
|
1452
|
+
var CONTROLS_EXCEPT_LINES = new RegExp(`[\\u0000-\\u0008\\u000B-\\u001F\\u007F-\\u009F${INVISIBLE_CHARACTERS}]`, "gu");
|
|
1453
|
+
function visibleLines(text, indent) {
|
|
1454
|
+
return text.split(/\r?\n/).map((line) => visibleControls(line)).join(`
|
|
1455
|
+
${indent}`);
|
|
1323
1456
|
}
|
|
1324
1457
|
function truncate(text, limit = 160) {
|
|
1325
|
-
const collapsed = visibleControls(text).replace(/\s+/g, " ").trim();
|
|
1326
|
-
|
|
1458
|
+
const collapsed = visibleControls(text, { multiline: true }).replace(/\s+/g, " ").trim();
|
|
1459
|
+
const points = [...collapsed];
|
|
1460
|
+
return points.length <= limit ? collapsed : `${points.slice(0, limit - 1).join("")}\u2026`;
|
|
1327
1461
|
}
|
|
1328
1462
|
function elideMiddle(raw, limit) {
|
|
1329
1463
|
const path = visibleControls(raw);
|
|
@@ -1667,6 +1801,7 @@ async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
|
1667
1801
|
const skipped = [];
|
|
1668
1802
|
const filesRead = [];
|
|
1669
1803
|
const shadowed = [];
|
|
1804
|
+
const conflicting = /* @__PURE__ */ new Map();
|
|
1670
1805
|
const problems = [];
|
|
1671
1806
|
const requested = new Set(files.filter((file) => file.client === "generic").map((file) => file.path));
|
|
1672
1807
|
for (const file of files) {
|
|
@@ -1695,9 +1830,19 @@ async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
|
1695
1830
|
const parsed = file.client === "claude-code" && file.scope === "user" ? await parseClaudeJson(raw, projectRoot, source, context) : await parseServerMap(raw, mapKey, { ...source, scope: file.scope }, context);
|
|
1696
1831
|
skipped.push(...parsed.skipped);
|
|
1697
1832
|
for (const server2 of parsed.servers.map((entry) => anchorCwd(entry, projectRoot))) {
|
|
1833
|
+
const contested = conflicting.get(server2.name);
|
|
1834
|
+
if (contested) {
|
|
1835
|
+
contested.push({ file: source.file, server: server2 });
|
|
1836
|
+
continue;
|
|
1837
|
+
}
|
|
1698
1838
|
const existing = byName2.get(server2.name);
|
|
1699
1839
|
if (existing) {
|
|
1700
|
-
|
|
1840
|
+
if (sameDefinition(existing.server, server2)) {
|
|
1841
|
+
shadowed.push({ name: server2.name, keptFrom: existing.from, alsoIn: source.file });
|
|
1842
|
+
continue;
|
|
1843
|
+
}
|
|
1844
|
+
byName2.delete(server2.name);
|
|
1845
|
+
conflicting.set(server2.name, [{ file: existing.from, server: existing.server }, { file: source.file, server: server2 }]);
|
|
1701
1846
|
continue;
|
|
1702
1847
|
}
|
|
1703
1848
|
byName2.set(server2.name, { server: server2, from: source.file });
|
|
@@ -1712,9 +1857,20 @@ async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
|
1712
1857
|
(path) => path !== void 0
|
|
1713
1858
|
),
|
|
1714
1859
|
shadowed,
|
|
1860
|
+
conflicts: [...conflicting].map(([name, definitions]) => ({ name, definitions })).sort((a, b) => a.name.localeCompare(b.name)),
|
|
1715
1861
|
problems
|
|
1716
1862
|
};
|
|
1717
1863
|
}
|
|
1864
|
+
function sameDefinition(a, b) {
|
|
1865
|
+
const essence = ({ transport: transport2 }) => transport2.type === "stdio" ? { type: "stdio", command: transport2.command, args: transport2.args, env: sorted(transport2.env), cwd: transport2.cwd ?? null } : { type: transport2.type, url: transport2.url, headers: sorted(lowercased(transport2.headers)), oauth: transport2.oauth ? sorted({ ...transport2.oauth }) : null };
|
|
1866
|
+
return JSON.stringify(essence(a)) === JSON.stringify(essence(b));
|
|
1867
|
+
}
|
|
1868
|
+
function sorted(record) {
|
|
1869
|
+
return Object.entries(record).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
1870
|
+
}
|
|
1871
|
+
function lowercased(headers) {
|
|
1872
|
+
return Object.fromEntries(Object.entries(headers).map(([name, value]) => [name.toLowerCase(), value]));
|
|
1873
|
+
}
|
|
1718
1874
|
|
|
1719
1875
|
// src/lock/build.ts
|
|
1720
1876
|
function byName(members) {
|
|
@@ -1766,6 +1922,7 @@ function lockTool(tool2, ignoredMeta) {
|
|
|
1766
1922
|
behavior: resolveBehavior(annotations2),
|
|
1767
1923
|
headerParams: headerParams.length > 0 ? headerParams : void 0,
|
|
1768
1924
|
icons: lockIcons(tool2.icons),
|
|
1925
|
+
execution: tool2.execution ? toJson(tool2.execution) : void 0,
|
|
1769
1926
|
meta: stripIgnoredMeta(toJson(tool2._meta), ignoredMeta)
|
|
1770
1927
|
});
|
|
1771
1928
|
}
|
|
@@ -1848,7 +2005,7 @@ import { readFile as readFile3 } from "fs/promises";
|
|
|
1848
2005
|
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
1849
2006
|
|
|
1850
2007
|
// src/lib/version.ts
|
|
1851
|
-
var VERSION = "0.
|
|
2008
|
+
var VERSION = "0.8.0";
|
|
1852
2009
|
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
1853
2010
|
|
|
1854
2011
|
// src/lock/provenance.ts
|
|
@@ -2040,7 +2197,7 @@ function firstPositional(args, valueFlags, explicitFlags, shortValues) {
|
|
|
2040
2197
|
let explicit;
|
|
2041
2198
|
for (let index = 0; index < args.length; index += 1) {
|
|
2042
2199
|
const arg = args[index];
|
|
2043
|
-
if (arg === "--") return { positional: args[index + 1], explicit };
|
|
2200
|
+
if (arg === "--") return { positional: args[index + 1], explicit, index: index + 1 };
|
|
2044
2201
|
const equals = arg.indexOf("=");
|
|
2045
2202
|
if (arg.startsWith("--") && equals > 0) {
|
|
2046
2203
|
if (explicitFlags.includes(arg.slice(0, equals))) explicit = arg.slice(equals + 1);
|
|
@@ -2056,7 +2213,7 @@ function firstPositional(args, valueFlags, explicitFlags, shortValues) {
|
|
|
2056
2213
|
else if (shortValues && !arg.startsWith("--") && arg.length > 2 && shortValues.has(arg.at(-1))) index += 1;
|
|
2057
2214
|
continue;
|
|
2058
2215
|
}
|
|
2059
|
-
return { positional: arg, explicit };
|
|
2216
|
+
return { positional: arg, explicit, index };
|
|
2060
2217
|
}
|
|
2061
2218
|
return { explicit };
|
|
2062
2219
|
}
|
|
@@ -2166,14 +2323,30 @@ async function resolvePypi(reference, options) {
|
|
|
2166
2323
|
const files = (body.urls ?? []).filter((file) => typeof file.filename === "string");
|
|
2167
2324
|
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];
|
|
2168
2325
|
const sha = chosen?.digests?.sha256;
|
|
2326
|
+
const published = Object.fromEntries(
|
|
2327
|
+
files.filter((file) => typeof file.digests?.sha256 === "string" && /^[a-f0-9]{64}$/.test(file.digests.sha256)).map((file) => [file.filename, `sha256:${file.digests.sha256}`]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
|
|
2328
|
+
);
|
|
2169
2329
|
return {
|
|
2170
2330
|
ecosystem: "pypi",
|
|
2171
2331
|
name: reference.name,
|
|
2172
2332
|
version: body.info.version,
|
|
2173
2333
|
...typeof sha === "string" && /^[a-f0-9]{64}$/.test(sha) ? { integrity: `sha256:${sha}` } : {},
|
|
2174
|
-
...requestedOf(reference)
|
|
2334
|
+
...requestedOf(reference),
|
|
2335
|
+
...Object.keys(published).length > 0 ? { files: published } : {}
|
|
2175
2336
|
};
|
|
2176
2337
|
}
|
|
2338
|
+
function launchPinned(transport2, provenance2) {
|
|
2339
|
+
if (provenance2?.ecosystem !== "oci" || provenance2.integrity === void 0 || !/^sha256:[a-f0-9]{64}$/.test(provenance2.integrity)) return void 0;
|
|
2340
|
+
const name = commandName(transport2.command);
|
|
2341
|
+
if (name !== "docker" && name !== "podman" || transport2.args[0] !== "run") return void 0;
|
|
2342
|
+
const { positional, index } = firstPositional(transport2.args.slice(1), DOCKER_VALUE_FLAGS, [], DOCKER_VALUE_SHORT);
|
|
2343
|
+
if (positional === void 0 || index === void 0) return void 0;
|
|
2344
|
+
const image = splitImage(positional);
|
|
2345
|
+
if (!image || image.digest) return void 0;
|
|
2346
|
+
const args = [...transport2.args];
|
|
2347
|
+
args[index + 1] = `${positional}@${provenance2.integrity}`;
|
|
2348
|
+
return { ...transport2, args };
|
|
2349
|
+
}
|
|
2177
2350
|
function imageLocation(name) {
|
|
2178
2351
|
const parts = name.split("/");
|
|
2179
2352
|
const first = parts[0];
|
|
@@ -2272,8 +2445,8 @@ function canonicalRegistry(url) {
|
|
|
2272
2445
|
}
|
|
2273
2446
|
function readSmall(path) {
|
|
2274
2447
|
try {
|
|
2275
|
-
const
|
|
2276
|
-
if (!
|
|
2448
|
+
const stat2 = statSync(path);
|
|
2449
|
+
if (!stat2.isFile() || stat2.size > 1e6) return void 0;
|
|
2277
2450
|
return readFileSync(path, "utf8");
|
|
2278
2451
|
} catch {
|
|
2279
2452
|
return void 0;
|
|
@@ -2446,9 +2619,9 @@ import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotoc
|
|
|
2446
2619
|
|
|
2447
2620
|
// src/mcp/oauth.ts
|
|
2448
2621
|
import { spawn } from "child_process";
|
|
2449
|
-
import { createHash as createHash3, randomUUID } from "crypto";
|
|
2622
|
+
import { createHash as createHash3, randomBytes, randomUUID } from "crypto";
|
|
2450
2623
|
import { readFileSync as readFileSync2 } from "fs";
|
|
2451
|
-
import { mkdir, readFile as readFile4, rm, writeFile } from "fs/promises";
|
|
2624
|
+
import { chmod, lstat, mkdir, readFile as readFile4, rename, rm, writeFile } from "fs/promises";
|
|
2452
2625
|
import { homedir as homedir4, platform as platform2 } from "os";
|
|
2453
2626
|
import { dirname as dirname2, join as join3 } from "path";
|
|
2454
2627
|
import { ClientCredentialsProvider, UnauthorizedError } from "@modelcontextprotocol/client";
|
|
@@ -2468,6 +2641,23 @@ var InteractiveAuthRequiredError = class extends Error {
|
|
|
2468
2641
|
}
|
|
2469
2642
|
serverName;
|
|
2470
2643
|
};
|
|
2644
|
+
async function writeOwnerOnly(path, contents) {
|
|
2645
|
+
const directory = dirname2(path);
|
|
2646
|
+
await mkdir(directory, { recursive: true, mode: 448 });
|
|
2647
|
+
const found = await lstat(directory);
|
|
2648
|
+
if (found.isSymbolicLink() || !found.isDirectory()) throw new Error(`refusing to store credentials in ${directory}: it is not a plain directory`);
|
|
2649
|
+
await chmod(directory, 448);
|
|
2650
|
+
const temporary = `${path}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`;
|
|
2651
|
+
try {
|
|
2652
|
+
await writeFile(temporary, contents, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
2653
|
+
await chmod(temporary, 384);
|
|
2654
|
+
await rename(temporary, path);
|
|
2655
|
+
} catch (error) {
|
|
2656
|
+
await rm(temporary, { force: true }).catch(() => {
|
|
2657
|
+
});
|
|
2658
|
+
throw error;
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2471
2661
|
var FileTokenProvider = class {
|
|
2472
2662
|
constructor(serverName, serverUrl, options = { interactive: false }) {
|
|
2473
2663
|
this.serverName = serverName;
|
|
@@ -2510,10 +2700,8 @@ var FileTokenProvider = class {
|
|
|
2510
2700
|
async write(patch) {
|
|
2511
2701
|
const next = { ...await this.read(), ...patch, serverUrl: this.serverUrl };
|
|
2512
2702
|
this.cache = next;
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
await writeFile(path, `${JSON.stringify(next, null, 2)}
|
|
2516
|
-
`, { encoding: "utf8", mode: 384 });
|
|
2703
|
+
await writeOwnerOnly(credentialPath(this.serverUrl), `${JSON.stringify(next, null, 2)}
|
|
2704
|
+
`);
|
|
2517
2705
|
}
|
|
2518
2706
|
async clientInformation() {
|
|
2519
2707
|
return (await this.read()).clientInformation;
|
|
@@ -2654,13 +2842,140 @@ function isAuthFailure(error) {
|
|
|
2654
2842
|
}
|
|
2655
2843
|
const outer = `${error instanceof Error ? error.message : String(error)}`;
|
|
2656
2844
|
const inner = error instanceof UnreachableServerError && error.cause instanceof Error ? error.cause.message : "";
|
|
2657
|
-
const text = `${outer} ${inner}`.toLowerCase();
|
|
2658
|
-
return /\b(401|403)\b|unauthorized|forbidden|invalid or missing
|
|
2845
|
+
const text = `${outer.slice(0, 4096)} ${inner.slice(0, 4096)}`.toLowerCase();
|
|
2846
|
+
return /\b(401|403)\b|unauthorized|forbidden|invalid or missing[^\n]{0,80}?token|authentication required|invalid_client|dynamic client registration/.test(text);
|
|
2659
2847
|
}
|
|
2660
2848
|
|
|
2661
2849
|
// src/mcp/connect.ts
|
|
2662
2850
|
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
2663
2851
|
var STDERR_KEEP_BYTES = 2e3;
|
|
2852
|
+
var MAX_SURFACE_BYTES = 32 * 1024 * 1024;
|
|
2853
|
+
var SurfaceGuard = class {
|
|
2854
|
+
constructor(stop) {
|
|
2855
|
+
this.stop = stop;
|
|
2856
|
+
}
|
|
2857
|
+
stop;
|
|
2858
|
+
messageBytes = 0;
|
|
2859
|
+
wireBytes = 0;
|
|
2860
|
+
refusal;
|
|
2861
|
+
refuse(reason) {
|
|
2862
|
+
if (this.refusal !== void 0) return;
|
|
2863
|
+
this.refusal = reason;
|
|
2864
|
+
this.stop();
|
|
2865
|
+
}
|
|
2866
|
+
/** Bytes as they arrive over HTTP, before anything is parsed. */
|
|
2867
|
+
received(bytes) {
|
|
2868
|
+
this.wireBytes += bytes;
|
|
2869
|
+
if (this.wireBytes <= MAX_SURFACE_BYTES) return true;
|
|
2870
|
+
this.refuse(tooLarge());
|
|
2871
|
+
return false;
|
|
2872
|
+
}
|
|
2873
|
+
/** A parsed message, before the client library sees it. False when it must not be passed on. */
|
|
2874
|
+
admit(message) {
|
|
2875
|
+
if (this.refusal !== void 0) return false;
|
|
2876
|
+
const { bytes, prototypeKey } = inspectMessage(message);
|
|
2877
|
+
if (prototypeKey) {
|
|
2878
|
+
this.refuse("the server's reply contains a key named `__proto__`, which the MCP client library drops before it can be read; a surface that cannot be read as it was sent cannot be pinned");
|
|
2879
|
+
return false;
|
|
2880
|
+
}
|
|
2881
|
+
this.messageBytes += bytes;
|
|
2882
|
+
if (this.messageBytes > MAX_SURFACE_BYTES) {
|
|
2883
|
+
this.refuse(tooLarge());
|
|
2884
|
+
return false;
|
|
2885
|
+
}
|
|
2886
|
+
return true;
|
|
2887
|
+
}
|
|
2888
|
+
};
|
|
2889
|
+
function tooLarge() {
|
|
2890
|
+
return `the server sent more than ${MAX_SURFACE_BYTES / 1024 / 1024} MB while being audited, so it was stopped there; nothing was pinned`;
|
|
2891
|
+
}
|
|
2892
|
+
function inspectMessage(message) {
|
|
2893
|
+
let bytes = 0;
|
|
2894
|
+
let prototypeKey = false;
|
|
2895
|
+
const pending = [message];
|
|
2896
|
+
while (pending.length > 0) {
|
|
2897
|
+
const node = pending.pop();
|
|
2898
|
+
if (typeof node === "string") bytes += node.length + 2;
|
|
2899
|
+
else if (Array.isArray(node)) {
|
|
2900
|
+
bytes += 2;
|
|
2901
|
+
for (const member of node) pending.push(member);
|
|
2902
|
+
} else if (node !== null && typeof node === "object") {
|
|
2903
|
+
bytes += 2;
|
|
2904
|
+
if (Object.hasOwn(node, "__proto__")) prototypeKey = true;
|
|
2905
|
+
for (const key of Object.keys(node)) {
|
|
2906
|
+
bytes += key.length + 3;
|
|
2907
|
+
pending.push(node[key]);
|
|
2908
|
+
}
|
|
2909
|
+
} else bytes += 5;
|
|
2910
|
+
}
|
|
2911
|
+
return { bytes, prototypeKey };
|
|
2912
|
+
}
|
|
2913
|
+
var INSPECTED = /* @__PURE__ */ Symbol("nulladrift.inspected");
|
|
2914
|
+
function guardMessages(transport2, guard) {
|
|
2915
|
+
let current;
|
|
2916
|
+
Object.defineProperty(transport2, "onmessage", {
|
|
2917
|
+
configurable: true,
|
|
2918
|
+
enumerable: true,
|
|
2919
|
+
get: () => current,
|
|
2920
|
+
set: (handler) => {
|
|
2921
|
+
if (handler === void 0 || handler[INSPECTED]) {
|
|
2922
|
+
current = handler;
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
const wrapped = ((message, extra) => {
|
|
2926
|
+
if (guard.admit(message)) handler(message, extra);
|
|
2927
|
+
});
|
|
2928
|
+
wrapped[INSPECTED] = true;
|
|
2929
|
+
current = wrapped;
|
|
2930
|
+
}
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
function guardedFetch(guard) {
|
|
2934
|
+
return (async (input, init) => {
|
|
2935
|
+
const response = await fetch(input, init);
|
|
2936
|
+
if (!response.body) return response;
|
|
2937
|
+
const reader = response.body.getReader();
|
|
2938
|
+
const body = new ReadableStream({
|
|
2939
|
+
async pull(controller) {
|
|
2940
|
+
const { done, value } = await reader.read();
|
|
2941
|
+
if (done) {
|
|
2942
|
+
controller.close();
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
if (!guard.received(value.byteLength)) {
|
|
2946
|
+
await reader.cancel().catch(() => {
|
|
2947
|
+
});
|
|
2948
|
+
controller.error(new Error(guard.refusal));
|
|
2949
|
+
return;
|
|
2950
|
+
}
|
|
2951
|
+
controller.enqueue(value);
|
|
2952
|
+
},
|
|
2953
|
+
cancel: (reason) => reader.cancel(reason)
|
|
2954
|
+
});
|
|
2955
|
+
return new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers });
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
var UNSENDABLE = /[\r\n\0]/;
|
|
2959
|
+
function refuseUnsendable(server2) {
|
|
2960
|
+
const { transport: transport2 } = server2;
|
|
2961
|
+
if (transport2.type === "stdio") {
|
|
2962
|
+
for (const [name, value] of Object.entries(transport2.env)) {
|
|
2963
|
+
if (value.includes("\0")) throw new UnreachableServerError(server2.name, `the environment variable ${name} contains a NUL character, which a process cannot be given; check where its value comes from`);
|
|
2964
|
+
}
|
|
2965
|
+
transport2.args.forEach((arg, index) => {
|
|
2966
|
+
if (arg.includes("\0")) throw new UnreachableServerError(server2.name, `argument ${index + 1} contains a NUL character, which a process cannot be given`);
|
|
2967
|
+
});
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
for (const [name, value] of Object.entries(transport2.headers)) {
|
|
2971
|
+
if (UNSENDABLE.test(value)) {
|
|
2972
|
+
throw new UnreachableServerError(
|
|
2973
|
+
server2.name,
|
|
2974
|
+
`the value of the ${name} header contains a line break or NUL, which HTTP does not allow; check the variable it is read from (a secret saved with a trailing newline is the usual cause)`
|
|
2975
|
+
);
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2664
2979
|
function buildTransport(server2, captureStderr = () => {
|
|
2665
2980
|
}, options = {}) {
|
|
2666
2981
|
const { transport: transport2 } = server2;
|
|
@@ -2681,8 +2996,9 @@ function buildTransport(server2, captureStderr = () => {
|
|
|
2681
2996
|
const headers = { "user-agent": USER_AGENT, ...transport2.headers };
|
|
2682
2997
|
const url = new URL(transport2.url);
|
|
2683
2998
|
const authProvider = createAuthProvider(server2, options);
|
|
2684
|
-
|
|
2685
|
-
return new
|
|
2999
|
+
const custom = options.fetch ? { fetch: options.fetch } : {};
|
|
3000
|
+
if (transport2.type === "sse") return new SSEClientTransport(url, { requestInit: { headers }, authProvider, ...custom });
|
|
3001
|
+
return new StreamableHTTPClientTransport(url, { requestInit: { headers }, authProvider, ...custom });
|
|
2686
3002
|
}
|
|
2687
3003
|
function diagnosticLines(stderr, limit = 3) {
|
|
2688
3004
|
const lines = stderr.split("\n").map((line) => line.trimEnd()).filter((line) => line.trim().length > 0).filter((line) => !/^\s*(at\s|\^+$|[}\])]+$|Node\.js v[\d.]+$)/.test(line));
|
|
@@ -2706,17 +3022,24 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
2706
3022
|
versionNegotiation: { mode: "auto", probe: { timeoutMs } }
|
|
2707
3023
|
}
|
|
2708
3024
|
);
|
|
3025
|
+
refuseUnsendable(server2);
|
|
2709
3026
|
let transport2;
|
|
3027
|
+
const guard = new SurfaceGuard(() => {
|
|
3028
|
+
void transport2?.close().catch(() => {
|
|
3029
|
+
});
|
|
3030
|
+
});
|
|
2710
3031
|
try {
|
|
2711
|
-
transport2 = buildTransport(server2, captureStderr, options);
|
|
3032
|
+
transport2 = buildTransport(server2, captureStderr, { ...options, fetch: guardedFetch(guard) });
|
|
2712
3033
|
} catch (error) {
|
|
2713
3034
|
throw new UnreachableServerError(server2.name, `could not prepare transport: ${error.message}`, error);
|
|
2714
3035
|
}
|
|
3036
|
+
guardMessages(transport2, guard);
|
|
2715
3037
|
try {
|
|
2716
3038
|
await client.connect(transport2, { timeout: timeoutMs });
|
|
2717
3039
|
} catch (error) {
|
|
2718
3040
|
await client.close().catch(() => {
|
|
2719
3041
|
});
|
|
3042
|
+
if (guard.refusal !== void 0) throw new UnreachableServerError(server2.name, guard.refusal, error);
|
|
2720
3043
|
const detail = stderrBuffer.trim();
|
|
2721
3044
|
throw new UnreachableServerError(
|
|
2722
3045
|
server2.name,
|
|
@@ -2728,6 +3051,7 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
2728
3051
|
return {
|
|
2729
3052
|
client,
|
|
2730
3053
|
stderr: () => stderrBuffer,
|
|
3054
|
+
refused: () => guard.refusal,
|
|
2731
3055
|
close: async () => {
|
|
2732
3056
|
await client.close().catch(() => {
|
|
2733
3057
|
});
|
|
@@ -2778,7 +3102,7 @@ async function listAllTools(client, timeoutMs) {
|
|
|
2778
3102
|
let cursor;
|
|
2779
3103
|
for (let page = 0; page < MAX_LIST_PAGES; page += 1) {
|
|
2780
3104
|
const result = await client.request({ method: "tools/list", params: cursor === void 0 ? {} : { cursor } }, { timeout: timeoutMs });
|
|
2781
|
-
|
|
3105
|
+
for (const tool2 of result.tools) tools.push(tool2);
|
|
2782
3106
|
cursor = result.nextCursor;
|
|
2783
3107
|
if (cursor === void 0) return tools;
|
|
2784
3108
|
if (cursors.has(cursor)) throw new Error("tools/list: the server repeated a page cursor, so the listing would never end");
|
|
@@ -2811,7 +3135,8 @@ function readServerInfo(client) {
|
|
|
2811
3135
|
title: info.title,
|
|
2812
3136
|
version: info.version,
|
|
2813
3137
|
description: info.description,
|
|
2814
|
-
websiteUrl: info.websiteUrl
|
|
3138
|
+
websiteUrl: info.websiteUrl,
|
|
3139
|
+
icons: lockIcons(info.icons)
|
|
2815
3140
|
};
|
|
2816
3141
|
}
|
|
2817
3142
|
async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
@@ -2836,6 +3161,10 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
|
2836
3161
|
connection = opened;
|
|
2837
3162
|
try {
|
|
2838
3163
|
return await readSurface(opened.client, server2, timeoutMs);
|
|
3164
|
+
} catch (error) {
|
|
3165
|
+
const refused = opened.refused();
|
|
3166
|
+
if (refused !== void 0) throw new UnreachableServerError(server2.name, refused, error);
|
|
3167
|
+
throw error;
|
|
2839
3168
|
} finally {
|
|
2840
3169
|
await opened.close();
|
|
2841
3170
|
}
|
|
@@ -2875,8 +3204,9 @@ async function provenanceOf(server2, options) {
|
|
|
2875
3204
|
if (server2.transport.type !== "stdio") return { unverified: false };
|
|
2876
3205
|
const reference = referenceOf(server2.transport, options.projectRoot);
|
|
2877
3206
|
if (!reference) return { unverified: false };
|
|
2878
|
-
if (fetchedElsewhere(server2.transport, reference, { projectRoot: options.projectRoot })) return { unverified: true };
|
|
2879
3207
|
const previous = options.previous?.subjects[server2.name]?.provenance;
|
|
3208
|
+
const elsewhere = fetchedElsewhere(server2.transport, reference, { projectRoot: options.projectRoot });
|
|
3209
|
+
if (elsewhere) return { unverified: true, ...previous ? { displaced: { previous, why: elsewhere } } : {} };
|
|
2880
3210
|
if (options.provenance === false) {
|
|
2881
3211
|
const kept2 = carriedForward(previous, reference);
|
|
2882
3212
|
return { ...kept2 ? { provenance: kept2 } : {}, unverified: true };
|
|
@@ -2904,14 +3234,15 @@ async function captureAll(options) {
|
|
|
2904
3234
|
const discovery = await discoverServers(options.projectRoot, options.configFiles, { userConfigs: options.userConfigs === true });
|
|
2905
3235
|
const captured = await mapWithLimit(discovery.servers, options.concurrency ?? 4, async (server2) => {
|
|
2906
3236
|
try {
|
|
2907
|
-
const { provenance: provenance2, unverified: unverified2 } = await provenanceOf(server2, options);
|
|
2908
|
-
const
|
|
3237
|
+
const { provenance: provenance2, unverified: unverified2, displaced: displaced2 } = await provenanceOf(server2, options);
|
|
3238
|
+
const pinned = server2.transport.type === "stdio" ? launchPinned(server2.transport, provenance2) : void 0;
|
|
3239
|
+
const surface = await captureSurface(pinned ? { ...server2, transport: pinned } : server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2);
|
|
2909
3240
|
const entry = buildLockedServer(server2, surface, options.policy);
|
|
2910
3241
|
options.onServerDone?.(server2.name, "captured");
|
|
2911
|
-
return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2 };
|
|
3242
|
+
return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2, displaced: displaced2 };
|
|
2912
3243
|
} catch (error) {
|
|
2913
3244
|
options.onServerDone?.(server2.name, "failed");
|
|
2914
|
-
const reason = error instanceof UnreachableServerError ? error.message : error.message;
|
|
3245
|
+
const reason = withoutSecrets(error instanceof UnreachableServerError ? error.message : error.message, server2);
|
|
2915
3246
|
const kind = authFailureKind(error) ?? "unreachable";
|
|
2916
3247
|
return { name: server2.name, failure: { server: server2.name, reason, kind } };
|
|
2917
3248
|
}
|
|
@@ -2919,14 +3250,30 @@ async function captureAll(options) {
|
|
|
2919
3250
|
const subjects = {};
|
|
2920
3251
|
const unreachable = [];
|
|
2921
3252
|
const unverified = [];
|
|
3253
|
+
const displaced = [];
|
|
3254
|
+
const unaudited = {};
|
|
3255
|
+
const configured = new Map(discovery.servers.map((server2) => [server2.name, server2]));
|
|
2922
3256
|
for (const result of captured) {
|
|
2923
3257
|
if ("entry" in result && result.entry) {
|
|
2924
3258
|
subjects[result.name] = result.entry;
|
|
2925
3259
|
if (result.unverified) unverified.push(result.name);
|
|
2926
|
-
|
|
3260
|
+
if (result.displaced) displaced.push({ server: result.name, ...result.displaced });
|
|
3261
|
+
} else if ("failure" in result && result.failure) {
|
|
3262
|
+
unreachable.push(result.failure);
|
|
3263
|
+
const server2 = configured.get(result.name);
|
|
3264
|
+
unaudited[result.name] = server2 ? { transport: lockTransport(server2) } : {};
|
|
3265
|
+
}
|
|
2927
3266
|
}
|
|
2928
3267
|
for (const skipped of discovery.skipped) {
|
|
2929
3268
|
unreachable.push({ server: skipped.serverName, reason: skipped.message, kind: "unreachable" });
|
|
3269
|
+
unaudited[skipped.serverName] = {};
|
|
3270
|
+
}
|
|
3271
|
+
for (const conflict of discovery.conflicts) {
|
|
3272
|
+
unreachable.push({
|
|
3273
|
+
server: conflict.name,
|
|
3274
|
+
reason: `defined differently in ${conflict.definitions.map((definition) => definition.file).join(" and ")}. Each client runs the one in its own file, so auditing one of them would vouch for the others. Give them different names, or make them the same.`,
|
|
3275
|
+
kind: "unreachable"
|
|
3276
|
+
});
|
|
2930
3277
|
}
|
|
2931
3278
|
for (const problem of discovery.problems) {
|
|
2932
3279
|
unreachable.push({ server: problem.file, reason: problem.reason, kind: "unreachable" });
|
|
@@ -2940,13 +3287,74 @@ async function captureAll(options) {
|
|
|
2940
3287
|
},
|
|
2941
3288
|
unreachable,
|
|
2942
3289
|
discovery,
|
|
2943
|
-
unverified: unverified.sort()
|
|
3290
|
+
unverified: unverified.sort(),
|
|
3291
|
+
displaced,
|
|
3292
|
+
unaudited,
|
|
3293
|
+
conflicted: discovery.conflicts.map((conflict) => conflict.name)
|
|
2944
3294
|
};
|
|
2945
3295
|
}
|
|
3296
|
+
function acknowledged(committed, name, now) {
|
|
3297
|
+
const agreed = committed.unaudited?.[name];
|
|
3298
|
+
return agreed !== void 0 && JSON.stringify(agreed.transport ?? null) === JSON.stringify(now.transport ?? null);
|
|
3299
|
+
}
|
|
3300
|
+
function compareWithLock(committed, result) {
|
|
3301
|
+
const changes = diffLockfiles(committed, result.lock);
|
|
3302
|
+
for (const moved of result.displaced) {
|
|
3303
|
+
const was = `${moved.previous.name}${moved.previous.version ? `@${moved.previous.version}` : ""}`;
|
|
3304
|
+
changes.push({
|
|
3305
|
+
kind: "server.artifact.changed",
|
|
3306
|
+
severity: SEVERITY["server.artifact.changed"],
|
|
3307
|
+
server: moved.server,
|
|
3308
|
+
summary: `${was} was pinned from its registry, and now ${moved.why}: what runs is not what was pinned, and nothing here can check it`,
|
|
3309
|
+
before: moved.previous
|
|
3310
|
+
});
|
|
3311
|
+
}
|
|
3312
|
+
const failed = new Map(result.unreachable.map((failure) => [failure.server, failure.reason]));
|
|
3313
|
+
for (const [name, now] of Object.entries(result.unaudited)) {
|
|
3314
|
+
if (committed.subjects[name] !== void 0 || acknowledged(committed, name, now)) continue;
|
|
3315
|
+
changes.push({
|
|
3316
|
+
kind: "server.added",
|
|
3317
|
+
severity: SEVERITY["server.added"],
|
|
3318
|
+
server: name,
|
|
3319
|
+
summary: `${committed.unaudited?.[name] ? "a server left unaudited is now reached differently, and" : "new server, which"} could not be audited: ${failed.get(name) ?? "it did not answer"}`
|
|
3320
|
+
});
|
|
3321
|
+
}
|
|
3322
|
+
for (const name of result.conflicted) {
|
|
3323
|
+
if (committed.subjects[name] !== void 0) continue;
|
|
3324
|
+
changes.push({
|
|
3325
|
+
kind: "server.added",
|
|
3326
|
+
severity: SEVERITY["server.added"],
|
|
3327
|
+
server: name,
|
|
3328
|
+
summary: `new server, defined differently in two config files: ${failed.get(name) ?? ""}`
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
return sortChanges(changes);
|
|
3332
|
+
}
|
|
3333
|
+
function unauditedToRecord(result, keep = () => true) {
|
|
3334
|
+
const entries = Object.entries(result.unaudited).filter(([name]) => keep(name));
|
|
3335
|
+
return entries.length > 0 ? Object.fromEntries(entries) : void 0;
|
|
3336
|
+
}
|
|
3337
|
+
function withoutSecrets(reason, server2) {
|
|
3338
|
+
const { transport: transport2 } = server2;
|
|
3339
|
+
const secrets = [];
|
|
3340
|
+
if (transport2.type === "stdio") {
|
|
3341
|
+
for (const [name, value] of Object.entries(transport2.env)) {
|
|
3342
|
+
if (isCredentialName(name) || value.length >= 16 && !/[\s/\\]/.test(value)) secrets.push(value);
|
|
3343
|
+
}
|
|
3344
|
+
} else {
|
|
3345
|
+
for (const value of Object.values(transport2.headers)) secrets.push(value, ...value.split(/\s+/));
|
|
3346
|
+
if (transport2.oauth?.clientSecret) secrets.push(transport2.oauth.clientSecret);
|
|
3347
|
+
}
|
|
3348
|
+
let out = reason;
|
|
3349
|
+
for (const secret of [...new Set(secrets)].filter((value) => value.length >= 8).sort((a, b) => b.length - a.length)) {
|
|
3350
|
+
out = out.split(secret).join("[redacted]");
|
|
3351
|
+
}
|
|
3352
|
+
return out;
|
|
3353
|
+
}
|
|
2946
3354
|
|
|
2947
3355
|
// src/lock/io.ts
|
|
2948
3356
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
2949
|
-
import { lstat, readFile as readFile5, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
|
|
3357
|
+
import { lstat as lstat2, readFile as readFile5, rename as rename2, rm as rm2, writeFile as writeFile2 } from "fs/promises";
|
|
2950
3358
|
|
|
2951
3359
|
// src/lock/schema.ts
|
|
2952
3360
|
import { z as z2 } from "zod";
|
|
@@ -2994,6 +3402,7 @@ var tool = z2.object({
|
|
|
2994
3402
|
behavior,
|
|
2995
3403
|
headerParams: z2.array(z2.string()).optional(),
|
|
2996
3404
|
icons: z2.array(icon).optional(),
|
|
3405
|
+
execution: jsonObject.optional(),
|
|
2997
3406
|
meta: jsonObject.optional(),
|
|
2998
3407
|
digest: digestString
|
|
2999
3408
|
});
|
|
@@ -3044,7 +3453,8 @@ var provenance = z2.object({
|
|
|
3044
3453
|
name: z2.string(),
|
|
3045
3454
|
version: z2.string().optional(),
|
|
3046
3455
|
integrity: z2.string().optional(),
|
|
3047
|
-
requested: z2.string().optional()
|
|
3456
|
+
requested: z2.string().optional(),
|
|
3457
|
+
files: z2.record(z2.string(), z2.string()).optional()
|
|
3048
3458
|
});
|
|
3049
3459
|
var server = z2.object({
|
|
3050
3460
|
kind: z2.literal("mcp-server"),
|
|
@@ -3065,7 +3475,8 @@ var server = z2.object({
|
|
|
3065
3475
|
title: z2.string().optional(),
|
|
3066
3476
|
version: z2.string().optional(),
|
|
3067
3477
|
description: z2.string().optional(),
|
|
3068
|
-
websiteUrl: z2.string().optional()
|
|
3478
|
+
websiteUrl: z2.string().optional(),
|
|
3479
|
+
icons: z2.array(icon).optional()
|
|
3069
3480
|
}).optional(),
|
|
3070
3481
|
capabilities: jsonObject.optional(),
|
|
3071
3482
|
instructions: z2.string().optional(),
|
|
@@ -3097,20 +3508,22 @@ var lockfileSchema = z2.object({
|
|
|
3097
3508
|
* union of one looks odd now and is the point: a second kind is a new member here, and every
|
|
3098
3509
|
* switch over the result stops compiling until it handles it.
|
|
3099
3510
|
*/
|
|
3100
|
-
subjects: z2.record(z2.string(), z2.discriminatedUnion("kind", [server]))
|
|
3511
|
+
subjects: z2.record(z2.string(), z2.discriminatedUnion("kind", [server])),
|
|
3512
|
+
// Listed here or lost, like provenance: an acknowledgement stripped on read is one `check` ignores.
|
|
3513
|
+
unaudited: z2.record(z2.string(), z2.object({ transport: transport.optional() })).optional()
|
|
3101
3514
|
});
|
|
3102
3515
|
|
|
3103
3516
|
// src/lock/io.ts
|
|
3104
3517
|
var DEFAULT_LOCK_FILENAME = "mcp.lock";
|
|
3105
3518
|
var KEY_ORDER = {
|
|
3106
|
-
root: ["lockfileVersion", "generatedBy", "policy", "subjects"],
|
|
3519
|
+
root: ["lockfileVersion", "generatedBy", "policy", "subjects", "unaudited"],
|
|
3107
3520
|
policy: ["ignoreMetaPrefixes", "allowUnreachable", "deniedCapabilities"],
|
|
3108
3521
|
server: ["kind", "source", "transport", "protocol", "serverInfo", "capabilities", "instructions", "tools", "resources", "resourceTemplates", "prompts", "digest"],
|
|
3109
3522
|
source: ["client", "file", "scope"],
|
|
3110
3523
|
transport: ["type", "command", "args", "envKeys", "cwd", "url", "headerKeys"],
|
|
3111
3524
|
protocol: ["era", "version", "supportedVersions"],
|
|
3112
|
-
serverInfo: ["name", "title", "version", "description", "websiteUrl"],
|
|
3113
|
-
tool: ["name", "title", "description", "inputSchema", "outputSchema", "annotations", "behavior", "headerParams", "icons", "meta", "digest"],
|
|
3525
|
+
serverInfo: ["name", "title", "version", "description", "websiteUrl", "icons"],
|
|
3526
|
+
tool: ["name", "title", "description", "inputSchema", "outputSchema", "annotations", "behavior", "headerParams", "icons", "execution", "meta", "digest"],
|
|
3114
3527
|
resource: ["uri", "name", "title", "description", "mimeType", "annotations", "icons", "meta", "digest"],
|
|
3115
3528
|
resourceTemplate: ["uriTemplate", "name", "title", "description", "mimeType", "annotations", "icons", "meta", "digest"],
|
|
3116
3529
|
prompt: ["name", "title", "description", "arguments", "icons", "meta", "digest"],
|
|
@@ -3173,7 +3586,10 @@ function serializeLockfile(lock) {
|
|
|
3173
3586
|
// Names sorted so that adding one produces a localized diff.
|
|
3174
3587
|
subjects: Object.fromEntries(
|
|
3175
3588
|
Object.keys(lock.subjects).sort().map((name) => [name, lock.subjects[name]])
|
|
3176
|
-
)
|
|
3589
|
+
),
|
|
3590
|
+
unaudited: lock.unaudited && Object.keys(lock.unaudited).length > 0 ? Object.fromEntries(
|
|
3591
|
+
Object.keys(lock.unaudited).sort().map((name) => [name, lock.unaudited[name]])
|
|
3592
|
+
) : void 0
|
|
3177
3593
|
};
|
|
3178
3594
|
const pad = INDENT;
|
|
3179
3595
|
const parts = [];
|
|
@@ -3244,7 +3660,7 @@ async function readLockfile(path) {
|
|
|
3244
3660
|
}
|
|
3245
3661
|
async function writeLockfile(path, lock) {
|
|
3246
3662
|
try {
|
|
3247
|
-
const link = await
|
|
3663
|
+
const link = await lstat2(path).catch(() => void 0);
|
|
3248
3664
|
if (link?.isSymbolicLink()) {
|
|
3249
3665
|
throw new LockfileError(`refusing to write ${path}: it is a symbolic link. A lockfile is a real file in the project, and following the link would write somewhere else.`);
|
|
3250
3666
|
}
|
|
@@ -3255,7 +3671,7 @@ async function writeLockfile(path, lock) {
|
|
|
3255
3671
|
const temporary = `${path}.${randomUUID2()}.tmp`;
|
|
3256
3672
|
await writeFile2(temporary, serializeLockfile(lock), { encoding: "utf8", flag: "wx" });
|
|
3257
3673
|
try {
|
|
3258
|
-
await
|
|
3674
|
+
await rename2(temporary, path);
|
|
3259
3675
|
} catch (error) {
|
|
3260
3676
|
await rm2(temporary, { force: true }).catch(() => {
|
|
3261
3677
|
});
|
|
@@ -3328,7 +3744,8 @@ function renderViolations(report) {
|
|
|
3328
3744
|
for (const violation of found) {
|
|
3329
3745
|
lines.push(
|
|
3330
3746
|
` ${red("denied")} ${bold(visibleControls(`${violation.server} \u203A ${violation.tool}`))} ${dim(violation.kind)}`,
|
|
3331
|
-
|
|
3747
|
+
// The evidence is an argument name, which the server chose.
|
|
3748
|
+
` ${violation.severity} \xB7 ${visibleControls(violation.evidence)}`
|
|
3332
3749
|
);
|
|
3333
3750
|
}
|
|
3334
3751
|
lines.push(
|
|
@@ -3360,7 +3777,7 @@ function renderHumanReport(report) {
|
|
|
3360
3777
|
lines.push(bold(`Could not audit ${report.unreachable.length} server(s):`), "");
|
|
3361
3778
|
for (const failure of report.unreachable) {
|
|
3362
3779
|
const label = failure.kind === "auth" ? yellow("needs creds") : failure.kind === "forbidden" ? yellow("not permitted") : red("unreachable");
|
|
3363
|
-
lines.push(` ${label} ${bold(visibleControls(failure.server))}`, ` ${
|
|
3780
|
+
lines.push(` ${label} ${bold(visibleControls(failure.server))}`, ` ${visibleLines(failure.reason, " ")}`, "");
|
|
3364
3781
|
}
|
|
3365
3782
|
}
|
|
3366
3783
|
const unverified = report.unverified ?? [];
|
|
@@ -3437,7 +3854,9 @@ function renderJsonReport(report, exitCode) {
|
|
|
3437
3854
|
*/
|
|
3438
3855
|
steering: (report.steering ?? []).reduce((sum, server2) => sum + server2.signals.length, 0),
|
|
3439
3856
|
/** Unlike steering, these DO decide the exit code. */
|
|
3440
|
-
violations: (report.violations ?? []).length
|
|
3857
|
+
violations: (report.violations ?? []).length,
|
|
3858
|
+
/** Answered, but what they run could not be established. Never part of the verdict. */
|
|
3859
|
+
unverified: (report.unverified ?? []).length
|
|
3441
3860
|
},
|
|
3442
3861
|
changes: report.changes.map((change2) => ({
|
|
3443
3862
|
kind: change2.kind,
|
|
@@ -3451,7 +3870,8 @@ function renderJsonReport(report, exitCode) {
|
|
|
3451
3870
|
unreachable: report.unreachable,
|
|
3452
3871
|
/** Text that began addressing the model since the lock was approved. Reported, never gated. */
|
|
3453
3872
|
steering: report.steering ?? [],
|
|
3454
|
-
violations: report.violations ?? []
|
|
3873
|
+
violations: report.violations ?? [],
|
|
3874
|
+
unverified: report.unverified ?? []
|
|
3455
3875
|
},
|
|
3456
3876
|
null,
|
|
3457
3877
|
2
|
|
@@ -3487,6 +3907,7 @@ var LEVEL = {
|
|
|
3487
3907
|
};
|
|
3488
3908
|
var DENIED_RULE = "policy.capability.denied";
|
|
3489
3909
|
var STEERING_RULE = "steering.passage.arrived";
|
|
3910
|
+
var UNVERIFIED_RULE = "server.artifact.unverified";
|
|
3490
3911
|
var RULE_HELP = {
|
|
3491
3912
|
"tool.capability.gained": "A tool gained a capability it did not declare before, derived from its name, its argument names and the shape of its schema. The severity is the capability's, not the schema change's: gaining a `command` argument is not the same finding as gaining an optional string.",
|
|
3492
3913
|
"tool.description.changed": "A tool description is injected into the model's context. A change here can carry instructions to the agent and should be read in full, not skimmed.",
|
|
@@ -3512,6 +3933,7 @@ function renderSarifReport(report, options = {}) {
|
|
|
3512
3933
|
const used = [...new Set(report.changes.map((change2) => change2.kind))].sort();
|
|
3513
3934
|
const violations = report.violations ?? [];
|
|
3514
3935
|
const steering = options.steering ? report.steering ?? [] : [];
|
|
3936
|
+
const unverified = report.unverified ?? [];
|
|
3515
3937
|
const at = (name, qualified) => [
|
|
3516
3938
|
{
|
|
3517
3939
|
physicalLocation: { artifactLocation: { uri: sarifUri(report), uriBaseId: "%SRCROOT%" } },
|
|
@@ -3532,6 +3954,13 @@ function renderSarifReport(report, options = {}) {
|
|
|
3532
3954
|
shortDescription: { text: "Text that began addressing the model" },
|
|
3533
3955
|
fullDescription: { text: "A passage a model is shown started reading as an instruction since this lock was approved. A signal to read, not a verdict: legitimate servers trip the same shape. It does not affect the exit code." },
|
|
3534
3956
|
defaultConfiguration: { level: "note" }
|
|
3957
|
+
}] : [],
|
|
3958
|
+
...unverified.length > 0 ? [{
|
|
3959
|
+
id: UNVERIFIED_RULE,
|
|
3960
|
+
name: "ServerArtifactUnverified",
|
|
3961
|
+
shortDescription: { text: "What a server runs could not be checked" },
|
|
3962
|
+
fullDescription: { text: "The server answered and its declared surface was compared, but the artifact behind it could not be established on this run: a registry that did not answer, or a launcher configured to fetch from somewhere the pin does not describe. It does not affect the exit code." },
|
|
3963
|
+
defaultConfiguration: { level: "note" }
|
|
3535
3964
|
}] : []
|
|
3536
3965
|
];
|
|
3537
3966
|
const document = {
|
|
@@ -3580,7 +4009,14 @@ function renderSarifReport(report, options = {}) {
|
|
|
3580
4009
|
locations: at(signal.field, `${server2}/${signal.field}`),
|
|
3581
4010
|
partialFingerprints: { "mcpAuditChange/v1": `${server2}/${signal.field}/${signal.kind}` }
|
|
3582
4011
|
}))
|
|
3583
|
-
)
|
|
4012
|
+
),
|
|
4013
|
+
...unverified.map((server2) => ({
|
|
4014
|
+
ruleId: UNVERIFIED_RULE,
|
|
4015
|
+
level: "note",
|
|
4016
|
+
message: { text: `${server2}: what this server runs could not be checked on this run` },
|
|
4017
|
+
locations: at(server2, server2),
|
|
4018
|
+
partialFingerprints: { "mcpAuditChange/v1": `${server2}/unverified` }
|
|
4019
|
+
}))
|
|
3584
4020
|
]
|
|
3585
4021
|
}
|
|
3586
4022
|
]
|
|
@@ -3597,10 +4033,10 @@ var AUDIT_FAILURE_LABEL = {
|
|
|
3597
4033
|
};
|
|
3598
4034
|
var MARK2 = { high: "\u{1F534}", medium: "\u{1F7E0}", low: "\u26AA" };
|
|
3599
4035
|
function plain(text) {
|
|
3600
|
-
return visibleControls(text).replace(/\r?\n/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/([\\`*_{}[\]()#+!|~])/g, "\\$1").replace(/@/g, "
|
|
4036
|
+
return visibleControls(text, { multiline: true }).replace(/\r?\n/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/([\\`*_{}[\]()#+!|~])/g, "\\$1").replace(/@/g, "@\u200B").replace(/\bwww\./gi, (prefix) => `${prefix.slice(0, 3)}\u200B.`).replace(/:\/\//g, "://").trim();
|
|
3601
4037
|
}
|
|
3602
4038
|
function code(text) {
|
|
3603
|
-
const body = visibleControls(text).replace(/\r?\n/g, " ").replace(/\|/g, "\\|").trim();
|
|
4039
|
+
const body = visibleControls(text, { multiline: true }).replace(/\r?\n/g, " ").replace(/\|/g, "\\|").trim();
|
|
3604
4040
|
const longest = Math.max(0, ...(body.match(/`+/g) ?? []).map((run) => run.length));
|
|
3605
4041
|
const fence = "`".repeat(longest + 1);
|
|
3606
4042
|
const pad = body.startsWith("`") || body.endsWith("`") ? " " : "";
|
|
@@ -3611,16 +4047,21 @@ function row(change2) {
|
|
|
3611
4047
|
return `| ${MARK2[change2.severity]} ${change2.severity} | ${code(where)} | ${plain(change2.kind)} | ${plain(change2.summary)} |`;
|
|
3612
4048
|
}
|
|
3613
4049
|
function renderMarkdownReport(report, options = {}) {
|
|
3614
|
-
|
|
4050
|
+
const violations = report.violations ?? [];
|
|
4051
|
+
if (report.changes.length === 0 && report.unreachable.length === 0 && violations.length === 0) return null;
|
|
3615
4052
|
const lines = [];
|
|
3616
4053
|
const high = report.changes.filter((change2) => change2.severity === "high").length;
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
4054
|
+
if (report.changes.length === 0 && violations.length > 0) {
|
|
4055
|
+
lines.push(`### ${violations.length} capabilit${violations.length === 1 ? "y" : "ies"} this project does not permit`, "");
|
|
4056
|
+
} else {
|
|
4057
|
+
lines.push(
|
|
4058
|
+
high > 0 ? `### ${report.changes.length} change${report.changes.length === 1 ? "" : "s"} to what your agents can reach, ${high} high` : `### ${report.changes.length} change${report.changes.length === 1 ? "" : "s"} to what your agents can reach`,
|
|
4059
|
+
"",
|
|
4060
|
+
"A server changed what it declares. Same version, same package: the comparison is against the",
|
|
4061
|
+
"surface you approved, not the version string.",
|
|
4062
|
+
""
|
|
4063
|
+
);
|
|
4064
|
+
}
|
|
3624
4065
|
if (report.changes.length > 0) {
|
|
3625
4066
|
lines.push("| | Where | What | Detail |", "| --- | --- | --- | --- |", ...report.changes.map(row), "");
|
|
3626
4067
|
const quiet = serversThatShippedNothing(report.changes);
|
|
@@ -3633,6 +4074,16 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
3633
4074
|
);
|
|
3634
4075
|
}
|
|
3635
4076
|
}
|
|
4077
|
+
if (violations.length > 0) {
|
|
4078
|
+
lines.push(
|
|
4079
|
+
`**${violations.length} capabilit${violations.length === 1 ? "y" : "ies"} this project does not permit.** Set by \`policy.deniedCapabilities\` in the lockfile; accepting the change does not clear it.`,
|
|
4080
|
+
"",
|
|
4081
|
+
"| Where | Capability | Evidence |",
|
|
4082
|
+
"| --- | --- | --- |",
|
|
4083
|
+
...violations.map((violation) => `| ${code(`${violation.server}/${violation.tool}`)} | ${plain(violation.kind)} | ${code(violation.evidence)} |`),
|
|
4084
|
+
""
|
|
4085
|
+
);
|
|
4086
|
+
}
|
|
3636
4087
|
const steering = report.steering ?? [];
|
|
3637
4088
|
if (steering.length > 0) {
|
|
3638
4089
|
const total = steering.reduce((sum, server2) => sum + server2.signals.length, 0);
|
|
@@ -3665,6 +4116,19 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
3665
4116
|
""
|
|
3666
4117
|
);
|
|
3667
4118
|
}
|
|
4119
|
+
const unverified = report.unverified ?? [];
|
|
4120
|
+
if (unverified.length > 0) {
|
|
4121
|
+
lines.push(
|
|
4122
|
+
`<details><summary>${unverified.length} server${unverified.length === 1 ? "" : "s"} whose code could not be checked</summary>`,
|
|
4123
|
+
"",
|
|
4124
|
+
"These answered and their declarations were compared, but what they run could not be established on this run.",
|
|
4125
|
+
"",
|
|
4126
|
+
...unverified.map((server2) => `- ${code(server2)}`),
|
|
4127
|
+
"",
|
|
4128
|
+
"</details>",
|
|
4129
|
+
""
|
|
4130
|
+
);
|
|
4131
|
+
}
|
|
3668
4132
|
lines.push(
|
|
3669
4133
|
options.url ? `Read the full diff and rule on it: ${options.url}` : "Run `nulladrift review` to read the full diff, or `nulladrift review --accept-all` to accept every change."
|
|
3670
4134
|
);
|
|
@@ -3706,12 +4170,29 @@ ${body}`;
|
|
|
3706
4170
|
const existing = await call(target, `/issues/${target.issue}/comments?per_page=100`);
|
|
3707
4171
|
if (existing.status === 403) return "forbidden";
|
|
3708
4172
|
if (!existing.ok) throw new Error(`could not read the comments (${existing.status})`);
|
|
4173
|
+
const self = await identity2(target);
|
|
3709
4174
|
const comments = await existing.json();
|
|
3710
|
-
const mine = comments.find((comment2) => comment2.body?.startsWith(MARKER));
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
4175
|
+
const mine = comments.find((comment2) => comment2.body?.startsWith(MARKER) && comment2.user?.login === self);
|
|
4176
|
+
if (mine) {
|
|
4177
|
+
const updated = await call(target, `/issues/comments/${mine.id}`, { method: "PATCH", body: JSON.stringify({ body: marked }) });
|
|
4178
|
+
if (updated.ok) return "updated";
|
|
4179
|
+
if (updated.status !== 403 && updated.status !== 404) throw new Error(`could not update the comment (${updated.status})`);
|
|
4180
|
+
}
|
|
4181
|
+
const created = await call(target, `/issues/${target.issue}/comments`, { method: "POST", body: JSON.stringify({ body: marked }) });
|
|
4182
|
+
if (created.status === 403) return "forbidden";
|
|
4183
|
+
if (!created.ok) throw new Error(`could not post the comment (${created.status})`);
|
|
4184
|
+
return "created";
|
|
4185
|
+
}
|
|
4186
|
+
async function identity2(target) {
|
|
4187
|
+
const response = await fetch(`${target.api}/user`, {
|
|
4188
|
+
headers: { accept: "application/vnd.github+json", authorization: `Bearer ${target.token}`, "x-github-api-version": "2022-11-28" },
|
|
4189
|
+
signal: AbortSignal.timeout(1e4)
|
|
4190
|
+
}).catch(() => void 0);
|
|
4191
|
+
if (response?.ok) {
|
|
4192
|
+
const body = await response.json().catch(() => ({}));
|
|
4193
|
+
if (typeof body.login === "string" && body.login.length > 0) return body.login;
|
|
4194
|
+
}
|
|
4195
|
+
return "github-actions[bot]";
|
|
3715
4196
|
}
|
|
3716
4197
|
|
|
3717
4198
|
// src/telemetry/index.ts
|
|
@@ -3825,7 +4306,7 @@ async function buildReport(options) {
|
|
|
3825
4306
|
});
|
|
3826
4307
|
for (const note of redactedNotes(result.lock)) process.stderr.write(`${yellow("note:")} ${note}
|
|
3827
4308
|
`);
|
|
3828
|
-
const changes =
|
|
4309
|
+
const changes = compareWithLock(committed, result);
|
|
3829
4310
|
const allowUnreachable = options.allowUnreachable || committed.policy?.allowUnreachable === true;
|
|
3830
4311
|
const report = {
|
|
3831
4312
|
changes,
|
|
@@ -3896,7 +4377,7 @@ async function comment(report) {
|
|
|
3896
4377
|
}
|
|
3897
4378
|
|
|
3898
4379
|
// src/commands/init.ts
|
|
3899
|
-
import { lstat as
|
|
4380
|
+
import { lstat as lstat3 } from "fs/promises";
|
|
3900
4381
|
|
|
3901
4382
|
// src/commands/telemetry.ts
|
|
3902
4383
|
import { createInterface } from "readline/promises";
|
|
@@ -3991,7 +4472,7 @@ ${dim(" No collector is configured in this build, so nothing will be sent until
|
|
|
3991
4472
|
// src/commands/init.ts
|
|
3992
4473
|
async function exists(path) {
|
|
3993
4474
|
try {
|
|
3994
|
-
await
|
|
4475
|
+
await lstat3(path);
|
|
3995
4476
|
return true;
|
|
3996
4477
|
} catch {
|
|
3997
4478
|
return false;
|
|
@@ -4034,7 +4515,8 @@ async function runInit(options) {
|
|
|
4034
4515
|
return EXIT_CLEAN;
|
|
4035
4516
|
}
|
|
4036
4517
|
const pinnedSomething = names.length > 0;
|
|
4037
|
-
|
|
4518
|
+
const unaudited = options.allowUnreachable ? unauditedToRecord(result) : void 0;
|
|
4519
|
+
if (pinnedSomething) await writeLockfile(options.lockPath, unaudited ? { ...result.lock, unaudited } : result.lock);
|
|
4038
4520
|
const lines = pinnedSomething ? ["", bold(`Pinned ${names.length} server(s) to ${options.lockPath}:`), ""] : ["", bold("Pinned nothing: no server answered."), ""];
|
|
4039
4521
|
for (const name of names) {
|
|
4040
4522
|
const entry = result.lock.subjects[name];
|
|
@@ -4078,7 +4560,7 @@ async function runInit(options) {
|
|
|
4078
4560
|
}
|
|
4079
4561
|
}
|
|
4080
4562
|
for (const failure of result.unreachable) {
|
|
4081
|
-
lines.push(` ${red("\u2717")} ${bold(failure.server)} ${dim("not pinned")}`, ` ${failure.reason}`);
|
|
4563
|
+
lines.push(` ${red("\u2717")} ${bold(visibleControls(failure.server))} ${dim("not pinned")}`, ` ${visibleLines(failure.reason, " ")}`);
|
|
4082
4564
|
}
|
|
4083
4565
|
if (result.discovery.userConfigsSkipped.length > 0) {
|
|
4084
4566
|
lines.push(
|
|
@@ -4103,7 +4585,8 @@ async function runInit(options) {
|
|
|
4103
4585
|
// src/commands/login.ts
|
|
4104
4586
|
import { createServer } from "http";
|
|
4105
4587
|
import { auth } from "@modelcontextprotocol/client";
|
|
4106
|
-
import { rm as rm4 } from "fs/promises";
|
|
4588
|
+
import { rm as rm4, stat } from "fs/promises";
|
|
4589
|
+
import { resolve as resolve5 } from "path";
|
|
4107
4590
|
var CALLBACK_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
4108
4591
|
async function awaitCallback(expectedState) {
|
|
4109
4592
|
let settle;
|
|
@@ -4140,8 +4623,8 @@ async function awaitCallback(expectedState) {
|
|
|
4140
4623
|
server2.listen(0, "127.0.0.1", ready);
|
|
4141
4624
|
});
|
|
4142
4625
|
const { port } = server2.address();
|
|
4143
|
-
const received = new Promise((
|
|
4144
|
-
settle =
|
|
4626
|
+
const received = new Promise((resolve7, reject) => {
|
|
4627
|
+
settle = resolve7;
|
|
4145
4628
|
fail = reject;
|
|
4146
4629
|
setTimeout(() => reject(new Error(`no callback within ${CALLBACK_TIMEOUT_MS / 1e3}s`)), CALLBACK_TIMEOUT_MS).unref();
|
|
4147
4630
|
});
|
|
@@ -4153,6 +4636,16 @@ async function awaitCallback(expectedState) {
|
|
|
4153
4636
|
}
|
|
4154
4637
|
async function findServer(projectRoot, configFiles, name) {
|
|
4155
4638
|
const discovery = await discoverServers(projectRoot, configFiles, { userConfigs: true });
|
|
4639
|
+
const conflict = discovery.conflicts.find((candidate) => candidate.name === name);
|
|
4640
|
+
if (conflict) {
|
|
4641
|
+
const named = new Set(configFiles.map((file) => portablePath(resolve5(projectRoot, file), projectRoot)));
|
|
4642
|
+
const chosen = conflict.definitions.filter((definition) => named.has(definition.file));
|
|
4643
|
+
if (chosen.length === 1) return chosen[0].server;
|
|
4644
|
+
const where = conflict.definitions.map((definition) => ` ${definition.file}: ${describeTarget(definition.server)}`).join("\n");
|
|
4645
|
+
return { error: `"${name}" is defined differently in more than one config:
|
|
4646
|
+
${where}
|
|
4647
|
+
Name the one you mean with --config <file>.` };
|
|
4648
|
+
}
|
|
4156
4649
|
const server2 = discovery.servers.find((candidate) => candidate.name === name);
|
|
4157
4650
|
if (!server2) {
|
|
4158
4651
|
const known = discovery.servers.map((candidate) => candidate.name);
|
|
@@ -4161,6 +4654,10 @@ async function findServer(projectRoot, configFiles, name) {
|
|
|
4161
4654
|
if (server2.transport.type === "stdio") return { error: `"${name}" is a stdio server; it is launched locally and has nothing to log in to` };
|
|
4162
4655
|
return server2;
|
|
4163
4656
|
}
|
|
4657
|
+
function describeTarget(server2) {
|
|
4658
|
+
const { transport: transport2 } = server2;
|
|
4659
|
+
return transport2.type === "stdio" ? `runs ${transport2.command}` : sanitizeUrl(transport2.url);
|
|
4660
|
+
}
|
|
4164
4661
|
async function runLogin(options) {
|
|
4165
4662
|
if (options.serverName === void 0) {
|
|
4166
4663
|
process.stderr.write(`${red("which server?")} ${dim("Usage: nulladrift login <server>")}
|
|
@@ -4220,9 +4717,16 @@ async function runLogout(options) {
|
|
|
4220
4717
|
return EXIT_INCOMPLETE;
|
|
4221
4718
|
}
|
|
4222
4719
|
const url = found.transport.type === "stdio" ? "" : found.transport.url;
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4720
|
+
const path = credentialPath(url);
|
|
4721
|
+
const existed = await stat(path).then(
|
|
4722
|
+
() => true,
|
|
4723
|
+
() => false
|
|
4724
|
+
);
|
|
4725
|
+
await rm4(path, { force: true });
|
|
4726
|
+
process.stdout.write(
|
|
4727
|
+
`${dim(existed ? `stored credentials for ${found.name} (${sanitizeUrl(url)}) deleted` : `no credentials were stored for ${found.name} (${sanitizeUrl(url)})`)}
|
|
4728
|
+
`
|
|
4729
|
+
);
|
|
4226
4730
|
return EXIT_CLEAN;
|
|
4227
4731
|
}
|
|
4228
4732
|
|
|
@@ -4285,7 +4789,7 @@ async function acquireBuildToken(options = {}) {
|
|
|
4285
4789
|
const explicit = env["NULLADRIFT_ID_TOKEN"];
|
|
4286
4790
|
if (explicit) return { token: explicit, source: "environment" };
|
|
4287
4791
|
if (env["GITHUB_ACTIONS"] !== "true") return void 0;
|
|
4288
|
-
return fromGithubActions(env["NULLADRIFT_BUILD_AUDIENCE"]
|
|
4792
|
+
return fromGithubActions(env["NULLADRIFT_BUILD_AUDIENCE"] || DEFAULT_AUDIENCE, env, options);
|
|
4289
4793
|
}
|
|
4290
4794
|
async function acquireReadingToken(audience, options = {}) {
|
|
4291
4795
|
const env = options.env ?? process.env;
|
|
@@ -4315,14 +4819,15 @@ async function fromGithubActions(audience, env, options) {
|
|
|
4315
4819
|
}
|
|
4316
4820
|
|
|
4317
4821
|
// src/commands/push.ts
|
|
4318
|
-
function describeIdentity(
|
|
4319
|
-
const
|
|
4320
|
-
const
|
|
4321
|
-
|
|
4322
|
-
if (
|
|
4822
|
+
function describeIdentity(identity3, hint) {
|
|
4823
|
+
const shown = (text) => visibleControls(text);
|
|
4824
|
+
const where = shown(`${identity3?.repository ?? ""}${identity3?.ref ? ` @ ${identity3.ref}` : ""}`);
|
|
4825
|
+
const contents = identity3?.boundToReading ? " \xB7 contents signed" : identity3?.bindingRefused ? ` \xB7 contents not signed: ${shown(identity3.bindingRefused)}` : "";
|
|
4826
|
+
if (identity3?.trust === "trusted") return `${green("signed")} ${dim(`${where} \xB7 a trusted build${contents}`)}`;
|
|
4827
|
+
if (identity3?.trust === "verified") {
|
|
4323
4828
|
return `${yellow("signed")} ${dim(`${where} \xB7 not a build this organization lists as trusted${contents}`)}`;
|
|
4324
4829
|
}
|
|
4325
|
-
if (
|
|
4830
|
+
if (identity3?.rejected) return `${red("build token refused")} ${dim(shown(identity3.rejected))}`;
|
|
4326
4831
|
return hint ? dim(`unsigned: ${hint}`) : void 0;
|
|
4327
4832
|
}
|
|
4328
4833
|
function inferProject(projectRoot) {
|
|
@@ -4348,6 +4853,7 @@ function refuseApiUrl(apiUrl) {
|
|
|
4348
4853
|
if (url.protocol === "https:" || url.protocol === "http:" && loopback) return void 0;
|
|
4349
4854
|
return `the control plane has to be reached over https (http only on this machine), not ${url.protocol}`;
|
|
4350
4855
|
}
|
|
4856
|
+
var UNSENDABLE2 = /[\r\n\0]/;
|
|
4351
4857
|
async function runPush(options) {
|
|
4352
4858
|
const apiUrl = (options.apiUrl ?? process.env["NULLADRIFT_API_URL"] ?? "").replace(/\/+$/, "");
|
|
4353
4859
|
const token = options.token ?? process.env["NULLADRIFT_TOKEN"] ?? "";
|
|
@@ -4369,6 +4875,17 @@ async function runPush(options) {
|
|
|
4369
4875
|
`);
|
|
4370
4876
|
return EXIT_INCOMPLETE;
|
|
4371
4877
|
}
|
|
4878
|
+
if (UNSENDABLE2.test(token)) {
|
|
4879
|
+
process.stderr.write(
|
|
4880
|
+
`${red("push refused:")} the collector token (${options.token !== void 0 ? "--token" : "NULLADRIFT_TOKEN"}) contains a line break or NUL; a secret saved with a trailing newline is the usual cause
|
|
4881
|
+
`
|
|
4882
|
+
);
|
|
4883
|
+
return EXIT_INCOMPLETE;
|
|
4884
|
+
}
|
|
4885
|
+
if (options.token !== void 0) {
|
|
4886
|
+
process.stderr.write(`${yellow("note:")} --token is visible to other processes on this machine; prefer NULLADRIFT_TOKEN.
|
|
4887
|
+
`);
|
|
4888
|
+
}
|
|
4372
4889
|
const result = await captureAll({
|
|
4373
4890
|
projectRoot: options.projectRoot,
|
|
4374
4891
|
configFiles: options.configFiles,
|
|
@@ -4416,8 +4933,14 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4416
4933
|
acquireBuildToken(),
|
|
4417
4934
|
acquireReadingToken(readingAudience(readingAudienceBase(apiUrl), digest2))
|
|
4418
4935
|
]);
|
|
4419
|
-
const
|
|
4420
|
-
|
|
4936
|
+
const sendable = (candidate, what) => {
|
|
4937
|
+
if (candidate === void 0 || !UNSENDABLE2.test(candidate)) return candidate;
|
|
4938
|
+
process.stderr.write(`${yellow("note:")} ${what} contains a line break or NUL, so it was left out; the reading goes unsigned.
|
|
4939
|
+
`);
|
|
4940
|
+
return void 0;
|
|
4941
|
+
};
|
|
4942
|
+
const buildToken = sendable(build && "token" in build ? build.token : void 0, "the identity token (NULLADRIFT_ID_TOKEN)");
|
|
4943
|
+
const readingToken = sendable(reading && "token" in reading ? reading.token : void 0, "the reading token");
|
|
4421
4944
|
let response;
|
|
4422
4945
|
try {
|
|
4423
4946
|
response = await fetch(`${apiUrl}/api/v1/ingest`, {
|
|
@@ -4434,7 +4957,9 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4434
4957
|
signal: AbortSignal.timeout(options.timeoutMs)
|
|
4435
4958
|
});
|
|
4436
4959
|
} catch (error) {
|
|
4437
|
-
|
|
4960
|
+
let message = error.message;
|
|
4961
|
+
for (const secret of [token, buildToken, readingToken]) if (secret) message = message.split(secret).join("[redacted]");
|
|
4962
|
+
process.stderr.write(`${red("could not reach the control plane:")} ${message}
|
|
4438
4963
|
`);
|
|
4439
4964
|
return EXIT_INCOMPLETE;
|
|
4440
4965
|
}
|
|
@@ -4447,16 +4972,17 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4447
4972
|
const verdict = await response.json();
|
|
4448
4973
|
const lines = [""];
|
|
4449
4974
|
const mark = verdict.verdict === "clean" ? green("\u2713") : verdict.verdict === "drift" ? yellow("!") : red("\u2717");
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4975
|
+
const shown = (text) => visibleControls(String(text ?? ""));
|
|
4976
|
+
lines.push(`${mark} ${bold(shown(verdict.verdict))} ${dim(`\xB7 ${servers.length} server(s) \xB7 reading ${shown(verdict.readingId).slice(0, 8)}`)}`);
|
|
4977
|
+
const identity3 = describeIdentity(verdict.identity, build && "hint" in build ? build.hint : void 0);
|
|
4978
|
+
if (identity3) lines.push(` ${identity3}`);
|
|
4453
4979
|
for (const change2 of verdict.changes) {
|
|
4454
|
-
lines.push(` ${change2.severity === "high" ? red("\u25CF") : change2.severity === "medium" ? yellow("\u25CF") : dim("\u25CF")} ${bold(change2.server)}${change2.member ? dim(`/${change2.member}`) : ""} ${change2.summary}`);
|
|
4980
|
+
lines.push(` ${change2.severity === "high" ? red("\u25CF") : change2.severity === "medium" ? yellow("\u25CF") : dim("\u25CF")} ${bold(shown(change2.server))}${change2.member ? dim(`/${shown(change2.member)}`) : ""} ${shown(change2.summary)}`);
|
|
4455
4981
|
}
|
|
4456
4982
|
for (const reason of verdict.decision.reasons) {
|
|
4457
|
-
lines.push(` ${red("blocked")} ${dim(reason.code)} ${reason.message}`);
|
|
4983
|
+
lines.push(` ${red("blocked")} ${dim(shown(reason.code))} ${shown(reason.message)}`);
|
|
4458
4984
|
}
|
|
4459
|
-
if (verdict.verdict !== "clean") lines.push("", dim(`Review it at ${verdict.url}`));
|
|
4985
|
+
if (verdict.verdict !== "clean") lines.push("", dim(`Review it at ${shown(verdict.url)}`));
|
|
4460
4986
|
lines.push("");
|
|
4461
4987
|
process.stdout.write(lines.join("\n"));
|
|
4462
4988
|
return verdict.exitCode === 0 ? EXIT_CLEAN : verdict.exitCode === 1 ? EXIT_DRIFT : EXIT_INCOMPLETE;
|
|
@@ -4513,7 +5039,7 @@ async function runReview(options) {
|
|
|
4513
5039
|
provenance: options.provenance,
|
|
4514
5040
|
userConfigs: options.userConfigs
|
|
4515
5041
|
});
|
|
4516
|
-
const changes =
|
|
5042
|
+
const changes = compareWithLock(committed, result);
|
|
4517
5043
|
if (changes.length === 0) {
|
|
4518
5044
|
process.stdout.write(`${green(`\u2713 nothing to review; ${options.lockPath} is up to date`)}
|
|
4519
5045
|
`);
|
|
@@ -4558,9 +5084,18 @@ ${context.length > 0 ? `${context.join("\n")}
|
|
|
4558
5084
|
continue;
|
|
4559
5085
|
}
|
|
4560
5086
|
accepted += 1;
|
|
4561
|
-
|
|
5087
|
+
let fresh = result.lock.subjects[serverName];
|
|
5088
|
+
const pin = committed.subjects[serverName]?.provenance;
|
|
5089
|
+
const displaced = result.displaced.some((moved) => moved.server === serverName);
|
|
5090
|
+
if (fresh && fresh.provenance === void 0 && pin !== void 0 && result.unverified.includes(serverName) && !displaced) {
|
|
5091
|
+
fresh = { ...fresh, provenance: pin };
|
|
5092
|
+
}
|
|
4562
5093
|
if (fresh) next.subjects[serverName] = fresh;
|
|
4563
5094
|
else delete next.subjects[serverName];
|
|
5095
|
+
const unaudited = { ...next.unaudited };
|
|
5096
|
+
if (!fresh && result.unaudited[serverName] !== void 0) unaudited[serverName] = result.unaudited[serverName];
|
|
5097
|
+
else delete unaudited[serverName];
|
|
5098
|
+
next.unaudited = Object.keys(unaudited).length > 0 ? unaudited : void 0;
|
|
4564
5099
|
for (const change2 of serverChanges) {
|
|
4565
5100
|
if (change2.kind === "server.renamed" && typeof change2.before === "string") delete next.subjects[change2.before];
|
|
4566
5101
|
}
|
|
@@ -4667,10 +5202,10 @@ async function main() {
|
|
|
4667
5202
|
`);
|
|
4668
5203
|
return EXIT_INCOMPLETE;
|
|
4669
5204
|
}
|
|
4670
|
-
const projectRoot =
|
|
5205
|
+
const projectRoot = resolve6(values.cwd ?? process.cwd());
|
|
4671
5206
|
const options = {
|
|
4672
5207
|
projectRoot,
|
|
4673
|
-
lockPath:
|
|
5208
|
+
lockPath: resolve6(projectRoot, values.lock ?? DEFAULT_LOCK_FILENAME),
|
|
4674
5209
|
configFiles: values.config ?? [],
|
|
4675
5210
|
timeoutMs,
|
|
4676
5211
|
allowUnreachable: values["allow-unreachable"],
|