@verax-ai/body 0.5.1 → 0.6.1
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 +4 -3
- package/dist/approval-signature.d.ts +19 -0
- package/dist/approval-signature.js +70 -5
- package/dist/approve-cli.js +20 -24
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +146 -14
- package/dist/config.d.ts +27 -0
- package/dist/config.js +72 -1
- package/dist/control-signature.d.ts +4 -0
- package/dist/control-signature.js +20 -5
- package/dist/definitions.d.ts +9 -0
- package/dist/definitions.js +53 -0
- package/dist/demo.js +11 -11
- package/dist/doctor.js +72 -0
- package/dist/downstream-pin.d.ts +9 -0
- package/dist/downstream-pin.js +273 -0
- package/dist/downstream.d.ts +22 -2
- package/dist/downstream.js +312 -44
- package/dist/heartbeat.d.ts +26 -2
- package/dist/heartbeat.js +90 -7
- package/dist/held-spend.d.ts +16 -0
- package/dist/held-spend.js +20 -0
- package/dist/http-io.d.ts +14 -0
- package/dist/http-io.js +46 -0
- package/dist/init-local.d.ts +11 -0
- package/dist/init-local.js +32 -3
- package/dist/install.d.ts +5 -0
- package/dist/install.js +37 -5
- package/dist/main.d.ts +1 -0
- package/dist/main.js +40 -6
- package/dist/operator-cli.d.ts +49 -1
- package/dist/operator-cli.js +136 -8
- package/dist/operator-credentials.d.ts +40 -1
- package/dist/operator-credentials.js +97 -7
- package/dist/operator-door-page.d.ts +3 -0
- package/dist/operator-door-page.js +819 -0
- package/dist/operator-door.d.ts +22 -0
- package/dist/operator-door.js +487 -0
- package/dist/operator-handlers.d.ts +28 -0
- package/dist/operator-handlers.js +221 -0
- package/dist/operator-pairing.d.ts +2 -0
- package/dist/operator-pairing.js +11 -0
- package/dist/reconcile-cli.js +3 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.js +133 -256
- package/dist/verify-cli.js +30 -10
- package/dist/webauthn-verify.d.ts +48 -4
- package/dist/webauthn-verify.js +183 -25
- package/dist/wiring.js +14 -1
- package/package.json +4 -4
package/dist/config.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
2
|
export const EX_CONFIG = 78;
|
|
3
|
+
/** A start error whose message begins with this is one stderr line and exit 78. */
|
|
4
|
+
export const POLICY_FILE_ERROR_PREFIX = "VERAX_POLICY_FILE ";
|
|
3
5
|
/** Per-tenant `memory.put` cap. The HTTP body cap does not reset this total. */
|
|
4
6
|
export const DEFAULT_MEMORY_QUOTA_BYTES = 1024 * 1024;
|
|
5
7
|
/** Per-tenant `message.send` cap. The HTTP body cap does not reset this total. */
|
|
@@ -47,6 +49,30 @@ function jwksPinParses(raw) {
|
|
|
47
49
|
return null;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
52
|
+
/** A directory or an unreadable file. A path that is not there is left to the read. */
|
|
53
|
+
export function policyFileRefusal(path) {
|
|
54
|
+
let st;
|
|
55
|
+
try {
|
|
56
|
+
st = statSync(path);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
const code = err.code;
|
|
60
|
+
if (code === "ENOENT")
|
|
61
|
+
return null;
|
|
62
|
+
return `${POLICY_FILE_ERROR_PREFIX}is missing or unreadable: ${path}`;
|
|
63
|
+
}
|
|
64
|
+
if (st.isDirectory())
|
|
65
|
+
return `${POLICY_FILE_ERROR_PREFIX}is a directory: ${path}`;
|
|
66
|
+
if (!st.isFile())
|
|
67
|
+
return `${POLICY_FILE_ERROR_PREFIX}is missing or unreadable: ${path}`;
|
|
68
|
+
try {
|
|
69
|
+
readFileSync(path);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return `${POLICY_FILE_ERROR_PREFIX}is missing or unreadable: ${path}`;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
50
76
|
function jwksFileParses(path) {
|
|
51
77
|
try {
|
|
52
78
|
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
@@ -56,6 +82,42 @@ function jwksFileParses(path) {
|
|
|
56
82
|
return false;
|
|
57
83
|
}
|
|
58
84
|
}
|
|
85
|
+
const DEFAULT_DOOR_BIND = "127.0.0.1:8788";
|
|
86
|
+
/**
|
|
87
|
+
* `VERAX_OPERATOR_DOOR` names the origin an operator reaches the door at. It
|
|
88
|
+
* is HTTPS, or `http://localhost` for a trial on the machine itself, and it
|
|
89
|
+
* is a name: WebAuthn does not take an IP address as a relying party. The
|
|
90
|
+
* door itself listens on loopback (`VERAX_OPERATOR_BIND`); what stands in
|
|
91
|
+
* front of it with a certificate is the operator's.
|
|
92
|
+
*/
|
|
93
|
+
export function readOperatorDoor(env) {
|
|
94
|
+
const raw = env.VERAX_OPERATOR_DOOR?.trim() ?? "";
|
|
95
|
+
if (raw === "")
|
|
96
|
+
return { ok: true, value: null };
|
|
97
|
+
let url;
|
|
98
|
+
try {
|
|
99
|
+
url = new URL(raw);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return { ok: false, reason: "VERAX_OPERATOR_DOOR is not an origin" };
|
|
103
|
+
}
|
|
104
|
+
if (url.origin !== raw) {
|
|
105
|
+
return { ok: false, reason: "VERAX_OPERATOR_DOOR is an origin only: scheme, host and port" };
|
|
106
|
+
}
|
|
107
|
+
const host = url.hostname;
|
|
108
|
+
if (/^[0-9.]+$/.test(host) || host.startsWith("[")) {
|
|
109
|
+
return { ok: false, reason: "VERAX_OPERATOR_DOOR needs a name, not an IP address" };
|
|
110
|
+
}
|
|
111
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && host === "localhost")) {
|
|
112
|
+
return { ok: false, reason: "VERAX_OPERATOR_DOOR needs https" };
|
|
113
|
+
}
|
|
114
|
+
const bindRaw = env.VERAX_OPERATOR_BIND?.trim() ?? "";
|
|
115
|
+
const bind = parseBind(bindRaw === "" ? DEFAULT_DOOR_BIND : bindRaw);
|
|
116
|
+
if (!isLoopbackHost(bind.host)) {
|
|
117
|
+
return { ok: false, reason: "VERAX_OPERATOR_BIND needs a loopback address" };
|
|
118
|
+
}
|
|
119
|
+
return { ok: true, value: { origin: url.origin, rpID: host, bindHost: bind.host, bindPort: bind.port } };
|
|
120
|
+
}
|
|
59
121
|
export function loadConfig(env) {
|
|
60
122
|
const issuer = env.VERAX_ISSUER?.trim() ?? "";
|
|
61
123
|
const jwksUrl = env.VERAX_JWKS_URL?.trim() ?? "";
|
|
@@ -114,6 +176,14 @@ export function loadConfig(env) {
|
|
|
114
176
|
if (policyFile === "") {
|
|
115
177
|
return { ok: false, code: EX_CONFIG, reason: "missing VERAX_POLICY_FILE" };
|
|
116
178
|
}
|
|
179
|
+
const policyRefusal = policyFileRefusal(policyFile);
|
|
180
|
+
if (policyRefusal) {
|
|
181
|
+
return { ok: false, code: EX_CONFIG, reason: policyRefusal };
|
|
182
|
+
}
|
|
183
|
+
const door = readOperatorDoor(env);
|
|
184
|
+
if (!door.ok) {
|
|
185
|
+
return { ok: false, code: EX_CONFIG, reason: door.reason };
|
|
186
|
+
}
|
|
117
187
|
const inventoryRaw = env.VERAX_INVENTORY_FILE?.trim() ?? "";
|
|
118
188
|
const downstreamRaw = env.VERAX_DOWNSTREAM?.trim() ?? "";
|
|
119
189
|
return {
|
|
@@ -137,6 +207,7 @@ export function loadConfig(env) {
|
|
|
137
207
|
.filter((item) => item !== ""),
|
|
138
208
|
memoryQuotaBytes: memoryQuotaBytes(env),
|
|
139
209
|
messageQuotaBytes: messageQuotaBytes(env),
|
|
210
|
+
operatorDoor: door.value,
|
|
140
211
|
},
|
|
141
212
|
};
|
|
142
213
|
}
|
|
@@ -33,6 +33,7 @@ export type ControlSignatureReport = {
|
|
|
33
33
|
ok: boolean;
|
|
34
34
|
signedVerified: number;
|
|
35
35
|
signedFailed: number;
|
|
36
|
+
signedAfterRemoval: number;
|
|
36
37
|
unsignedHttp: number;
|
|
37
38
|
cli: number;
|
|
38
39
|
file: number;
|
|
@@ -46,6 +47,9 @@ export type ControlSignatureReport = {
|
|
|
46
47
|
* just before its own (`null` for line 0), and verify under the operator key
|
|
47
48
|
* over the challenge rebuilt from that and the record's subject. A challenge
|
|
48
49
|
* counts once. The authenticator counter is not consulted.
|
|
50
|
+
* Removal marks advance in this same walk. They are not history lines:
|
|
51
|
+
* `prev` still names the history line before this record. A signature whose
|
|
52
|
+
* passkey is already in the set is not signed-verified; one earlier still is.
|
|
49
53
|
*/
|
|
50
54
|
export declare function verifyControlSignatures(stateDir: string, opts?: {
|
|
51
55
|
credentialsFile?: string;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { canonical } from "@cedulon/core";
|
|
14
14
|
import { listPieceFiles } from "@verax-ai/proxy";
|
|
15
|
-
import { asAssertion, assertionMatches, readLines, trustOf } from "./approval-signature.js";
|
|
15
|
+
import { asAssertion, assertionMatches, indexRemovalMark, noteChainRemoval, passkeyRemovedAt, readLines, signedAfterRemovalSegment, trustOf, } from "./approval-signature.js";
|
|
16
16
|
import { historyTail } from "./halt.js";
|
|
17
17
|
import { credentialsPath, findCredential, hasRegisteredOperator, readCredentialsAt, updateCounter, } from "./operator-credentials.js";
|
|
18
18
|
import { readRpConfig } from "./rp-config.js";
|
|
@@ -91,6 +91,9 @@ function controlSignatureOf(value) {
|
|
|
91
91
|
* just before its own (`null` for line 0), and verify under the operator key
|
|
92
92
|
* over the challenge rebuilt from that and the record's subject. A challenge
|
|
93
93
|
* counts once. The authenticator counter is not consulted.
|
|
94
|
+
* Removal marks advance in this same walk. They are not history lines:
|
|
95
|
+
* `prev` still names the history line before this record. A signature whose
|
|
96
|
+
* passkey is already in the set is not signed-verified; one earlier still is.
|
|
94
97
|
*/
|
|
95
98
|
export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
96
99
|
const pinned = typeof opts.credentialsFile === "string";
|
|
@@ -98,6 +101,7 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
98
101
|
const trust = trustOf(pinned, credentials);
|
|
99
102
|
const decisions = [];
|
|
100
103
|
const inputsByRef = new Map();
|
|
104
|
+
const removalByRef = new Map();
|
|
101
105
|
for (const piece of listPieceFiles(stateDir)) {
|
|
102
106
|
for (const line of readLines(piece.decisions)) {
|
|
103
107
|
try {
|
|
@@ -116,6 +120,7 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
116
120
|
const byHash = inputsByRef.get(row.ref) ?? new Map();
|
|
117
121
|
byHash.set(hash, row.inputs?.control ?? null);
|
|
118
122
|
inputsByRef.set(row.ref, byHash);
|
|
123
|
+
indexRemovalMark(removalByRef, row.ref, hash, row.inputs);
|
|
119
124
|
}
|
|
120
125
|
catch {
|
|
121
126
|
// Same as a decision line.
|
|
@@ -124,14 +129,19 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
124
129
|
}
|
|
125
130
|
let signedVerified = 0;
|
|
126
131
|
let signedFailed = 0;
|
|
132
|
+
let signedAfterRemoval = 0;
|
|
127
133
|
let unsignedHttp = 0;
|
|
128
134
|
let cli = 0;
|
|
129
135
|
let file = 0;
|
|
130
136
|
const lineHashByLine = new Map();
|
|
131
137
|
const used = new Set();
|
|
138
|
+
// Ledger order, not history-line order. A removal between two control
|
|
139
|
+
// records updates this set and leaves `lineHashByLine` where it was.
|
|
140
|
+
const removed = new Set();
|
|
132
141
|
for (const row of decisions) {
|
|
133
142
|
if (!row || typeof row !== "object" || !row.claims || typeof row.claims !== "object")
|
|
134
143
|
continue;
|
|
144
|
+
noteChainRemoval(row.claims, removalByRef, removed);
|
|
135
145
|
const claims = row.claims;
|
|
136
146
|
if (claims.effectClass !== "verax.control" || claims.decision !== "allow")
|
|
137
147
|
continue;
|
|
@@ -162,8 +172,12 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
162
172
|
if (challenge !== null)
|
|
163
173
|
used.add(challenge);
|
|
164
174
|
const cred = sig ? credentials.find((c) => c.id === sig.credentialId && c.sub === sig.sub) : undefined;
|
|
165
|
-
if (sig && cred && challenge && firstUse && assertionMatches(sig, cred.publicKey, challenge))
|
|
166
|
-
|
|
175
|
+
if (sig && cred && challenge && firstUse && assertionMatches(sig, cred.publicKey, challenge)) {
|
|
176
|
+
if (passkeyRemovedAt(sig.credentialId, removed))
|
|
177
|
+
signedAfterRemoval += 1;
|
|
178
|
+
else
|
|
179
|
+
signedVerified += 1;
|
|
180
|
+
}
|
|
167
181
|
else
|
|
168
182
|
signedFailed += 1;
|
|
169
183
|
}
|
|
@@ -171,13 +185,14 @@ export async function verifyControlSignatures(stateDir, opts = {}) {
|
|
|
171
185
|
lineHashByLine.set(at, control.lineHash);
|
|
172
186
|
}
|
|
173
187
|
return {
|
|
174
|
-
ok: signedFailed === 0,
|
|
188
|
+
ok: signedFailed === 0 && signedAfterRemoval === 0,
|
|
175
189
|
signedVerified,
|
|
176
190
|
signedFailed,
|
|
191
|
+
signedAfterRemoval,
|
|
177
192
|
unsignedHttp,
|
|
178
193
|
cli,
|
|
179
194
|
file,
|
|
180
|
-
line: `control signatures signed-verified ${signedVerified} · signed-failed ${signedFailed} · unsigned-http ${unsignedHttp} · cli ${cli} · file ${file}`,
|
|
195
|
+
line: `control signatures signed-verified ${signedVerified} · signed-failed ${signedFailed} · unsigned-http ${unsignedHttp} · cli ${cli} · file ${file}${signedAfterRemovalSegment(signedAfterRemoval)}`,
|
|
181
196
|
trustSource: trust.trustSource,
|
|
182
197
|
trustNote: trust.trustNote,
|
|
183
198
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies the pinned manifest into the state directory, create-only, before a
|
|
3
|
+
* start row names it. The source bytes must hash to the digest; a file
|
|
4
|
+
* already there must be those same bytes. What the copy and the signed row
|
|
5
|
+
* prove, and no more: the body that held a trusted record key recorded these
|
|
6
|
+
* definitions at that start. They do not prove that a person read them or
|
|
7
|
+
* that the child's code behaves as described.
|
|
8
|
+
*/
|
|
9
|
+
export declare function copyDefinition(stateDir: string, definitionsDir: string, digest: string): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
const DIGEST_RE = /^[0-9a-f]{64}$/;
|
|
5
|
+
/**
|
|
6
|
+
* Copies the pinned manifest into the state directory, create-only, before a
|
|
7
|
+
* start row names it. The source bytes must hash to the digest; a file
|
|
8
|
+
* already there must be those same bytes. What the copy and the signed row
|
|
9
|
+
* prove, and no more: the body that held a trusted record key recorded these
|
|
10
|
+
* definitions at that start. They do not prove that a person read them or
|
|
11
|
+
* that the child's code behaves as described.
|
|
12
|
+
*/
|
|
13
|
+
export function copyDefinition(stateDir, definitionsDir, digest) {
|
|
14
|
+
if (!DIGEST_RE.test(digest))
|
|
15
|
+
throw new Error(`downstream-manifest-invalid:${digest}`);
|
|
16
|
+
const source = join(definitionsDir, "definitions", `${digest}.json`);
|
|
17
|
+
let bytes;
|
|
18
|
+
try {
|
|
19
|
+
bytes = readFileSync(source);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error(`downstream-manifest-invalid:${digest}`);
|
|
23
|
+
}
|
|
24
|
+
if (createHash("sha256").update(bytes).digest("hex") !== digest) {
|
|
25
|
+
throw new Error(`downstream-manifest-invalid:${digest}`);
|
|
26
|
+
}
|
|
27
|
+
const dest = join(stateDir, "definitions", `${digest}.json`);
|
|
28
|
+
let existing;
|
|
29
|
+
try {
|
|
30
|
+
existing = readFileSync(dest);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
if (err.code !== "ENOENT")
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
if (existing !== undefined) {
|
|
37
|
+
if (existing.equals(bytes))
|
|
38
|
+
return;
|
|
39
|
+
throw new Error(`downstream-manifest-conflict:${digest}`);
|
|
40
|
+
}
|
|
41
|
+
mkdirSync(join(stateDir, "definitions"), { recursive: true, mode: 0o700 });
|
|
42
|
+
try {
|
|
43
|
+
writeFileSync(dest, bytes, { flag: "wx", mode: 0o600 });
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (err.code !== "EEXIST")
|
|
47
|
+
throw err;
|
|
48
|
+
const raced = readFileSync(dest);
|
|
49
|
+
if (raced.equals(bytes))
|
|
50
|
+
return;
|
|
51
|
+
throw new Error(`downstream-manifest-conflict:${digest}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/demo.js
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from "node:path";
|
|
|
6
6
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
7
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
8
8
|
import { exportJWK, generateKeyPair, SignJWT } from "jose";
|
|
9
|
-
import { verifyLedger } from "@verax-ai/proxy";
|
|
9
|
+
import { terminalText, verifyLedger } from "@verax-ai/proxy";
|
|
10
10
|
import { runApprove } from "./approve-cli.js";
|
|
11
11
|
import { listen } from "./server.js";
|
|
12
12
|
import { shippedPolicyPath } from "./shipped-policy.js";
|
|
@@ -341,8 +341,8 @@ export async function runDemo(argv, env, io, opts) {
|
|
|
341
341
|
if (!denied)
|
|
342
342
|
throw new Error(`demo: message.send ${toolText(sent)}`);
|
|
343
343
|
writeOut(`message.send -> ops@${DENY_HOST}\n`);
|
|
344
|
-
writeOut(` refused ${denied.code} (signed)\n`);
|
|
345
|
-
writeOut(` ref ${denied.ref}\n`);
|
|
344
|
+
writeOut(` refused ${terminalText(denied.code)} (signed)\n`);
|
|
345
|
+
writeOut(` ref ${terminalText(denied.ref)}\n`);
|
|
346
346
|
writeOut("\n");
|
|
347
347
|
const spent = await client.callTool({
|
|
348
348
|
name: "spend",
|
|
@@ -398,7 +398,7 @@ export async function runDemo(argv, env, io, opts) {
|
|
|
398
398
|
const secretsDenied = parseTagged(secrets.text, "denied");
|
|
399
399
|
writeOut("conarium.query public.secrets\n");
|
|
400
400
|
if (secretsDenied) {
|
|
401
|
-
writeOut(` refused ${secretsDenied.code} (signed)\n`);
|
|
401
|
+
writeOut(` refused ${terminalText(secretsDenied.code)} (signed)\n`);
|
|
402
402
|
failed = true;
|
|
403
403
|
}
|
|
404
404
|
else if (childAnsweredWithError(secrets.text, "conarium.query")) {
|
|
@@ -419,7 +419,7 @@ export async function runDemo(argv, env, io, opts) {
|
|
|
419
419
|
writeOut("conarium.list_tables\n");
|
|
420
420
|
if (!listedDenied)
|
|
421
421
|
throw new Error(`demo: conarium.list_tables ${listed.text}`);
|
|
422
|
-
writeOut(` refused ${listedDenied.code} (signed)\n`);
|
|
422
|
+
writeOut(` refused ${terminalText(listedDenied.code)} (signed)\n`);
|
|
423
423
|
writeOut(" refused by this gate; the downstream server never saw the call\n");
|
|
424
424
|
writeOut("\n");
|
|
425
425
|
}
|
|
@@ -442,8 +442,8 @@ export async function runDemo(argv, env, io, opts) {
|
|
|
442
442
|
findingCode = "unparsed";
|
|
443
443
|
}
|
|
444
444
|
writeOut("audit.explain of the refuse\n");
|
|
445
|
-
writeOut(` finding ${findingCode}\n`);
|
|
446
|
-
writeOut(` trust-root ${trust}\n`);
|
|
445
|
+
writeOut(` finding ${terminalText(findingCode)}\n`);
|
|
446
|
+
writeOut(` trust-root ${terminalText(trust)}\n`);
|
|
447
447
|
if (findingCode === "none" && trust !== "unread") {
|
|
448
448
|
writeOut(" chain and signatures read back\n");
|
|
449
449
|
}
|
|
@@ -461,8 +461,8 @@ export async function runDemo(argv, env, io, opts) {
|
|
|
461
461
|
writeOut(`records ${counted.decisions}\n`);
|
|
462
462
|
writeOut(`effects ${counted.effects}\n`);
|
|
463
463
|
if (keep) {
|
|
464
|
-
writeOut(`ledger ${stateDir}\n`);
|
|
465
|
-
writeOut(`verax verify ${stateDir}\n`);
|
|
464
|
+
writeOut(`ledger ${terminalText(stateDir)}\n`);
|
|
465
|
+
writeOut(`verax verify ${terminalText(stateDir)}\n`);
|
|
466
466
|
}
|
|
467
467
|
else {
|
|
468
468
|
writeOut("ledger removed on exit (run with --keep to keep it and check it with verax verify)\n");
|
|
@@ -476,10 +476,10 @@ export async function runDemo(argv, env, io, opts) {
|
|
|
476
476
|
const detail = err instanceof Error ? err.message : "fault";
|
|
477
477
|
if (withConarium && attachFailedDetail(detail)) {
|
|
478
478
|
discardState = true;
|
|
479
|
-
writeErr(`could not start the Conarium child (${detail}). run without --with-conarium\n`);
|
|
479
|
+
writeErr(`could not start the Conarium child (${terminalText(detail)}). run without --with-conarium\n`);
|
|
480
480
|
}
|
|
481
481
|
else {
|
|
482
|
-
writeErr(`demo: ${detail.replace(/^demo: /, "")}\n`);
|
|
482
|
+
writeErr(`demo: ${terminalText(detail.replace(/^demo: /, ""))}\n`);
|
|
483
483
|
}
|
|
484
484
|
await cleanup();
|
|
485
485
|
return 1;
|
package/dist/doctor.js
CHANGED
|
@@ -241,6 +241,22 @@ export function runDoctor(env, argv, opts = {}) {
|
|
|
241
241
|
detail: `stdio child ${spec.prefix} runs as the same user as the body and can read the body's signing keys (keys/*.pem). An untrusted child should be reached over HTTP, ideally on a separate machine or under a separate operating-system user.`,
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
|
+
for (const spec of specs) {
|
|
245
|
+
if (spec.pins === undefined) {
|
|
246
|
+
checks.push({
|
|
247
|
+
id: `downstream-unpinned:${spec.prefix}`,
|
|
248
|
+
level: "warn",
|
|
249
|
+
detail: `child ${spec.prefix} has no pins; tool definitions are not compared at start`,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (spec.command !== undefined && fetchesUnversionedPackage(spec.command, spec.args ?? [])) {
|
|
253
|
+
checks.push({
|
|
254
|
+
id: `downstream-unversioned:${spec.prefix}`,
|
|
255
|
+
level: "warn",
|
|
256
|
+
detail: `child ${spec.prefix} fetches a package with no version. A version is a name for the code, not proof of its integrity.`,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
244
260
|
}
|
|
245
261
|
catch (err) {
|
|
246
262
|
checks.push({
|
|
@@ -253,6 +269,62 @@ export function runDoctor(env, argv, opts = {}) {
|
|
|
253
269
|
checks.push(...jwksFileChecks(env, stateDir));
|
|
254
270
|
return checks;
|
|
255
271
|
}
|
|
272
|
+
function commandBase(command) {
|
|
273
|
+
const slash = Math.max(command.lastIndexOf("/"), command.lastIndexOf("\\"));
|
|
274
|
+
const base = (slash === -1 ? command : command.slice(slash + 1)).toLowerCase();
|
|
275
|
+
return base.replace(/\.(cmd|exe|bat)$/, "");
|
|
276
|
+
}
|
|
277
|
+
/** The package named by `--package` / `--from`, when that flag is present. */
|
|
278
|
+
function flaggedSpec(args, flag) {
|
|
279
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
280
|
+
const arg = args[i];
|
|
281
|
+
if (arg === flag)
|
|
282
|
+
return { present: true, value: args[i + 1] };
|
|
283
|
+
if (arg.startsWith(`${flag}=`))
|
|
284
|
+
return { present: true, value: arg.slice(flag.length + 1) };
|
|
285
|
+
}
|
|
286
|
+
return { present: false };
|
|
287
|
+
}
|
|
288
|
+
/** First argument that is not a flag. `-y` and `--yes` are flags and are skipped. */
|
|
289
|
+
function positionalSpec(args) {
|
|
290
|
+
for (const arg of args) {
|
|
291
|
+
if (arg === "-y" || arg === "--yes" || arg.startsWith("-"))
|
|
292
|
+
continue;
|
|
293
|
+
return arg;
|
|
294
|
+
}
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
/** major.minor.patch, with an optional prerelease or build. A dist-tag or a range is not this. */
|
|
298
|
+
const FULL_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
299
|
+
/** `name@1.2.3`. A scoped name's leading `@` is not a version. */
|
|
300
|
+
function npxVersioned(spec) {
|
|
301
|
+
const at = spec.startsWith("@") ? spec.indexOf("@", 1) : spec.indexOf("@");
|
|
302
|
+
return at > 0 && FULL_VERSION.test(spec.slice(at + 1));
|
|
303
|
+
}
|
|
304
|
+
/** `name==1.2.3`. `>=`, `~=` and `*` leave the package unversioned. */
|
|
305
|
+
function uvxVersioned(spec) {
|
|
306
|
+
const at = spec.indexOf("==");
|
|
307
|
+
if (at <= 0)
|
|
308
|
+
return false;
|
|
309
|
+
const version = spec.slice(at + 2);
|
|
310
|
+
return FULL_VERSION.test(version);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* True when `npx` or `uvx` fetches a package that carries no version.
|
|
314
|
+
* `npx name@1.2.3`, `npx --package name@1.2.3`, `uvx name==1.2.3` and
|
|
315
|
+
* `uvx --from name==1.2.3` are versioned. Any other command is not this check.
|
|
316
|
+
*/
|
|
317
|
+
function fetchesUnversionedPackage(command, args) {
|
|
318
|
+
const base = commandBase(command);
|
|
319
|
+
if (base !== "npx" && base !== "uvx")
|
|
320
|
+
return false;
|
|
321
|
+
const flag = base === "npx" ? "--package" : "--from";
|
|
322
|
+
const named = flaggedSpec(args, flag);
|
|
323
|
+
const spec = named.present ? named.value : positionalSpec(args);
|
|
324
|
+
if (spec === undefined || spec === "" || spec.startsWith("-"))
|
|
325
|
+
return true;
|
|
326
|
+
return base === "npx" ? !npxVersioned(spec) : !uvxVersioned(spec);
|
|
327
|
+
}
|
|
256
328
|
function jwksFileChecks(env, stateDir) {
|
|
257
329
|
const file = env.VERAX_JWKS_FILE?.trim() ?? "";
|
|
258
330
|
if (file === "")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type DownstreamPinIO = {
|
|
2
|
+
out: (s: string) => void;
|
|
3
|
+
ask: () => Promise<string>;
|
|
4
|
+
};
|
|
5
|
+
export declare function renderToolEntry(entry: unknown): string;
|
|
6
|
+
export declare function runDownstreamPin(input: {
|
|
7
|
+
file: string;
|
|
8
|
+
prefix: string;
|
|
9
|
+
}, io: DownstreamPinIO): Promise<number>;
|