nulladrift 0.7.0 → 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 +665 -128
- 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
|
}
|
|
@@ -758,8 +804,9 @@ function collectFacts(schema) {
|
|
|
758
804
|
const properties = asObject(object["properties"]);
|
|
759
805
|
if (properties) {
|
|
760
806
|
const requiredList = Array.isArray(object["required"]) ? object["required"].filter((entry) => typeof entry === "string") : [];
|
|
807
|
+
const requiredSet = new Set(requiredList);
|
|
761
808
|
for (const [name, child] of Object.entries(properties)) {
|
|
762
|
-
visit(child, path === "" ? name : `${path}.${name}`,
|
|
809
|
+
visit(child, path === "" ? name : `${path}.${name}`, requiredSet.has(name), depth + 1);
|
|
763
810
|
}
|
|
764
811
|
}
|
|
765
812
|
const items = object["items"];
|
|
@@ -772,7 +819,8 @@ function collectFacts(schema) {
|
|
|
772
819
|
return facts;
|
|
773
820
|
}
|
|
774
821
|
function isSuperset(next, previous) {
|
|
775
|
-
|
|
822
|
+
const members = new Set(next);
|
|
823
|
+
return previous.every((entry) => members.has(entry));
|
|
776
824
|
}
|
|
777
825
|
function classifySchemaChange(before, after) {
|
|
778
826
|
if (stableKey(before) === stableKey(after)) return "same";
|
|
@@ -847,8 +895,15 @@ function change(kind, server2, summary, extra) {
|
|
|
847
895
|
function same(a, b) {
|
|
848
896
|
return stableKey(a ?? null) === stableKey(b ?? null);
|
|
849
897
|
}
|
|
850
|
-
function
|
|
851
|
-
|
|
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;
|
|
852
907
|
}
|
|
853
908
|
function declaredNames(capabilities) {
|
|
854
909
|
const names = [];
|
|
@@ -882,12 +937,12 @@ var CAPABILITY_SEVERITY = {
|
|
|
882
937
|
low: "low"
|
|
883
938
|
};
|
|
884
939
|
function compareToolCapabilities(server2, before, after) {
|
|
885
|
-
const previous =
|
|
940
|
+
const previous = groupBy(before, (tool2) => tool2.name);
|
|
886
941
|
const changes = [];
|
|
887
942
|
for (const tool2 of after ?? []) {
|
|
888
943
|
const existing = previous.get(tool2.name);
|
|
889
944
|
if (!existing) continue;
|
|
890
|
-
const had = new Set(toolCapabilities(
|
|
945
|
+
const had = new Set(existing.flatMap((copy) => toolCapabilities(copy).map((capability) => capability.kind)));
|
|
891
946
|
for (const capability of toolCapabilities(tool2)) {
|
|
892
947
|
if (had.has(capability.kind)) continue;
|
|
893
948
|
changes.push(
|
|
@@ -939,10 +994,20 @@ function compareTool(name, before, after) {
|
|
|
939
994
|
);
|
|
940
995
|
}
|
|
941
996
|
if (changes.length === 0) {
|
|
942
|
-
|
|
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 }));
|
|
943
1004
|
}
|
|
944
1005
|
return changes;
|
|
945
1006
|
}
|
|
1007
|
+
function describeExecution(execution) {
|
|
1008
|
+
const support = execution?.["taskSupport"];
|
|
1009
|
+
return typeof support === "string" ? `task support ${support}` : "unstated";
|
|
1010
|
+
}
|
|
946
1011
|
function describeEscalation(before, after) {
|
|
947
1012
|
const gained = [];
|
|
948
1013
|
if (before.behavior.readOnly && !after.behavior.readOnly) gained.push("may now modify");
|
|
@@ -953,25 +1018,61 @@ function describeEscalation(before, after) {
|
|
|
953
1018
|
}
|
|
954
1019
|
function compareMembers(name, before, after, spec, deep) {
|
|
955
1020
|
const changes = [];
|
|
956
|
-
const previous =
|
|
957
|
-
const next =
|
|
958
|
-
for (const [key,
|
|
1021
|
+
const previous = groupBy(before, spec.key);
|
|
1022
|
+
const next = groupBy(after, spec.key);
|
|
1023
|
+
for (const [key, members] of next) {
|
|
959
1024
|
const existing = previous.get(key);
|
|
960
1025
|
if (!existing) {
|
|
961
|
-
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
|
+
}
|
|
962
1049
|
changes.push(
|
|
963
|
-
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 })]
|
|
964
1051
|
);
|
|
965
|
-
continue;
|
|
966
1052
|
}
|
|
967
|
-
|
|
968
|
-
|
|
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
|
+
}
|
|
969
1056
|
}
|
|
970
|
-
for (const [key,
|
|
971
|
-
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 }));
|
|
972
1060
|
}
|
|
973
1061
|
return changes;
|
|
974
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
|
+
}
|
|
975
1076
|
function compareProvenance(name, before, after) {
|
|
976
1077
|
const was = before.provenance;
|
|
977
1078
|
const now = after.provenance;
|
|
@@ -981,7 +1082,16 @@ function compareProvenance(name, before, after) {
|
|
|
981
1082
|
const unexplained = surfaceHeld ? ", and the declared surface did not change: nothing else in this report describes what the new code does" : "";
|
|
982
1083
|
const integrityMoved = was.integrity !== void 0 && now.integrity !== void 0 && was.integrity !== now.integrity;
|
|
983
1084
|
if (was.version !== void 0 && was.version === now.version) {
|
|
984
|
-
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
|
+
}
|
|
985
1095
|
if (was.ecosystem === "npm") {
|
|
986
1096
|
return [
|
|
987
1097
|
change(
|
|
@@ -1002,6 +1112,17 @@ function compareProvenance(name, before, after) {
|
|
|
1002
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";
|
|
1003
1113
|
return [change("server.artifact.changed", name, `${what}${unexplained}`, { before: was, after: now })];
|
|
1004
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
|
+
}
|
|
1005
1126
|
function compareServer(name, before, after) {
|
|
1006
1127
|
const provenance2 = compareProvenance(name, before, after);
|
|
1007
1128
|
if (before.digest === after.digest) return provenance2;
|
|
@@ -1084,6 +1205,14 @@ function compareServer(name, before, after) {
|
|
|
1084
1205
|
noun: "prompt"
|
|
1085
1206
|
})
|
|
1086
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
|
+
}
|
|
1087
1216
|
return changes;
|
|
1088
1217
|
}
|
|
1089
1218
|
function detectRenames(before, after, removed, added) {
|
|
@@ -1132,6 +1261,9 @@ function diffLockfiles(before, after) {
|
|
|
1132
1261
|
}
|
|
1133
1262
|
|
|
1134
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");
|
|
1135
1267
|
var PATTERNS = [
|
|
1136
1268
|
// Imperatives aimed at the reader of the prompt, not at a person reading documentation.
|
|
1137
1269
|
{ kind: "model-directive", pattern: /\b(ignore|disregard|override)\s+(all\s+)?(previous|prior|earlier|above)\b[^.]{0,80}/gi },
|
|
@@ -1150,7 +1282,7 @@ var PATTERNS = [
|
|
|
1150
1282
|
// Paths that only appear in a description when something wants their contents.
|
|
1151
1283
|
{ kind: "credential-path", pattern: /(~|\$HOME|\/home\/[\w.-]+|\/Users\/[\w.-]+)?[/\\]?\.(aws\/credentials|ssh\/id_[\w]+|npmrc|netrc|git-credentials|kube\/config|env)\b/gi },
|
|
1152
1284
|
{ kind: "credential-path", pattern: /\b(id_rsa|id_ed25519|authorized_keys|\.pem|service-account\.json)\b/gi },
|
|
1153
|
-
{ 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 },
|
|
1154
1286
|
{ kind: "exfiltration", pattern: /\b(include|append|attach)\s+(its|the|their)\s+contents?\b[^.]{0,60}/gi },
|
|
1155
1287
|
/*
|
|
1156
1288
|
* The MCP-native form of a credential path. A server's own resource URIs are the secrets it
|
|
@@ -1158,16 +1290,16 @@ var PATTERNS = [
|
|
|
1158
1290
|
* `~/.aws/credentials`. Only when something is being told to go and read it: a description that
|
|
1159
1291
|
* merely names its own resource is documentation.
|
|
1160
1292
|
*/
|
|
1161
|
-
{ 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 },
|
|
1162
1294
|
// Characters that make text render as something other than what it is.
|
|
1163
|
-
{ kind: "hidden-text", pattern:
|
|
1295
|
+
{ kind: "hidden-text", pattern: INVISIBLE_RUN },
|
|
1164
1296
|
/*
|
|
1165
1297
|
* Markup inside a tool description, which is the convention every published tool-poisoning
|
|
1166
1298
|
* sample follows: a pseudo-tag or an HTML comment is invisible wherever the description is
|
|
1167
1299
|
* rendered and plain text to the model that is given it. A description is documentation for a
|
|
1168
1300
|
* person; a section of it addressed to a reader who is not that person is the whole technique.
|
|
1169
1301
|
*/
|
|
1170
|
-
{ 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 },
|
|
1171
1303
|
{ kind: "hidden-text", pattern: /<!--[\s\S]{0,200}?-->/g }
|
|
1172
1304
|
];
|
|
1173
1305
|
var CONFUSABLES2 = {
|
|
@@ -1198,7 +1330,7 @@ function steeringSignals(text, field) {
|
|
|
1198
1330
|
const at = match.index ?? 0;
|
|
1199
1331
|
const raw = text.slice(at, at + match[0].length).trim();
|
|
1200
1332
|
if (raw.length === 0) continue;
|
|
1201
|
-
const quote =
|
|
1333
|
+
const quote = ONLY_INVISIBLE.test(raw) ? `${[...raw].length} invisible character(s)` : raw.length > 120 ? `${[...raw].slice(0, 119).join("")}\u2026` : raw;
|
|
1202
1334
|
const key = `${kind}\0${quote}`;
|
|
1203
1335
|
if (seen.has(key)) continue;
|
|
1204
1336
|
seen.add(key);
|
|
@@ -1310,18 +1442,22 @@ var red = wrap(31);
|
|
|
1310
1442
|
var green = wrap(32);
|
|
1311
1443
|
var yellow = wrap(33);
|
|
1312
1444
|
var blue = wrap(34);
|
|
1313
|
-
function visibleControls(text) {
|
|
1314
|
-
return text.replace(
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
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}`);
|
|
1321
1456
|
}
|
|
1322
1457
|
function truncate(text, limit = 160) {
|
|
1323
|
-
const collapsed = visibleControls(text).replace(/\s+/g, " ").trim();
|
|
1324
|
-
|
|
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`;
|
|
1325
1461
|
}
|
|
1326
1462
|
function elideMiddle(raw, limit) {
|
|
1327
1463
|
const path = visibleControls(raw);
|
|
@@ -1665,6 +1801,7 @@ async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
|
1665
1801
|
const skipped = [];
|
|
1666
1802
|
const filesRead = [];
|
|
1667
1803
|
const shadowed = [];
|
|
1804
|
+
const conflicting = /* @__PURE__ */ new Map();
|
|
1668
1805
|
const problems = [];
|
|
1669
1806
|
const requested = new Set(files.filter((file) => file.client === "generic").map((file) => file.path));
|
|
1670
1807
|
for (const file of files) {
|
|
@@ -1693,9 +1830,19 @@ async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
|
1693
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);
|
|
1694
1831
|
skipped.push(...parsed.skipped);
|
|
1695
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
|
+
}
|
|
1696
1838
|
const existing = byName2.get(server2.name);
|
|
1697
1839
|
if (existing) {
|
|
1698
|
-
|
|
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 }]);
|
|
1699
1846
|
continue;
|
|
1700
1847
|
}
|
|
1701
1848
|
byName2.set(server2.name, { server: server2, from: source.file });
|
|
@@ -1710,9 +1857,20 @@ async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
|
1710
1857
|
(path) => path !== void 0
|
|
1711
1858
|
),
|
|
1712
1859
|
shadowed,
|
|
1860
|
+
conflicts: [...conflicting].map(([name, definitions]) => ({ name, definitions })).sort((a, b) => a.name.localeCompare(b.name)),
|
|
1713
1861
|
problems
|
|
1714
1862
|
};
|
|
1715
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
|
+
}
|
|
1716
1874
|
|
|
1717
1875
|
// src/lock/build.ts
|
|
1718
1876
|
function byName(members) {
|
|
@@ -1764,6 +1922,7 @@ function lockTool(tool2, ignoredMeta) {
|
|
|
1764
1922
|
behavior: resolveBehavior(annotations2),
|
|
1765
1923
|
headerParams: headerParams.length > 0 ? headerParams : void 0,
|
|
1766
1924
|
icons: lockIcons(tool2.icons),
|
|
1925
|
+
execution: tool2.execution ? toJson(tool2.execution) : void 0,
|
|
1767
1926
|
meta: stripIgnoredMeta(toJson(tool2._meta), ignoredMeta)
|
|
1768
1927
|
});
|
|
1769
1928
|
}
|
|
@@ -1846,7 +2005,7 @@ import { readFile as readFile3 } from "fs/promises";
|
|
|
1846
2005
|
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
1847
2006
|
|
|
1848
2007
|
// src/lib/version.ts
|
|
1849
|
-
var VERSION = "0.
|
|
2008
|
+
var VERSION = "0.8.0";
|
|
1850
2009
|
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
1851
2010
|
|
|
1852
2011
|
// src/lock/provenance.ts
|
|
@@ -2038,7 +2197,7 @@ function firstPositional(args, valueFlags, explicitFlags, shortValues) {
|
|
|
2038
2197
|
let explicit;
|
|
2039
2198
|
for (let index = 0; index < args.length; index += 1) {
|
|
2040
2199
|
const arg = args[index];
|
|
2041
|
-
if (arg === "--") return { positional: args[index + 1], explicit };
|
|
2200
|
+
if (arg === "--") return { positional: args[index + 1], explicit, index: index + 1 };
|
|
2042
2201
|
const equals = arg.indexOf("=");
|
|
2043
2202
|
if (arg.startsWith("--") && equals > 0) {
|
|
2044
2203
|
if (explicitFlags.includes(arg.slice(0, equals))) explicit = arg.slice(equals + 1);
|
|
@@ -2054,7 +2213,7 @@ function firstPositional(args, valueFlags, explicitFlags, shortValues) {
|
|
|
2054
2213
|
else if (shortValues && !arg.startsWith("--") && arg.length > 2 && shortValues.has(arg.at(-1))) index += 1;
|
|
2055
2214
|
continue;
|
|
2056
2215
|
}
|
|
2057
|
-
return { positional: arg, explicit };
|
|
2216
|
+
return { positional: arg, explicit, index };
|
|
2058
2217
|
}
|
|
2059
2218
|
return { explicit };
|
|
2060
2219
|
}
|
|
@@ -2164,14 +2323,30 @@ async function resolvePypi(reference, options) {
|
|
|
2164
2323
|
const files = (body.urls ?? []).filter((file) => typeof file.filename === "string");
|
|
2165
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];
|
|
2166
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
|
+
);
|
|
2167
2329
|
return {
|
|
2168
2330
|
ecosystem: "pypi",
|
|
2169
2331
|
name: reference.name,
|
|
2170
2332
|
version: body.info.version,
|
|
2171
2333
|
...typeof sha === "string" && /^[a-f0-9]{64}$/.test(sha) ? { integrity: `sha256:${sha}` } : {},
|
|
2172
|
-
...requestedOf(reference)
|
|
2334
|
+
...requestedOf(reference),
|
|
2335
|
+
...Object.keys(published).length > 0 ? { files: published } : {}
|
|
2173
2336
|
};
|
|
2174
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
|
+
}
|
|
2175
2350
|
function imageLocation(name) {
|
|
2176
2351
|
const parts = name.split("/");
|
|
2177
2352
|
const first = parts[0];
|
|
@@ -2270,8 +2445,8 @@ function canonicalRegistry(url) {
|
|
|
2270
2445
|
}
|
|
2271
2446
|
function readSmall(path) {
|
|
2272
2447
|
try {
|
|
2273
|
-
const
|
|
2274
|
-
if (!
|
|
2448
|
+
const stat2 = statSync(path);
|
|
2449
|
+
if (!stat2.isFile() || stat2.size > 1e6) return void 0;
|
|
2275
2450
|
return readFileSync(path, "utf8");
|
|
2276
2451
|
} catch {
|
|
2277
2452
|
return void 0;
|
|
@@ -2444,9 +2619,9 @@ import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotoc
|
|
|
2444
2619
|
|
|
2445
2620
|
// src/mcp/oauth.ts
|
|
2446
2621
|
import { spawn } from "child_process";
|
|
2447
|
-
import { createHash as createHash3, randomUUID } from "crypto";
|
|
2622
|
+
import { createHash as createHash3, randomBytes, randomUUID } from "crypto";
|
|
2448
2623
|
import { readFileSync as readFileSync2 } from "fs";
|
|
2449
|
-
import { mkdir, readFile as readFile4, rm, writeFile } from "fs/promises";
|
|
2624
|
+
import { chmod, lstat, mkdir, readFile as readFile4, rename, rm, writeFile } from "fs/promises";
|
|
2450
2625
|
import { homedir as homedir4, platform as platform2 } from "os";
|
|
2451
2626
|
import { dirname as dirname2, join as join3 } from "path";
|
|
2452
2627
|
import { ClientCredentialsProvider, UnauthorizedError } from "@modelcontextprotocol/client";
|
|
@@ -2466,6 +2641,23 @@ var InteractiveAuthRequiredError = class extends Error {
|
|
|
2466
2641
|
}
|
|
2467
2642
|
serverName;
|
|
2468
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
|
+
}
|
|
2469
2661
|
var FileTokenProvider = class {
|
|
2470
2662
|
constructor(serverName, serverUrl, options = { interactive: false }) {
|
|
2471
2663
|
this.serverName = serverName;
|
|
@@ -2508,10 +2700,8 @@ var FileTokenProvider = class {
|
|
|
2508
2700
|
async write(patch) {
|
|
2509
2701
|
const next = { ...await this.read(), ...patch, serverUrl: this.serverUrl };
|
|
2510
2702
|
this.cache = next;
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
await writeFile(path, `${JSON.stringify(next, null, 2)}
|
|
2514
|
-
`, { encoding: "utf8", mode: 384 });
|
|
2703
|
+
await writeOwnerOnly(credentialPath(this.serverUrl), `${JSON.stringify(next, null, 2)}
|
|
2704
|
+
`);
|
|
2515
2705
|
}
|
|
2516
2706
|
async clientInformation() {
|
|
2517
2707
|
return (await this.read()).clientInformation;
|
|
@@ -2652,13 +2842,140 @@ function isAuthFailure(error) {
|
|
|
2652
2842
|
}
|
|
2653
2843
|
const outer = `${error instanceof Error ? error.message : String(error)}`;
|
|
2654
2844
|
const inner = error instanceof UnreachableServerError && error.cause instanceof Error ? error.cause.message : "";
|
|
2655
|
-
const text = `${outer} ${inner}`.toLowerCase();
|
|
2656
|
-
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);
|
|
2657
2847
|
}
|
|
2658
2848
|
|
|
2659
2849
|
// src/mcp/connect.ts
|
|
2660
2850
|
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
2661
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
|
+
}
|
|
2662
2979
|
function buildTransport(server2, captureStderr = () => {
|
|
2663
2980
|
}, options = {}) {
|
|
2664
2981
|
const { transport: transport2 } = server2;
|
|
@@ -2679,8 +2996,9 @@ function buildTransport(server2, captureStderr = () => {
|
|
|
2679
2996
|
const headers = { "user-agent": USER_AGENT, ...transport2.headers };
|
|
2680
2997
|
const url = new URL(transport2.url);
|
|
2681
2998
|
const authProvider = createAuthProvider(server2, options);
|
|
2682
|
-
|
|
2683
|
-
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 });
|
|
2684
3002
|
}
|
|
2685
3003
|
function diagnosticLines(stderr, limit = 3) {
|
|
2686
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));
|
|
@@ -2704,17 +3022,24 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
2704
3022
|
versionNegotiation: { mode: "auto", probe: { timeoutMs } }
|
|
2705
3023
|
}
|
|
2706
3024
|
);
|
|
3025
|
+
refuseUnsendable(server2);
|
|
2707
3026
|
let transport2;
|
|
3027
|
+
const guard = new SurfaceGuard(() => {
|
|
3028
|
+
void transport2?.close().catch(() => {
|
|
3029
|
+
});
|
|
3030
|
+
});
|
|
2708
3031
|
try {
|
|
2709
|
-
transport2 = buildTransport(server2, captureStderr, options);
|
|
3032
|
+
transport2 = buildTransport(server2, captureStderr, { ...options, fetch: guardedFetch(guard) });
|
|
2710
3033
|
} catch (error) {
|
|
2711
3034
|
throw new UnreachableServerError(server2.name, `could not prepare transport: ${error.message}`, error);
|
|
2712
3035
|
}
|
|
3036
|
+
guardMessages(transport2, guard);
|
|
2713
3037
|
try {
|
|
2714
3038
|
await client.connect(transport2, { timeout: timeoutMs });
|
|
2715
3039
|
} catch (error) {
|
|
2716
3040
|
await client.close().catch(() => {
|
|
2717
3041
|
});
|
|
3042
|
+
if (guard.refusal !== void 0) throw new UnreachableServerError(server2.name, guard.refusal, error);
|
|
2718
3043
|
const detail = stderrBuffer.trim();
|
|
2719
3044
|
throw new UnreachableServerError(
|
|
2720
3045
|
server2.name,
|
|
@@ -2726,6 +3051,7 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
2726
3051
|
return {
|
|
2727
3052
|
client,
|
|
2728
3053
|
stderr: () => stderrBuffer,
|
|
3054
|
+
refused: () => guard.refusal,
|
|
2729
3055
|
close: async () => {
|
|
2730
3056
|
await client.close().catch(() => {
|
|
2731
3057
|
});
|
|
@@ -2776,7 +3102,7 @@ async function listAllTools(client, timeoutMs) {
|
|
|
2776
3102
|
let cursor;
|
|
2777
3103
|
for (let page = 0; page < MAX_LIST_PAGES; page += 1) {
|
|
2778
3104
|
const result = await client.request({ method: "tools/list", params: cursor === void 0 ? {} : { cursor } }, { timeout: timeoutMs });
|
|
2779
|
-
|
|
3105
|
+
for (const tool2 of result.tools) tools.push(tool2);
|
|
2780
3106
|
cursor = result.nextCursor;
|
|
2781
3107
|
if (cursor === void 0) return tools;
|
|
2782
3108
|
if (cursors.has(cursor)) throw new Error("tools/list: the server repeated a page cursor, so the listing would never end");
|
|
@@ -2809,7 +3135,8 @@ function readServerInfo(client) {
|
|
|
2809
3135
|
title: info.title,
|
|
2810
3136
|
version: info.version,
|
|
2811
3137
|
description: info.description,
|
|
2812
|
-
websiteUrl: info.websiteUrl
|
|
3138
|
+
websiteUrl: info.websiteUrl,
|
|
3139
|
+
icons: lockIcons(info.icons)
|
|
2813
3140
|
};
|
|
2814
3141
|
}
|
|
2815
3142
|
async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
@@ -2834,6 +3161,10 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
|
2834
3161
|
connection = opened;
|
|
2835
3162
|
try {
|
|
2836
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;
|
|
2837
3168
|
} finally {
|
|
2838
3169
|
await opened.close();
|
|
2839
3170
|
}
|
|
@@ -2873,8 +3204,9 @@ async function provenanceOf(server2, options) {
|
|
|
2873
3204
|
if (server2.transport.type !== "stdio") return { unverified: false };
|
|
2874
3205
|
const reference = referenceOf(server2.transport, options.projectRoot);
|
|
2875
3206
|
if (!reference) return { unverified: false };
|
|
2876
|
-
if (fetchedElsewhere(server2.transport, reference, { projectRoot: options.projectRoot })) return { unverified: true };
|
|
2877
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 } } : {} };
|
|
2878
3210
|
if (options.provenance === false) {
|
|
2879
3211
|
const kept2 = carriedForward(previous, reference);
|
|
2880
3212
|
return { ...kept2 ? { provenance: kept2 } : {}, unverified: true };
|
|
@@ -2902,14 +3234,15 @@ async function captureAll(options) {
|
|
|
2902
3234
|
const discovery = await discoverServers(options.projectRoot, options.configFiles, { userConfigs: options.userConfigs === true });
|
|
2903
3235
|
const captured = await mapWithLimit(discovery.servers, options.concurrency ?? 4, async (server2) => {
|
|
2904
3236
|
try {
|
|
2905
|
-
const { provenance: provenance2, unverified: unverified2 } = await provenanceOf(server2, options);
|
|
2906
|
-
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);
|
|
2907
3240
|
const entry = buildLockedServer(server2, surface, options.policy);
|
|
2908
3241
|
options.onServerDone?.(server2.name, "captured");
|
|
2909
|
-
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 };
|
|
2910
3243
|
} catch (error) {
|
|
2911
3244
|
options.onServerDone?.(server2.name, "failed");
|
|
2912
|
-
const reason = error instanceof UnreachableServerError ? error.message : error.message;
|
|
3245
|
+
const reason = withoutSecrets(error instanceof UnreachableServerError ? error.message : error.message, server2);
|
|
2913
3246
|
const kind = authFailureKind(error) ?? "unreachable";
|
|
2914
3247
|
return { name: server2.name, failure: { server: server2.name, reason, kind } };
|
|
2915
3248
|
}
|
|
@@ -2917,14 +3250,30 @@ async function captureAll(options) {
|
|
|
2917
3250
|
const subjects = {};
|
|
2918
3251
|
const unreachable = [];
|
|
2919
3252
|
const unverified = [];
|
|
3253
|
+
const displaced = [];
|
|
3254
|
+
const unaudited = {};
|
|
3255
|
+
const configured = new Map(discovery.servers.map((server2) => [server2.name, server2]));
|
|
2920
3256
|
for (const result of captured) {
|
|
2921
3257
|
if ("entry" in result && result.entry) {
|
|
2922
3258
|
subjects[result.name] = result.entry;
|
|
2923
3259
|
if (result.unverified) unverified.push(result.name);
|
|
2924
|
-
|
|
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
|
+
}
|
|
2925
3266
|
}
|
|
2926
3267
|
for (const skipped of discovery.skipped) {
|
|
2927
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
|
+
});
|
|
2928
3277
|
}
|
|
2929
3278
|
for (const problem of discovery.problems) {
|
|
2930
3279
|
unreachable.push({ server: problem.file, reason: problem.reason, kind: "unreachable" });
|
|
@@ -2938,13 +3287,74 @@ async function captureAll(options) {
|
|
|
2938
3287
|
},
|
|
2939
3288
|
unreachable,
|
|
2940
3289
|
discovery,
|
|
2941
|
-
unverified: unverified.sort()
|
|
3290
|
+
unverified: unverified.sort(),
|
|
3291
|
+
displaced,
|
|
3292
|
+
unaudited,
|
|
3293
|
+
conflicted: discovery.conflicts.map((conflict) => conflict.name)
|
|
2942
3294
|
};
|
|
2943
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
|
+
}
|
|
2944
3354
|
|
|
2945
3355
|
// src/lock/io.ts
|
|
2946
3356
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
2947
|
-
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";
|
|
2948
3358
|
|
|
2949
3359
|
// src/lock/schema.ts
|
|
2950
3360
|
import { z as z2 } from "zod";
|
|
@@ -2992,6 +3402,7 @@ var tool = z2.object({
|
|
|
2992
3402
|
behavior,
|
|
2993
3403
|
headerParams: z2.array(z2.string()).optional(),
|
|
2994
3404
|
icons: z2.array(icon).optional(),
|
|
3405
|
+
execution: jsonObject.optional(),
|
|
2995
3406
|
meta: jsonObject.optional(),
|
|
2996
3407
|
digest: digestString
|
|
2997
3408
|
});
|
|
@@ -3042,7 +3453,8 @@ var provenance = z2.object({
|
|
|
3042
3453
|
name: z2.string(),
|
|
3043
3454
|
version: z2.string().optional(),
|
|
3044
3455
|
integrity: z2.string().optional(),
|
|
3045
|
-
requested: z2.string().optional()
|
|
3456
|
+
requested: z2.string().optional(),
|
|
3457
|
+
files: z2.record(z2.string(), z2.string()).optional()
|
|
3046
3458
|
});
|
|
3047
3459
|
var server = z2.object({
|
|
3048
3460
|
kind: z2.literal("mcp-server"),
|
|
@@ -3063,7 +3475,8 @@ var server = z2.object({
|
|
|
3063
3475
|
title: z2.string().optional(),
|
|
3064
3476
|
version: z2.string().optional(),
|
|
3065
3477
|
description: z2.string().optional(),
|
|
3066
|
-
websiteUrl: z2.string().optional()
|
|
3478
|
+
websiteUrl: z2.string().optional(),
|
|
3479
|
+
icons: z2.array(icon).optional()
|
|
3067
3480
|
}).optional(),
|
|
3068
3481
|
capabilities: jsonObject.optional(),
|
|
3069
3482
|
instructions: z2.string().optional(),
|
|
@@ -3095,20 +3508,22 @@ var lockfileSchema = z2.object({
|
|
|
3095
3508
|
* union of one looks odd now and is the point: a second kind is a new member here, and every
|
|
3096
3509
|
* switch over the result stops compiling until it handles it.
|
|
3097
3510
|
*/
|
|
3098
|
-
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()
|
|
3099
3514
|
});
|
|
3100
3515
|
|
|
3101
3516
|
// src/lock/io.ts
|
|
3102
3517
|
var DEFAULT_LOCK_FILENAME = "mcp.lock";
|
|
3103
3518
|
var KEY_ORDER = {
|
|
3104
|
-
root: ["lockfileVersion", "generatedBy", "policy", "subjects"],
|
|
3519
|
+
root: ["lockfileVersion", "generatedBy", "policy", "subjects", "unaudited"],
|
|
3105
3520
|
policy: ["ignoreMetaPrefixes", "allowUnreachable", "deniedCapabilities"],
|
|
3106
3521
|
server: ["kind", "source", "transport", "protocol", "serverInfo", "capabilities", "instructions", "tools", "resources", "resourceTemplates", "prompts", "digest"],
|
|
3107
3522
|
source: ["client", "file", "scope"],
|
|
3108
3523
|
transport: ["type", "command", "args", "envKeys", "cwd", "url", "headerKeys"],
|
|
3109
3524
|
protocol: ["era", "version", "supportedVersions"],
|
|
3110
|
-
serverInfo: ["name", "title", "version", "description", "websiteUrl"],
|
|
3111
|
-
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"],
|
|
3112
3527
|
resource: ["uri", "name", "title", "description", "mimeType", "annotations", "icons", "meta", "digest"],
|
|
3113
3528
|
resourceTemplate: ["uriTemplate", "name", "title", "description", "mimeType", "annotations", "icons", "meta", "digest"],
|
|
3114
3529
|
prompt: ["name", "title", "description", "arguments", "icons", "meta", "digest"],
|
|
@@ -3171,7 +3586,10 @@ function serializeLockfile(lock) {
|
|
|
3171
3586
|
// Names sorted so that adding one produces a localized diff.
|
|
3172
3587
|
subjects: Object.fromEntries(
|
|
3173
3588
|
Object.keys(lock.subjects).sort().map((name) => [name, lock.subjects[name]])
|
|
3174
|
-
)
|
|
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
|
|
3175
3593
|
};
|
|
3176
3594
|
const pad = INDENT;
|
|
3177
3595
|
const parts = [];
|
|
@@ -3242,7 +3660,7 @@ async function readLockfile(path) {
|
|
|
3242
3660
|
}
|
|
3243
3661
|
async function writeLockfile(path, lock) {
|
|
3244
3662
|
try {
|
|
3245
|
-
const link = await
|
|
3663
|
+
const link = await lstat2(path).catch(() => void 0);
|
|
3246
3664
|
if (link?.isSymbolicLink()) {
|
|
3247
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.`);
|
|
3248
3666
|
}
|
|
@@ -3253,7 +3671,7 @@ async function writeLockfile(path, lock) {
|
|
|
3253
3671
|
const temporary = `${path}.${randomUUID2()}.tmp`;
|
|
3254
3672
|
await writeFile2(temporary, serializeLockfile(lock), { encoding: "utf8", flag: "wx" });
|
|
3255
3673
|
try {
|
|
3256
|
-
await
|
|
3674
|
+
await rename2(temporary, path);
|
|
3257
3675
|
} catch (error) {
|
|
3258
3676
|
await rm2(temporary, { force: true }).catch(() => {
|
|
3259
3677
|
});
|
|
@@ -3326,7 +3744,8 @@ function renderViolations(report) {
|
|
|
3326
3744
|
for (const violation of found) {
|
|
3327
3745
|
lines.push(
|
|
3328
3746
|
` ${red("denied")} ${bold(visibleControls(`${violation.server} \u203A ${violation.tool}`))} ${dim(violation.kind)}`,
|
|
3329
|
-
|
|
3747
|
+
// The evidence is an argument name, which the server chose.
|
|
3748
|
+
` ${violation.severity} \xB7 ${visibleControls(violation.evidence)}`
|
|
3330
3749
|
);
|
|
3331
3750
|
}
|
|
3332
3751
|
lines.push(
|
|
@@ -3358,7 +3777,7 @@ function renderHumanReport(report) {
|
|
|
3358
3777
|
lines.push(bold(`Could not audit ${report.unreachable.length} server(s):`), "");
|
|
3359
3778
|
for (const failure of report.unreachable) {
|
|
3360
3779
|
const label = failure.kind === "auth" ? yellow("needs creds") : failure.kind === "forbidden" ? yellow("not permitted") : red("unreachable");
|
|
3361
|
-
lines.push(` ${label} ${bold(visibleControls(failure.server))}`, ` ${
|
|
3780
|
+
lines.push(` ${label} ${bold(visibleControls(failure.server))}`, ` ${visibleLines(failure.reason, " ")}`, "");
|
|
3362
3781
|
}
|
|
3363
3782
|
}
|
|
3364
3783
|
const unverified = report.unverified ?? [];
|
|
@@ -3435,7 +3854,9 @@ function renderJsonReport(report, exitCode) {
|
|
|
3435
3854
|
*/
|
|
3436
3855
|
steering: (report.steering ?? []).reduce((sum, server2) => sum + server2.signals.length, 0),
|
|
3437
3856
|
/** Unlike steering, these DO decide the exit code. */
|
|
3438
|
-
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
|
|
3439
3860
|
},
|
|
3440
3861
|
changes: report.changes.map((change2) => ({
|
|
3441
3862
|
kind: change2.kind,
|
|
@@ -3449,7 +3870,8 @@ function renderJsonReport(report, exitCode) {
|
|
|
3449
3870
|
unreachable: report.unreachable,
|
|
3450
3871
|
/** Text that began addressing the model since the lock was approved. Reported, never gated. */
|
|
3451
3872
|
steering: report.steering ?? [],
|
|
3452
|
-
violations: report.violations ?? []
|
|
3873
|
+
violations: report.violations ?? [],
|
|
3874
|
+
unverified: report.unverified ?? []
|
|
3453
3875
|
},
|
|
3454
3876
|
null,
|
|
3455
3877
|
2
|
|
@@ -3485,6 +3907,7 @@ var LEVEL = {
|
|
|
3485
3907
|
};
|
|
3486
3908
|
var DENIED_RULE = "policy.capability.denied";
|
|
3487
3909
|
var STEERING_RULE = "steering.passage.arrived";
|
|
3910
|
+
var UNVERIFIED_RULE = "server.artifact.unverified";
|
|
3488
3911
|
var RULE_HELP = {
|
|
3489
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.",
|
|
3490
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.",
|
|
@@ -3510,6 +3933,7 @@ function renderSarifReport(report, options = {}) {
|
|
|
3510
3933
|
const used = [...new Set(report.changes.map((change2) => change2.kind))].sort();
|
|
3511
3934
|
const violations = report.violations ?? [];
|
|
3512
3935
|
const steering = options.steering ? report.steering ?? [] : [];
|
|
3936
|
+
const unverified = report.unverified ?? [];
|
|
3513
3937
|
const at = (name, qualified) => [
|
|
3514
3938
|
{
|
|
3515
3939
|
physicalLocation: { artifactLocation: { uri: sarifUri(report), uriBaseId: "%SRCROOT%" } },
|
|
@@ -3530,6 +3954,13 @@ function renderSarifReport(report, options = {}) {
|
|
|
3530
3954
|
shortDescription: { text: "Text that began addressing the model" },
|
|
3531
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." },
|
|
3532
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" }
|
|
3533
3964
|
}] : []
|
|
3534
3965
|
];
|
|
3535
3966
|
const document = {
|
|
@@ -3578,7 +4009,14 @@ function renderSarifReport(report, options = {}) {
|
|
|
3578
4009
|
locations: at(signal.field, `${server2}/${signal.field}`),
|
|
3579
4010
|
partialFingerprints: { "mcpAuditChange/v1": `${server2}/${signal.field}/${signal.kind}` }
|
|
3580
4011
|
}))
|
|
3581
|
-
)
|
|
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
|
+
}))
|
|
3582
4020
|
]
|
|
3583
4021
|
}
|
|
3584
4022
|
]
|
|
@@ -3595,10 +4033,10 @@ var AUDIT_FAILURE_LABEL = {
|
|
|
3595
4033
|
};
|
|
3596
4034
|
var MARK2 = { high: "\u{1F534}", medium: "\u{1F7E0}", low: "\u26AA" };
|
|
3597
4035
|
function plain(text) {
|
|
3598
|
-
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();
|
|
3599
4037
|
}
|
|
3600
4038
|
function code(text) {
|
|
3601
|
-
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();
|
|
3602
4040
|
const longest = Math.max(0, ...(body.match(/`+/g) ?? []).map((run) => run.length));
|
|
3603
4041
|
const fence = "`".repeat(longest + 1);
|
|
3604
4042
|
const pad = body.startsWith("`") || body.endsWith("`") ? " " : "";
|
|
@@ -3609,16 +4047,21 @@ function row(change2) {
|
|
|
3609
4047
|
return `| ${MARK2[change2.severity]} ${change2.severity} | ${code(where)} | ${plain(change2.kind)} | ${plain(change2.summary)} |`;
|
|
3610
4048
|
}
|
|
3611
4049
|
function renderMarkdownReport(report, options = {}) {
|
|
3612
|
-
|
|
4050
|
+
const violations = report.violations ?? [];
|
|
4051
|
+
if (report.changes.length === 0 && report.unreachable.length === 0 && violations.length === 0) return null;
|
|
3613
4052
|
const lines = [];
|
|
3614
4053
|
const high = report.changes.filter((change2) => change2.severity === "high").length;
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
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
|
+
}
|
|
3622
4065
|
if (report.changes.length > 0) {
|
|
3623
4066
|
lines.push("| | Where | What | Detail |", "| --- | --- | --- | --- |", ...report.changes.map(row), "");
|
|
3624
4067
|
const quiet = serversThatShippedNothing(report.changes);
|
|
@@ -3631,6 +4074,16 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
3631
4074
|
);
|
|
3632
4075
|
}
|
|
3633
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
|
+
}
|
|
3634
4087
|
const steering = report.steering ?? [];
|
|
3635
4088
|
if (steering.length > 0) {
|
|
3636
4089
|
const total = steering.reduce((sum, server2) => sum + server2.signals.length, 0);
|
|
@@ -3663,6 +4116,19 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
3663
4116
|
""
|
|
3664
4117
|
);
|
|
3665
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
|
+
}
|
|
3666
4132
|
lines.push(
|
|
3667
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."
|
|
3668
4134
|
);
|
|
@@ -3704,12 +4170,29 @@ ${body}`;
|
|
|
3704
4170
|
const existing = await call(target, `/issues/${target.issue}/comments?per_page=100`);
|
|
3705
4171
|
if (existing.status === 403) return "forbidden";
|
|
3706
4172
|
if (!existing.ok) throw new Error(`could not read the comments (${existing.status})`);
|
|
4173
|
+
const self = await identity2(target);
|
|
3707
4174
|
const comments = await existing.json();
|
|
3708
|
-
const mine = comments.find((comment2) => comment2.body?.startsWith(MARKER));
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
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]";
|
|
3713
4196
|
}
|
|
3714
4197
|
|
|
3715
4198
|
// src/telemetry/index.ts
|
|
@@ -3823,7 +4306,7 @@ async function buildReport(options) {
|
|
|
3823
4306
|
});
|
|
3824
4307
|
for (const note of redactedNotes(result.lock)) process.stderr.write(`${yellow("note:")} ${note}
|
|
3825
4308
|
`);
|
|
3826
|
-
const changes =
|
|
4309
|
+
const changes = compareWithLock(committed, result);
|
|
3827
4310
|
const allowUnreachable = options.allowUnreachable || committed.policy?.allowUnreachable === true;
|
|
3828
4311
|
const report = {
|
|
3829
4312
|
changes,
|
|
@@ -3894,7 +4377,7 @@ async function comment(report) {
|
|
|
3894
4377
|
}
|
|
3895
4378
|
|
|
3896
4379
|
// src/commands/init.ts
|
|
3897
|
-
import { lstat as
|
|
4380
|
+
import { lstat as lstat3 } from "fs/promises";
|
|
3898
4381
|
|
|
3899
4382
|
// src/commands/telemetry.ts
|
|
3900
4383
|
import { createInterface } from "readline/promises";
|
|
@@ -3989,7 +4472,7 @@ ${dim(" No collector is configured in this build, so nothing will be sent until
|
|
|
3989
4472
|
// src/commands/init.ts
|
|
3990
4473
|
async function exists(path) {
|
|
3991
4474
|
try {
|
|
3992
|
-
await
|
|
4475
|
+
await lstat3(path);
|
|
3993
4476
|
return true;
|
|
3994
4477
|
} catch {
|
|
3995
4478
|
return false;
|
|
@@ -4032,7 +4515,8 @@ async function runInit(options) {
|
|
|
4032
4515
|
return EXIT_CLEAN;
|
|
4033
4516
|
}
|
|
4034
4517
|
const pinnedSomething = names.length > 0;
|
|
4035
|
-
|
|
4518
|
+
const unaudited = options.allowUnreachable ? unauditedToRecord(result) : void 0;
|
|
4519
|
+
if (pinnedSomething) await writeLockfile(options.lockPath, unaudited ? { ...result.lock, unaudited } : result.lock);
|
|
4036
4520
|
const lines = pinnedSomething ? ["", bold(`Pinned ${names.length} server(s) to ${options.lockPath}:`), ""] : ["", bold("Pinned nothing: no server answered."), ""];
|
|
4037
4521
|
for (const name of names) {
|
|
4038
4522
|
const entry = result.lock.subjects[name];
|
|
@@ -4076,7 +4560,7 @@ async function runInit(options) {
|
|
|
4076
4560
|
}
|
|
4077
4561
|
}
|
|
4078
4562
|
for (const failure of result.unreachable) {
|
|
4079
|
-
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, " ")}`);
|
|
4080
4564
|
}
|
|
4081
4565
|
if (result.discovery.userConfigsSkipped.length > 0) {
|
|
4082
4566
|
lines.push(
|
|
@@ -4101,7 +4585,8 @@ async function runInit(options) {
|
|
|
4101
4585
|
// src/commands/login.ts
|
|
4102
4586
|
import { createServer } from "http";
|
|
4103
4587
|
import { auth } from "@modelcontextprotocol/client";
|
|
4104
|
-
import { rm as rm4 } from "fs/promises";
|
|
4588
|
+
import { rm as rm4, stat } from "fs/promises";
|
|
4589
|
+
import { resolve as resolve5 } from "path";
|
|
4105
4590
|
var CALLBACK_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
4106
4591
|
async function awaitCallback(expectedState) {
|
|
4107
4592
|
let settle;
|
|
@@ -4138,8 +4623,8 @@ async function awaitCallback(expectedState) {
|
|
|
4138
4623
|
server2.listen(0, "127.0.0.1", ready);
|
|
4139
4624
|
});
|
|
4140
4625
|
const { port } = server2.address();
|
|
4141
|
-
const received = new Promise((
|
|
4142
|
-
settle =
|
|
4626
|
+
const received = new Promise((resolve7, reject) => {
|
|
4627
|
+
settle = resolve7;
|
|
4143
4628
|
fail = reject;
|
|
4144
4629
|
setTimeout(() => reject(new Error(`no callback within ${CALLBACK_TIMEOUT_MS / 1e3}s`)), CALLBACK_TIMEOUT_MS).unref();
|
|
4145
4630
|
});
|
|
@@ -4151,6 +4636,16 @@ async function awaitCallback(expectedState) {
|
|
|
4151
4636
|
}
|
|
4152
4637
|
async function findServer(projectRoot, configFiles, name) {
|
|
4153
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
|
+
}
|
|
4154
4649
|
const server2 = discovery.servers.find((candidate) => candidate.name === name);
|
|
4155
4650
|
if (!server2) {
|
|
4156
4651
|
const known = discovery.servers.map((candidate) => candidate.name);
|
|
@@ -4159,6 +4654,10 @@ async function findServer(projectRoot, configFiles, name) {
|
|
|
4159
4654
|
if (server2.transport.type === "stdio") return { error: `"${name}" is a stdio server; it is launched locally and has nothing to log in to` };
|
|
4160
4655
|
return server2;
|
|
4161
4656
|
}
|
|
4657
|
+
function describeTarget(server2) {
|
|
4658
|
+
const { transport: transport2 } = server2;
|
|
4659
|
+
return transport2.type === "stdio" ? `runs ${transport2.command}` : sanitizeUrl(transport2.url);
|
|
4660
|
+
}
|
|
4162
4661
|
async function runLogin(options) {
|
|
4163
4662
|
if (options.serverName === void 0) {
|
|
4164
4663
|
process.stderr.write(`${red("which server?")} ${dim("Usage: nulladrift login <server>")}
|
|
@@ -4218,9 +4717,16 @@ async function runLogout(options) {
|
|
|
4218
4717
|
return EXIT_INCOMPLETE;
|
|
4219
4718
|
}
|
|
4220
4719
|
const url = found.transport.type === "stdio" ? "" : found.transport.url;
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
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
|
+
);
|
|
4224
4730
|
return EXIT_CLEAN;
|
|
4225
4731
|
}
|
|
4226
4732
|
|
|
@@ -4283,7 +4789,7 @@ async function acquireBuildToken(options = {}) {
|
|
|
4283
4789
|
const explicit = env["NULLADRIFT_ID_TOKEN"];
|
|
4284
4790
|
if (explicit) return { token: explicit, source: "environment" };
|
|
4285
4791
|
if (env["GITHUB_ACTIONS"] !== "true") return void 0;
|
|
4286
|
-
return fromGithubActions(env["NULLADRIFT_BUILD_AUDIENCE"]
|
|
4792
|
+
return fromGithubActions(env["NULLADRIFT_BUILD_AUDIENCE"] || DEFAULT_AUDIENCE, env, options);
|
|
4287
4793
|
}
|
|
4288
4794
|
async function acquireReadingToken(audience, options = {}) {
|
|
4289
4795
|
const env = options.env ?? process.env;
|
|
@@ -4313,14 +4819,15 @@ async function fromGithubActions(audience, env, options) {
|
|
|
4313
4819
|
}
|
|
4314
4820
|
|
|
4315
4821
|
// src/commands/push.ts
|
|
4316
|
-
function describeIdentity(
|
|
4317
|
-
const
|
|
4318
|
-
const
|
|
4319
|
-
|
|
4320
|
-
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") {
|
|
4321
4828
|
return `${yellow("signed")} ${dim(`${where} \xB7 not a build this organization lists as trusted${contents}`)}`;
|
|
4322
4829
|
}
|
|
4323
|
-
if (
|
|
4830
|
+
if (identity3?.rejected) return `${red("build token refused")} ${dim(shown(identity3.rejected))}`;
|
|
4324
4831
|
return hint ? dim(`unsigned: ${hint}`) : void 0;
|
|
4325
4832
|
}
|
|
4326
4833
|
function inferProject(projectRoot) {
|
|
@@ -4346,6 +4853,7 @@ function refuseApiUrl(apiUrl) {
|
|
|
4346
4853
|
if (url.protocol === "https:" || url.protocol === "http:" && loopback) return void 0;
|
|
4347
4854
|
return `the control plane has to be reached over https (http only on this machine), not ${url.protocol}`;
|
|
4348
4855
|
}
|
|
4856
|
+
var UNSENDABLE2 = /[\r\n\0]/;
|
|
4349
4857
|
async function runPush(options) {
|
|
4350
4858
|
const apiUrl = (options.apiUrl ?? process.env["NULLADRIFT_API_URL"] ?? "").replace(/\/+$/, "");
|
|
4351
4859
|
const token = options.token ?? process.env["NULLADRIFT_TOKEN"] ?? "";
|
|
@@ -4367,6 +4875,17 @@ async function runPush(options) {
|
|
|
4367
4875
|
`);
|
|
4368
4876
|
return EXIT_INCOMPLETE;
|
|
4369
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
|
+
}
|
|
4370
4889
|
const result = await captureAll({
|
|
4371
4890
|
projectRoot: options.projectRoot,
|
|
4372
4891
|
configFiles: options.configFiles,
|
|
@@ -4414,8 +4933,14 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4414
4933
|
acquireBuildToken(),
|
|
4415
4934
|
acquireReadingToken(readingAudience(readingAudienceBase(apiUrl), digest2))
|
|
4416
4935
|
]);
|
|
4417
|
-
const
|
|
4418
|
-
|
|
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");
|
|
4419
4944
|
let response;
|
|
4420
4945
|
try {
|
|
4421
4946
|
response = await fetch(`${apiUrl}/api/v1/ingest`, {
|
|
@@ -4432,7 +4957,9 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4432
4957
|
signal: AbortSignal.timeout(options.timeoutMs)
|
|
4433
4958
|
});
|
|
4434
4959
|
} catch (error) {
|
|
4435
|
-
|
|
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}
|
|
4436
4963
|
`);
|
|
4437
4964
|
return EXIT_INCOMPLETE;
|
|
4438
4965
|
}
|
|
@@ -4445,16 +4972,17 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4445
4972
|
const verdict = await response.json();
|
|
4446
4973
|
const lines = [""];
|
|
4447
4974
|
const mark = verdict.verdict === "clean" ? green("\u2713") : verdict.verdict === "drift" ? yellow("!") : red("\u2717");
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
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}`);
|
|
4451
4979
|
for (const change2 of verdict.changes) {
|
|
4452
|
-
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)}`);
|
|
4453
4981
|
}
|
|
4454
4982
|
for (const reason of verdict.decision.reasons) {
|
|
4455
|
-
lines.push(` ${red("blocked")} ${dim(reason.code)} ${reason.message}`);
|
|
4983
|
+
lines.push(` ${red("blocked")} ${dim(shown(reason.code))} ${shown(reason.message)}`);
|
|
4456
4984
|
}
|
|
4457
|
-
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)}`));
|
|
4458
4986
|
lines.push("");
|
|
4459
4987
|
process.stdout.write(lines.join("\n"));
|
|
4460
4988
|
return verdict.exitCode === 0 ? EXIT_CLEAN : verdict.exitCode === 1 ? EXIT_DRIFT : EXIT_INCOMPLETE;
|
|
@@ -4511,7 +5039,7 @@ async function runReview(options) {
|
|
|
4511
5039
|
provenance: options.provenance,
|
|
4512
5040
|
userConfigs: options.userConfigs
|
|
4513
5041
|
});
|
|
4514
|
-
const changes =
|
|
5042
|
+
const changes = compareWithLock(committed, result);
|
|
4515
5043
|
if (changes.length === 0) {
|
|
4516
5044
|
process.stdout.write(`${green(`\u2713 nothing to review; ${options.lockPath} is up to date`)}
|
|
4517
5045
|
`);
|
|
@@ -4556,9 +5084,18 @@ ${context.length > 0 ? `${context.join("\n")}
|
|
|
4556
5084
|
continue;
|
|
4557
5085
|
}
|
|
4558
5086
|
accepted += 1;
|
|
4559
|
-
|
|
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
|
+
}
|
|
4560
5093
|
if (fresh) next.subjects[serverName] = fresh;
|
|
4561
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;
|
|
4562
5099
|
for (const change2 of serverChanges) {
|
|
4563
5100
|
if (change2.kind === "server.renamed" && typeof change2.before === "string") delete next.subjects[change2.before];
|
|
4564
5101
|
}
|
|
@@ -4665,10 +5202,10 @@ async function main() {
|
|
|
4665
5202
|
`);
|
|
4666
5203
|
return EXIT_INCOMPLETE;
|
|
4667
5204
|
}
|
|
4668
|
-
const projectRoot =
|
|
5205
|
+
const projectRoot = resolve6(values.cwd ?? process.cwd());
|
|
4669
5206
|
const options = {
|
|
4670
5207
|
projectRoot,
|
|
4671
|
-
lockPath:
|
|
5208
|
+
lockPath: resolve6(projectRoot, values.lock ?? DEFAULT_LOCK_FILENAME),
|
|
4672
5209
|
configFiles: values.config ?? [],
|
|
4673
5210
|
timeoutMs,
|
|
4674
5211
|
allowUnreachable: values["allow-unreachable"],
|