@akai-workflow-builder/cli-sdk 0.13.0 → 0.15.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/CHANGELOG.md +22 -0
- package/README.md +57 -3
- package/dist/ctx/build-ctx.d.ts +10 -0
- package/dist/ctx/build-ctx.d.ts.map +1 -1
- package/dist/ctx/build-ctx.js +9 -0
- package/dist/ctx/private-egress.d.ts +81 -0
- package/dist/ctx/private-egress.d.ts.map +1 -0
- package/dist/ctx/private-egress.js +252 -0
- package/dist/ctx/safe-fetch.d.ts +54 -0
- package/dist/ctx/safe-fetch.d.ts.map +1 -1
- package/dist/ctx/safe-fetch.js +130 -15
- package/dist/ctx/trusted-ca.d.ts +60 -0
- package/dist/ctx/trusted-ca.d.ts.map +1 -0
- package/dist/ctx/trusted-ca.js +190 -0
- package/dist/define-connection.d.ts +3 -0
- package/dist/define-connection.d.ts.map +1 -1
- package/dist/define-connection.js +40 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/manifest/json-schema.d.ts +5 -0
- package/dist/manifest/json-schema.d.ts.map +1 -1
- package/dist/manifest/json-schema.js +36 -0
- package/dist/manifest/types.d.ts +6 -0
- package/dist/manifest/types.d.ts.map +1 -1
- package/dist/runtime/executor/index.d.ts +9 -0
- package/dist/runtime/executor/index.d.ts.map +1 -1
- package/dist/runtime/executor/index.js +2 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/registry/connection-manifest.d.ts.map +1 -1
- package/dist/runtime/registry/connection-manifest.js +1 -0
- package/dist/runtime/registry/loader.js +34 -6
- package/dist/runtime/registry/manifest-wire.d.ts.map +1 -1
- package/dist/runtime/registry/manifest-wire.js +2 -1
- package/dist/runtime/registry/types.d.ts +7 -0
- package/dist/runtime/registry/types.d.ts.map +1 -1
- package/dist/runtime/registry/wire.d.ts +17 -0
- package/dist/runtime/registry/wire.d.ts.map +1 -1
- package/dist/runtime/registry/wire.js +13 -0
- package/dist/tool.d.ts.map +1 -1
- package/dist/tool.js +19 -0
- package/dist/types.d.ts +36 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/ctx/safe-fetch.js
CHANGED
|
@@ -4,6 +4,8 @@ import { isIPv4, isIPv6 } from 'node:net';
|
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
5
|
import { Readable } from 'node:stream';
|
|
6
6
|
import { AkaiEgressError, AkaiResponseTooLargeError } from '../errors.js';
|
|
7
|
+
import { canonicalIp, cidrContains, isForbiddenPinAddress, normalizePrivateEgress, } from './private-egress.js';
|
|
8
|
+
import { ensureTrustedCa } from './trusted-ca.js';
|
|
7
9
|
/**
|
|
8
10
|
* Default per-response byte cap for JSON/text `ctx.fetch` calls (override via
|
|
9
11
|
* {@link SafeFetchBinding.maxResponseBytes}). Grounded in prod trace data
|
|
@@ -89,6 +91,51 @@ function hostMatches(hostname, allowed) {
|
|
|
89
91
|
return hostname === a || hostname.endsWith(`.${a}`);
|
|
90
92
|
});
|
|
91
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Decide whether an operator pin allows a request whose host resolved to a
|
|
96
|
+
* private address. Returns the pin and the checked addresses, or `null` — and
|
|
97
|
+
* on `null` the caller throws the same refusal it always has, word for word.
|
|
98
|
+
*
|
|
99
|
+
* A pin allows the call only when ALL of these hold:
|
|
100
|
+
* - the calling CLI is the pin's CLI (`cliId === pin.cli`);
|
|
101
|
+
* - the URL host is the pin's host, exactly: `url.hostname` is already
|
|
102
|
+
* lowercased by WHATWG URL, and there is no suffix or wildcard match, so
|
|
103
|
+
* `x.host`, `evilhost` and `host.evil.com` all fail;
|
|
104
|
+
* - the scheme is `https:` and the port is the pin's (443 by default);
|
|
105
|
+
* - EVERY resolved address is inside one of the pin's CIDRs and none of them
|
|
106
|
+
* is loopback, link-local (incl. the metadata address) or unspecified.
|
|
107
|
+
* Addresses are canonicalized first, so `::ffff:127.0.0.1` and `::ffff:7f00:1`
|
|
108
|
+
* are judged as the `127.0.0.1` they are. A mixed answer — one address in the
|
|
109
|
+
* CIDR, one outside it — fails: a single bad record is enough.
|
|
110
|
+
*
|
|
111
|
+
* Several pins may share a CLI and host; the first that satisfies all of the
|
|
112
|
+
* above wins.
|
|
113
|
+
*/
|
|
114
|
+
export function matchPrivatePin(pins, cliId, url, addresses) {
|
|
115
|
+
if (url.protocol !== 'https:' || addresses.length === 0)
|
|
116
|
+
return null;
|
|
117
|
+
const port = url.port === '' ? 443 : Number(url.port);
|
|
118
|
+
for (const pin of pins) {
|
|
119
|
+
if (pin.cli !== cliId || pin.host !== url.hostname || pin.port !== port)
|
|
120
|
+
continue;
|
|
121
|
+
const checked = [];
|
|
122
|
+
let allInside = true;
|
|
123
|
+
for (const address of addresses) {
|
|
124
|
+
const ip = canonicalIp(address);
|
|
125
|
+
if (ip === null || isForbiddenPinAddress(ip) || !pin.cidrs.some((cidr) => cidrContains(cidr, ip))) {
|
|
126
|
+
allInside = false;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
// An IPv4-mapped IPv6 answer is pinned as the plain IPv4 address it is.
|
|
130
|
+
const canonical = ip.length === 4 ? Array.from(ip).join('.') : address;
|
|
131
|
+
if (!checked.includes(canonical))
|
|
132
|
+
checked.push(canonical);
|
|
133
|
+
}
|
|
134
|
+
if (allInside)
|
|
135
|
+
return { pin, addresses: checked };
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
92
139
|
/**
|
|
93
140
|
* Decide the redirect mode for one call.
|
|
94
141
|
*
|
|
@@ -144,8 +191,11 @@ const FORWARDED_INIT_FIELDS = [
|
|
|
144
191
|
'referrerPolicy',
|
|
145
192
|
];
|
|
146
193
|
export function createSafeFetch(binding) {
|
|
147
|
-
const { egress, cliId, toolName, sdkVersion, tenantId, clientCert, userAgent, maxResponseBytes } = binding;
|
|
194
|
+
const { egress, cliId, toolName, sdkVersion, tenantId, clientCert, userAgent, trustedCa, maxResponseBytes } = binding;
|
|
148
195
|
const maxBytes = maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;
|
|
196
|
+
// Validated once per binding. An entry that fails validation is gone from here
|
|
197
|
+
// on, so the request path below only ever sees pins that are safe to match.
|
|
198
|
+
const privatePins = normalizePrivateEgress(binding.privateEgress, binding.onPrivateEgressInvalid);
|
|
149
199
|
return async function safeFetch(rawUrl, init = {}) {
|
|
150
200
|
// Coerce once. Otherwise `new URL(rawUrl)` (for validation) and
|
|
151
201
|
// `fetch(rawUrl, …)` would invoke `Symbol.toPrimitive`/`toString` twice,
|
|
@@ -190,9 +240,16 @@ export function createSafeFetch(binding) {
|
|
|
190
240
|
dnsMessage: err instanceof Error ? err.message : String(err),
|
|
191
241
|
});
|
|
192
242
|
}
|
|
243
|
+
// Set only when an operator pin allows this call to reach a private address.
|
|
244
|
+
let pinned = null;
|
|
193
245
|
if (!isDev) {
|
|
194
246
|
for (const { address } of addresses) {
|
|
195
247
|
if (isPrivateIp(address)) {
|
|
248
|
+
// The pin is judged against the WHOLE answer, once, at the first
|
|
249
|
+
// private address. No match → the refusal below, unchanged.
|
|
250
|
+
pinned = matchPrivatePin(privatePins, cliId, u, addresses.map((entry) => entry.address));
|
|
251
|
+
if (pinned !== null)
|
|
252
|
+
break;
|
|
196
253
|
throw new AkaiEgressError(`safe-fetch: ${u.hostname} resolved to private address ${address}`, { hostname: u.hostname, address, allResolved: addresses.map((entry) => entry.address) });
|
|
197
254
|
}
|
|
198
255
|
}
|
|
@@ -233,9 +290,25 @@ export function createSafeFetch(binding) {
|
|
|
233
290
|
// this path rides `node:https` — same TLS stack, zero dependencies —
|
|
234
291
|
// and adapts back to a standard `Response`. Dev-mode `http:` URLs fall
|
|
235
292
|
// through to plain fetch: there is no TLS handshake to present a cert on.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
293
|
+
//
|
|
294
|
+
// A pinned private-egress call also rides `node:https`, for a different
|
|
295
|
+
// reason: global fetch would resolve the host a second time and could be
|
|
296
|
+
// sent to an address the check above never saw (DNS rebinding), and it
|
|
297
|
+
// cannot take a per-connection CA. See pinnedHttpsFetch.
|
|
298
|
+
//
|
|
299
|
+
// Extra CAs go into Node's default CA list (extended, never replaced) so
|
|
300
|
+
// every transport below picks them up: global fetch, a host-installed
|
|
301
|
+
// global dispatcher (e.g. a proxy), and the node:https mTLS path.
|
|
302
|
+
if (trustedCa !== undefined && u.protocol === 'https:')
|
|
303
|
+
ensureTrustedCa(trustedCa, { cliId, toolName });
|
|
304
|
+
const response = pinned !== null
|
|
305
|
+
? await pinnedHttpsFetch(u, sanitized, {
|
|
306
|
+
...(clientCert !== undefined ? { identity: clientCert } : {}),
|
|
307
|
+
pin: { addresses: pinned.addresses, ...(pinned.pin.caPem !== undefined ? { caPem: pinned.pin.caPem } : {}) },
|
|
308
|
+
})
|
|
309
|
+
: clientCert !== undefined && u.protocol === 'https:'
|
|
310
|
+
? await pinnedHttpsFetch(u, sanitized, { identity: clientCert })
|
|
311
|
+
: await fetch(url, sanitized);
|
|
239
312
|
return capResponseBody(response, maxBytes, { hostname: u.hostname, cliId, toolName });
|
|
240
313
|
};
|
|
241
314
|
}
|
|
@@ -279,8 +352,26 @@ function capResponseBody(res, maxBytes, info) {
|
|
|
279
352
|
/** Response statuses that must not carry a body (Response ctor throws otherwise). */
|
|
280
353
|
const NULL_BODY_STATUSES = new Set([204, 205, 304]);
|
|
281
354
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
355
|
+
* A `lookup` that answers with the addresses safe-fetch already checked, so the
|
|
356
|
+
* socket cannot be sent anywhere a second DNS answer might point. Node calls it
|
|
357
|
+
* in either shape — `all: true` (happy-eyeballs, the default since Node 20) wants
|
|
358
|
+
* a list, the legacy form wants one address and its family.
|
|
359
|
+
*/
|
|
360
|
+
export function pinnedLookup(addresses) {
|
|
361
|
+
const entries = addresses.map((address) => ({ address, family: isIPv6(address) ? 6 : 4 }));
|
|
362
|
+
return (_hostname, options, callback) => {
|
|
363
|
+
if (options.all) {
|
|
364
|
+
callback(null, entries.map((entry) => ({ ...entry })));
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
callback(null, entries[0].address, entries[0].family);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Minimal fetch-over-`node:https`, used for the two cases global fetch cannot
|
|
373
|
+
* serve: mutual-TLS requests (`identity`) and operator-pinned private egress
|
|
374
|
+
* (`pin`). Parity notes vs global fetch:
|
|
284
375
|
* - `https.request` never follows redirects itself, so redirect handling is
|
|
285
376
|
* explicit: under `redirect: 'manual'` a 3xx is returned to the caller like
|
|
286
377
|
* any other response, and otherwise it is rejected — matching what
|
|
@@ -291,8 +382,21 @@ const NULL_BODY_STATUSES = new Set([204, 205, 304]);
|
|
|
291
382
|
* buffered, not streamed (fine for the ≤tens-of-MB payloads tools move).
|
|
292
383
|
* - No `accept-encoding` is sent, so upstreams respond uncompressed; if one
|
|
293
384
|
* compresses anyway the raw bytes surface with `content-encoding` intact.
|
|
385
|
+
*
|
|
386
|
+
* With a `pin`, the connection is held to what the egress check saw:
|
|
387
|
+
* - `lookup` answers only the checked addresses, so a second DNS answer (DNS
|
|
388
|
+
* rebinding) cannot redirect the socket;
|
|
389
|
+
* - `servername` is the pinned host and `ca` is the pin's CA when it has one —
|
|
390
|
+
* verification stays on, and the CA replaces the default store for this
|
|
391
|
+
* connection alone;
|
|
392
|
+
* - the `Host` header is forced to the pinned host. Global fetch ignores a
|
|
393
|
+
* caller-supplied `Host`, `node:https` does not, and the private gateway
|
|
394
|
+
* behind a pinned host routes on it, so a handler could otherwise ask a
|
|
395
|
+
* shared load balancer for a different internal service;
|
|
396
|
+
* - `agent: false` opens a fresh connection through that `lookup` instead of
|
|
397
|
+
* reusing a pooled socket that was dialled under another answer.
|
|
294
398
|
*/
|
|
295
|
-
async function
|
|
399
|
+
async function pinnedHttpsFetch(url, init, { identity, pin }) {
|
|
296
400
|
const headers = init.headers;
|
|
297
401
|
const method = (init.method ?? 'GET').toUpperCase();
|
|
298
402
|
let body;
|
|
@@ -312,14 +416,25 @@ async function mtlsFetch(url, init, identity) {
|
|
|
312
416
|
headers.forEach((value, name) => {
|
|
313
417
|
headerRecord[name] = value;
|
|
314
418
|
});
|
|
419
|
+
// `Headers` lowercases names, so this drops every spelling a handler tried.
|
|
420
|
+
if (pin)
|
|
421
|
+
headerRecord['host'] = url.host;
|
|
422
|
+
const requestOptions = {
|
|
423
|
+
method,
|
|
424
|
+
headers: headerRecord,
|
|
425
|
+
...(identity ? { cert: identity.cert, key: identity.key } : {}),
|
|
426
|
+
...(pin
|
|
427
|
+
? {
|
|
428
|
+
lookup: pinnedLookup(pin.addresses),
|
|
429
|
+
servername: url.hostname,
|
|
430
|
+
agent: false,
|
|
431
|
+
...(pin.caPem !== undefined ? { ca: pin.caPem } : {}),
|
|
432
|
+
}
|
|
433
|
+
: {}),
|
|
434
|
+
...(init.signal ? { signal: init.signal } : {}),
|
|
435
|
+
};
|
|
315
436
|
return new Promise((resolve, reject) => {
|
|
316
|
-
const req = httpsRequest(url, {
|
|
317
|
-
method,
|
|
318
|
-
headers: headerRecord,
|
|
319
|
-
cert: identity.cert,
|
|
320
|
-
key: identity.key,
|
|
321
|
-
...(init.signal ? { signal: init.signal } : {}),
|
|
322
|
-
}, (res) => {
|
|
437
|
+
const req = httpsRequest(url, requestOptions, (res) => {
|
|
323
438
|
// Synchronous throws in here (e.g. Response rejecting an interim
|
|
324
439
|
// status) must reject the fetch promise, not escape into http's
|
|
325
440
|
// event handling.
|
|
@@ -330,7 +445,7 @@ async function mtlsFetch(url, init, identity) {
|
|
|
330
445
|
status < 400 &&
|
|
331
446
|
res.headers.location !== undefined) {
|
|
332
447
|
res.resume();
|
|
333
|
-
reject(new AkaiEgressError(`safe-fetch: refusing redirect (${status}) on mutual-TLS request to ${url.hostname}`, { hostname: url.hostname, status }));
|
|
448
|
+
reject(new AkaiEgressError(`safe-fetch: refusing redirect (${status}) on ${pin ? 'pinned private-egress' : 'mutual-TLS'} request to ${url.hostname}`, { hostname: url.hostname, status }));
|
|
334
449
|
return;
|
|
335
450
|
}
|
|
336
451
|
// rawHeaders (flat name/value pairs) preserves repeated headers like
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extra CA certificates a tool declares in `network.trustedCa`, for upstreams
|
|
3
|
+
* whose server leaves an intermediate out of its TLS chain.
|
|
4
|
+
*
|
|
5
|
+
* Browsers fetch a missing intermediate themselves (from the leaf's AIA
|
|
6
|
+
* extension); Node does not, so such a server fails every `ctx.fetch` with
|
|
7
|
+
* `UNABLE_TO_VERIFY_LEAF_SIGNATURE` (AKAI-3302: laborfirst.delaware.gov, which
|
|
8
|
+
* omits Sectigo's "Public Server Authentication CA OV R36"). The fix is to
|
|
9
|
+
* hand Node that public intermediate, never to turn verification off.
|
|
10
|
+
*
|
|
11
|
+
* What a tool may declare is held to one rule: each certificate must be a CA
|
|
12
|
+
* certificate that is not self-signed and is issued directly, by verified
|
|
13
|
+
* signature, by a root already in Node's bundled store. Deeper chains are
|
|
14
|
+
* refused: their path constraints (pathLenConstraint, name constraints) would
|
|
15
|
+
* need checking, which Node does not expose. One outside its validity window is never installed. OpenSSL only builds chains up to a self-signed anchor —
|
|
16
|
+
* Node leaves partial-chain trust off — so such an intermediate adds no new
|
|
17
|
+
* trust: it lets Node complete a chain it would already accept from a server
|
|
18
|
+
* that sent it. That is what makes it safe to add these to the process's
|
|
19
|
+
* default CA list (below) rather than to one connection: no host becomes
|
|
20
|
+
* reachable that was not already trusted, and the tool's egress allowlist
|
|
21
|
+
* still decides which hosts it may reach at all.
|
|
22
|
+
*
|
|
23
|
+
* Applying through the default CA list, not a per-request option, is what
|
|
24
|
+
* lets this compose with every transport `ctx.fetch` rides: global fetch on
|
|
25
|
+
* Node's own dispatcher, a host-installed global dispatcher (the worker's
|
|
26
|
+
* PROXY_LOCATION ProxyAgent, whose tunnelled TLS leg uses the default list),
|
|
27
|
+
* and the `node:https` path that mutual TLS takes. Node's defaults are
|
|
28
|
+
* extended, never replaced.
|
|
29
|
+
*/
|
|
30
|
+
import { X509Certificate } from 'node:crypto';
|
|
31
|
+
/**
|
|
32
|
+
* Hold `network.trustedCa` to the rule above and return each certificate as
|
|
33
|
+
* normalised PEM. Throws a plain `Error` whose message names the offending
|
|
34
|
+
* certificate; `tool()` reports it as a spec error.
|
|
35
|
+
*
|
|
36
|
+
* @param input - one PEM string or a list; a string may hold several blocks.
|
|
37
|
+
* @param roots - the trust anchors to chain to; Node's bundled roots by default.
|
|
38
|
+
*
|
|
39
|
+
* Validity dates are not checked here: this runs when a tool is defined, at
|
|
40
|
+
* module load, so an embedded certificate expiring would take every tool of the
|
|
41
|
+
* CLI down with it. {@link ensureTrustedCa} leaves an out-of-date one out instead.
|
|
42
|
+
*/
|
|
43
|
+
export declare function validateTrustedCa(input: string | readonly string[], roots?: readonly X509Certificate[]): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Make sure `pems` (already validated and normalised by
|
|
46
|
+
* {@link validateTrustedCa}) are in this process's default CA list, extending
|
|
47
|
+
* Node's defaults rather than replacing them. Idempotent and cheap once done.
|
|
48
|
+
*
|
|
49
|
+
* @throws {AkaiEgressError} when the Node.js runtime cannot extend its CA list
|
|
50
|
+
* (`tls.setDefaultCACertificates` landed in Node 24.5), or when the default
|
|
51
|
+
* list does not hold Node's bundled roots. Failing here, before the request,
|
|
52
|
+
* beats the opaque TLS error the request would otherwise end in.
|
|
53
|
+
*/
|
|
54
|
+
export declare function ensureTrustedCa(pems: readonly string[], info: {
|
|
55
|
+
cliId: string;
|
|
56
|
+
toolName: string;
|
|
57
|
+
}, now?: Date): void;
|
|
58
|
+
/** Test hook: forget what {@link ensureTrustedCa} did. Does not touch Node's CA list. */
|
|
59
|
+
export declare function resetTrustedCaForTests(): void;
|
|
60
|
+
//# sourceMappingURL=trusted-ca.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trusted-ca.d.ts","sourceRoot":"","sources":["../../src/ctx/trusted-ca.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA8C9C;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EACjC,KAAK,GAAE,SAAS,eAAe,EAA8B,GAC5D,MAAM,EAAE,CAyCV;AASD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EACzC,GAAG,GAAE,IAAiB,GACrB,IAAI,CAiCN;AAmBD,yFAAyF;AACzF,wBAAgB,sBAAsB,IAAI,IAAI,CAG7C"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extra CA certificates a tool declares in `network.trustedCa`, for upstreams
|
|
3
|
+
* whose server leaves an intermediate out of its TLS chain.
|
|
4
|
+
*
|
|
5
|
+
* Browsers fetch a missing intermediate themselves (from the leaf's AIA
|
|
6
|
+
* extension); Node does not, so such a server fails every `ctx.fetch` with
|
|
7
|
+
* `UNABLE_TO_VERIFY_LEAF_SIGNATURE` (AKAI-3302: laborfirst.delaware.gov, which
|
|
8
|
+
* omits Sectigo's "Public Server Authentication CA OV R36"). The fix is to
|
|
9
|
+
* hand Node that public intermediate, never to turn verification off.
|
|
10
|
+
*
|
|
11
|
+
* What a tool may declare is held to one rule: each certificate must be a CA
|
|
12
|
+
* certificate that is not self-signed and is issued directly, by verified
|
|
13
|
+
* signature, by a root already in Node's bundled store. Deeper chains are
|
|
14
|
+
* refused: their path constraints (pathLenConstraint, name constraints) would
|
|
15
|
+
* need checking, which Node does not expose. One outside its validity window is never installed. OpenSSL only builds chains up to a self-signed anchor —
|
|
16
|
+
* Node leaves partial-chain trust off — so such an intermediate adds no new
|
|
17
|
+
* trust: it lets Node complete a chain it would already accept from a server
|
|
18
|
+
* that sent it. That is what makes it safe to add these to the process's
|
|
19
|
+
* default CA list (below) rather than to one connection: no host becomes
|
|
20
|
+
* reachable that was not already trusted, and the tool's egress allowlist
|
|
21
|
+
* still decides which hosts it may reach at all.
|
|
22
|
+
*
|
|
23
|
+
* Applying through the default CA list, not a per-request option, is what
|
|
24
|
+
* lets this compose with every transport `ctx.fetch` rides: global fetch on
|
|
25
|
+
* Node's own dispatcher, a host-installed global dispatcher (the worker's
|
|
26
|
+
* PROXY_LOCATION ProxyAgent, whose tunnelled TLS leg uses the default list),
|
|
27
|
+
* and the `node:https` path that mutual TLS takes. Node's defaults are
|
|
28
|
+
* extended, never replaced.
|
|
29
|
+
*/
|
|
30
|
+
import tls from 'node:tls';
|
|
31
|
+
import { X509Certificate } from 'node:crypto';
|
|
32
|
+
import { AkaiEgressError } from '../errors.js';
|
|
33
|
+
const BEGIN = '-----BEGIN CERTIFICATE-----';
|
|
34
|
+
const END = '-----END CERTIFICATE-----';
|
|
35
|
+
/**
|
|
36
|
+
* The CERTIFICATE blocks in `text`, found with a linear scan. Text between
|
|
37
|
+
* blocks must be whitespace, so a pasted private key or a stray line is
|
|
38
|
+
* rejected rather than silently dropped.
|
|
39
|
+
*/
|
|
40
|
+
function splitCertificates(text, label) {
|
|
41
|
+
const blocks = [];
|
|
42
|
+
let at = 0;
|
|
43
|
+
for (;;) {
|
|
44
|
+
const start = text.indexOf(BEGIN, at);
|
|
45
|
+
const gap = text.slice(at, start === -1 ? text.length : start);
|
|
46
|
+
if (gap.trim() !== '') {
|
|
47
|
+
throw new Error(`${label} holds text that is not a PEM certificate (only "${BEGIN}" blocks are accepted)`);
|
|
48
|
+
}
|
|
49
|
+
if (start === -1)
|
|
50
|
+
break;
|
|
51
|
+
const end = text.indexOf(END, start + BEGIN.length);
|
|
52
|
+
if (end === -1)
|
|
53
|
+
throw new Error(`${label} has a "${BEGIN}" with no matching "${END}"`);
|
|
54
|
+
blocks.push(text.slice(start, end + END.length));
|
|
55
|
+
at = end + END.length;
|
|
56
|
+
}
|
|
57
|
+
if (blocks.length === 0)
|
|
58
|
+
throw new Error(`${label} holds no PEM certificate`);
|
|
59
|
+
return blocks;
|
|
60
|
+
}
|
|
61
|
+
let bundledRoots;
|
|
62
|
+
function bundledRootCertificates() {
|
|
63
|
+
bundledRoots ??= tls.rootCertificates.map((pem) => new X509Certificate(pem));
|
|
64
|
+
return bundledRoots;
|
|
65
|
+
}
|
|
66
|
+
function issuedBy(cert, issuer) {
|
|
67
|
+
return cert.checkIssued(issuer) && cert.verify(issuer.publicKey);
|
|
68
|
+
}
|
|
69
|
+
const validAt = (cert, now) => cert.validFromDate.getTime() <= now.getTime() && now.getTime() <= cert.validToDate.getTime();
|
|
70
|
+
const oneLine = (dn) => dn.replace(/\n/g, ', ');
|
|
71
|
+
const subjectOf = (cert) => oneLine(cert.subject);
|
|
72
|
+
/**
|
|
73
|
+
* Hold `network.trustedCa` to the rule above and return each certificate as
|
|
74
|
+
* normalised PEM. Throws a plain `Error` whose message names the offending
|
|
75
|
+
* certificate; `tool()` reports it as a spec error.
|
|
76
|
+
*
|
|
77
|
+
* @param input - one PEM string or a list; a string may hold several blocks.
|
|
78
|
+
* @param roots - the trust anchors to chain to; Node's bundled roots by default.
|
|
79
|
+
*
|
|
80
|
+
* Validity dates are not checked here: this runs when a tool is defined, at
|
|
81
|
+
* module load, so an embedded certificate expiring would take every tool of the
|
|
82
|
+
* CLI down with it. {@link ensureTrustedCa} leaves an out-of-date one out instead.
|
|
83
|
+
*/
|
|
84
|
+
export function validateTrustedCa(input, roots = bundledRootCertificates()) {
|
|
85
|
+
const entries = typeof input === 'string' ? [input] : input;
|
|
86
|
+
if (entries.length === 0)
|
|
87
|
+
throw new Error('network.trustedCa must list at least one certificate');
|
|
88
|
+
const pending = [];
|
|
89
|
+
entries.forEach((entry, i) => {
|
|
90
|
+
const label = `network.trustedCa[${i}]`;
|
|
91
|
+
for (const block of splitCertificates(entry, label)) {
|
|
92
|
+
let cert;
|
|
93
|
+
try {
|
|
94
|
+
cert = new X509Certificate(block);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
throw new Error(`${label} is not a valid X.509 certificate`);
|
|
98
|
+
}
|
|
99
|
+
if (!cert.ca) {
|
|
100
|
+
throw new Error(`${label} (${subjectOf(cert)}) is not a CA certificate; only intermediates are accepted`);
|
|
101
|
+
}
|
|
102
|
+
if (issuedBy(cert, cert)) {
|
|
103
|
+
throw new Error(`${label} (${subjectOf(cert)}) is self-signed; a root would add new trust, so only intermediates that chain to a root Node already trusts are accepted`);
|
|
104
|
+
}
|
|
105
|
+
pending.push(cert);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
// Only certificates a bundled root issued directly are accepted. A deeper
|
|
109
|
+
// chain would need its path constraints (pathLenConstraint, name
|
|
110
|
+
// constraints) checked, which Node does not expose; installed in the shared
|
|
111
|
+
// CA list, a sub-CA that breaks them can make OpenSSL fail unrelated
|
|
112
|
+
// connections with PATH_LENGTH_EXCEEDED. One level is what an incomplete
|
|
113
|
+
// server chain needs in practice.
|
|
114
|
+
for (const cert of pending) {
|
|
115
|
+
if (!roots.some((root) => issuedBy(cert, root))) {
|
|
116
|
+
throw new Error(`network.trustedCa certificate ${subjectOf(cert)} is not issued directly by a root Node trusts (issuer: ${oneLine(cert.issuer)}); only first-level intermediates are accepted`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const accepted = pending;
|
|
120
|
+
return accepted.map((cert) => cert.toString());
|
|
121
|
+
}
|
|
122
|
+
/** Certificates {@link ensureTrustedCa} has dealt with: already trusted, or added by it. */
|
|
123
|
+
const handled = new Set();
|
|
124
|
+
/** The ones it added itself (normalised PEM → certificate), pruned once out of date. */
|
|
125
|
+
const added = new Map();
|
|
126
|
+
const fingerprint = (pem) => new X509Certificate(pem).fingerprint256;
|
|
127
|
+
/**
|
|
128
|
+
* Make sure `pems` (already validated and normalised by
|
|
129
|
+
* {@link validateTrustedCa}) are in this process's default CA list, extending
|
|
130
|
+
* Node's defaults rather than replacing them. Idempotent and cheap once done.
|
|
131
|
+
*
|
|
132
|
+
* @throws {AkaiEgressError} when the Node.js runtime cannot extend its CA list
|
|
133
|
+
* (`tls.setDefaultCACertificates` landed in Node 24.5), or when the default
|
|
134
|
+
* list does not hold Node's bundled roots. Failing here, before the request,
|
|
135
|
+
* beats the opaque TLS error the request would otherwise end in.
|
|
136
|
+
*/
|
|
137
|
+
export function ensureTrustedCa(pems, info, now = new Date()) {
|
|
138
|
+
pruneOutOfDate(now);
|
|
139
|
+
// A certificate outside its validity window is left out rather than
|
|
140
|
+
// installed: in the shared list OpenSSL may prefer it over the valid copy a
|
|
141
|
+
// server sends and fail unrelated connections. The request then fails
|
|
142
|
+
// verification as it would have without trustedCa.
|
|
143
|
+
const missing = pems.filter((pem) => !handled.has(pem) && validAt(new X509Certificate(pem), now));
|
|
144
|
+
if (missing.length === 0)
|
|
145
|
+
return;
|
|
146
|
+
if (typeof tls.setDefaultCACertificates !== 'function' || typeof tls.getCACertificates !== 'function') {
|
|
147
|
+
throw new AkaiEgressError(`safe-fetch: network.trustedCa needs Node.js 24.5 or later (tls.setDefaultCACertificates); this process runs ${process.version}`, { cliId: info.cliId, toolName: info.toolName, nodeVersion: process.version });
|
|
148
|
+
}
|
|
149
|
+
const current = tls.getCACertificates('default');
|
|
150
|
+
const present = new Set(current.map(fingerprint));
|
|
151
|
+
// The list Node reports must be the one it verifies with. It holds the
|
|
152
|
+
// bundled roots unless Node trusts OpenSSL's store instead (--use-openssl-ca
|
|
153
|
+
// in any spelling, or a build that defaults to it), whose SSL_CERT_FILE /
|
|
154
|
+
// SSL_CERT_DIR anchors it does not list: setting the default from it would
|
|
155
|
+
// drop those for every connection. Checked on the list itself rather than on
|
|
156
|
+
// flags, so no spelling of an option can slip past.
|
|
157
|
+
if (!tls.rootCertificates.every((root) => present.has(fingerprint(root)))) {
|
|
158
|
+
throw new AkaiEgressError("safe-fetch: network.trustedCa cannot extend Node's CA list here: it does not hold Node's bundled roots (e.g. --use-openssl-ca, which trusts OpenSSL's store instead); nothing was changed", { cliId: info.cliId, toolName: info.toolName });
|
|
159
|
+
}
|
|
160
|
+
// One the host already trusts stays the host's: not re-added, never pruned.
|
|
161
|
+
const adding = missing.filter((pem) => !present.has(fingerprint(pem)));
|
|
162
|
+
if (adding.length > 0)
|
|
163
|
+
tls.setDefaultCACertificates([...current, ...adding]);
|
|
164
|
+
for (const pem of missing)
|
|
165
|
+
handled.add(pem);
|
|
166
|
+
for (const pem of adding)
|
|
167
|
+
added.set(pem, new X509Certificate(pem));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Take certificates this module added back out of the default CA list once
|
|
171
|
+
* they are out of date, leaving every other entry as it is. Runs on each
|
|
172
|
+
* {@link ensureTrustedCa} call; hosts run a tool per process or restart far
|
|
173
|
+
* more often than an intermediate lives, so no timer is kept for it.
|
|
174
|
+
*/
|
|
175
|
+
function pruneOutOfDate(now) {
|
|
176
|
+
const stale = [...added].filter(([, cert]) => !validAt(cert, now));
|
|
177
|
+
if (stale.length === 0)
|
|
178
|
+
return;
|
|
179
|
+
const drop = new Set(stale.map(([, cert]) => cert.fingerprint256));
|
|
180
|
+
tls.setDefaultCACertificates(tls.getCACertificates('default').filter((pem) => !drop.has(fingerprint(pem))));
|
|
181
|
+
for (const [pem] of stale) {
|
|
182
|
+
added.delete(pem);
|
|
183
|
+
handled.delete(pem);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** Test hook: forget what {@link ensureTrustedCa} did. Does not touch Node's CA list. */
|
|
187
|
+
export function resetTrustedCaForTests() {
|
|
188
|
+
handled.clear();
|
|
189
|
+
added.clear();
|
|
190
|
+
}
|
|
@@ -17,6 +17,9 @@ export declare function isAkaiConnection(x: unknown): x is ConnectionDef;
|
|
|
17
17
|
*
|
|
18
18
|
* CLIs link to a connection through `defineCLI({ connectionSlug: <slug> })` —
|
|
19
19
|
* `defineCLI` is unchanged.
|
|
20
|
+
*
|
|
21
|
+
* A connection that sets `mcpServer` instead stands for a hosted MCP server: it has
|
|
22
|
+
* no CLIs, no static OAuth client and no secrets (see {@link ConnectionSpec.mcpServer}).
|
|
20
23
|
*/
|
|
21
24
|
export declare function defineConnection(spec: ConnectionSpec): ConnectionDef;
|
|
22
25
|
//# sourceMappingURL=define-connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-connection.d.ts","sourceRoot":"","sources":["../src/define-connection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EAEb,cAAc,EAGf,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"define-connection.d.ts","sourceRoot":"","sources":["../src/define-connection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EAEb,cAAc,EAGf,MAAM,YAAY,CAAC;AAsSpB,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa,CAE/D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,aAAa,CAmFpE"}
|
|
@@ -155,9 +155,45 @@ const ConnectionSpecShape = z
|
|
|
155
155
|
oauth: ConnectionOAuthConfigShape.optional(),
|
|
156
156
|
jwtRefresh: JwtRefreshShape.optional(),
|
|
157
157
|
nativeBuiltin: z.boolean({ error: 'nativeBuiltin must be a boolean if provided' }).optional(),
|
|
158
|
+
mcpServer: z
|
|
159
|
+
.object({ url: UrlString }, { error: 'mcpServer must be an object with a url if provided' })
|
|
160
|
+
.optional(),
|
|
158
161
|
override: z.boolean({ error: 'override must be a boolean if provided' }).optional(),
|
|
159
162
|
})
|
|
160
163
|
.superRefine((spec, ctx) => {
|
|
164
|
+
// A hosted MCP server authenticates through the server's own OAuth (discovered + dynamically
|
|
165
|
+
// registered by the host at connect time) or not at all. It carries no static OAuth client and
|
|
166
|
+
// no credentials of its own, so every credential-shaped field is forbidden. Checked first (and
|
|
167
|
+
// returning early) so the surfaced issue names the mcpServer conflict, not a downstream rule.
|
|
168
|
+
if (spec.mcpServer) {
|
|
169
|
+
if (spec.authKind === 'apiKey') {
|
|
170
|
+
ctx.addIssue({
|
|
171
|
+
code: 'custom',
|
|
172
|
+
path: ['authKind'],
|
|
173
|
+
message: "authKind 'apiKey' is not supported with mcpServer yet (use 'oauth2' or 'none')",
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (spec.oauth !== undefined) {
|
|
177
|
+
ctx.addIssue({
|
|
178
|
+
code: 'custom',
|
|
179
|
+
path: ['oauth'],
|
|
180
|
+
message: 'oauth must not be set with mcpServer (the host discovers the server OAuth metadata and registers dynamically)',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (spec.secrets !== undefined && spec.secrets.length > 0) {
|
|
184
|
+
ctx.addIssue({ code: 'custom', path: ['secrets'], message: 'secrets must not be set with mcpServer' });
|
|
185
|
+
}
|
|
186
|
+
if (spec.apiKeyHeader !== undefined) {
|
|
187
|
+
ctx.addIssue({ code: 'custom', path: ['apiKeyHeader'], message: 'apiKeyHeader must not be set with mcpServer' });
|
|
188
|
+
}
|
|
189
|
+
if (spec.jwtRefresh !== undefined) {
|
|
190
|
+
ctx.addIssue({ code: 'custom', path: ['jwtRefresh'], message: 'jwtRefresh must not be set with mcpServer' });
|
|
191
|
+
}
|
|
192
|
+
if (spec.nativeBuiltin === true) {
|
|
193
|
+
ctx.addIssue({ code: 'custom', path: ['nativeBuiltin'], message: 'nativeBuiltin must not be true with mcpServer' });
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
161
197
|
if (spec.secrets) {
|
|
162
198
|
const seen = new Set();
|
|
163
199
|
for (const s of spec.secrets) {
|
|
@@ -262,6 +298,9 @@ export function isAkaiConnection(x) {
|
|
|
262
298
|
*
|
|
263
299
|
* CLIs link to a connection through `defineCLI({ connectionSlug: <slug> })` —
|
|
264
300
|
* `defineCLI` is unchanged.
|
|
301
|
+
*
|
|
302
|
+
* A connection that sets `mcpServer` instead stands for a hosted MCP server: it has
|
|
303
|
+
* no CLIs, no static OAuth client and no secrets (see {@link ConnectionSpec.mcpServer}).
|
|
265
304
|
*/
|
|
266
305
|
export function defineConnection(spec) {
|
|
267
306
|
const parsed = ConnectionSpecShape.safeParse(spec);
|
|
@@ -332,6 +371,7 @@ export function defineConnection(spec) {
|
|
|
332
371
|
}
|
|
333
372
|
: {}),
|
|
334
373
|
...(v.nativeBuiltin !== undefined ? { nativeBuiltin: v.nativeBuiltin } : {}),
|
|
374
|
+
...(v.mcpServer !== undefined ? { mcpServer: Object.freeze({ url: v.mcpServer.url }) } : {}),
|
|
335
375
|
...(v.override !== undefined ? { override: v.override } : {}),
|
|
336
376
|
};
|
|
337
377
|
Object.freeze(def);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { buildCtx } from './ctx/build-ctx.js';
|
|
|
8
8
|
export type { BuildCtxParams } from './ctx/build-ctx.js';
|
|
9
9
|
export { createSafeFetch } from './ctx/safe-fetch.js';
|
|
10
10
|
export type { SafeFetch, SafeFetchBinding } from './ctx/safe-fetch.js';
|
|
11
|
+
export type { PrivateEgressPin } from './ctx/private-egress.js';
|
|
11
12
|
export type { AnyToolDef, CLIDef, CLISpec, ClientCertOptions, ConnectionAuthKind, ConnectionDef, ConnectionOAuthConfig, ConnectionSpec, DynamicEgress, InputOf, NetworkOptions, OAuthAdminField, OutputOf, PropertiesOf, PropertyDecl, RefreshStrategy, SecretDecl, SecretsOf, StepFetcher, TokenEndpointAuthMethod, ToolCtx, ToolDef, ToolLogger, ToolOptions, ToolSpec, } from './types.js';
|
|
12
13
|
export { createSafePath } from './ctx/safe-path.js';
|
|
13
14
|
export type { SafePath } from './ctx/safe-path.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EACV,UAAU,EACV,MAAM,EACN,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,OAAO,EACP,cAAc,EACd,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,UAAU,EACV,SAAS,EACT,WAAW,EACX,uBAAuB,EACvB,OAAO,EACP,OAAO,EACP,UAAU,EACV,WAAW,EACX,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,EACf,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,+BAA+B,EAC/B,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EACV,UAAU,EACV,MAAM,EACN,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,OAAO,EACP,cAAc,EACd,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,UAAU,EACV,SAAS,EACT,WAAW,EACX,uBAAuB,EACvB,OAAO,EACP,OAAO,EACP,UAAU,EACV,WAAW,EACX,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,EACf,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,+BAA+B,EAC/B,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ConnectionManifest } from './types.js';
|
|
3
|
+
/** True when `val` parses as a URL with the `https:` protocol. Shared with the registry loader. */
|
|
4
|
+
export declare function isHttpsUrl(val: string): boolean;
|
|
3
5
|
/**
|
|
4
6
|
* Cross-check for dynamic-egress references. Mirrors the invariant
|
|
5
7
|
* `defineCLI()` enforces at spec time:
|
|
@@ -118,6 +120,9 @@ export declare const ConnectionManifestSchema: z.ZodObject<{
|
|
|
118
120
|
claimTtlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
119
121
|
}, z.core.$strip>>;
|
|
120
122
|
nativeBuiltin: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
+
mcpServer: z.ZodOptional<z.ZodObject<{
|
|
124
|
+
url: z.ZodString;
|
|
125
|
+
}, z.core.$strip>>;
|
|
121
126
|
override: z.ZodOptional<z.ZodBoolean>;
|
|
122
127
|
}, z.core.$strip>>;
|
|
123
128
|
tools: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/manifest/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/manifest/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAmLrD,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAM/C;AAmGD;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiFnC,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAAsD,CAAC;AAExF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAE/D"}
|
|
@@ -162,6 +162,15 @@ const ManifestJwtRefreshSchema = z.object({
|
|
|
162
162
|
revocationBackoffMs: z.number().int().positive().optional(),
|
|
163
163
|
claimTtlSeconds: z.number().int().positive().optional(),
|
|
164
164
|
});
|
|
165
|
+
/** True when `val` parses as a URL with the `https:` protocol. Shared with the registry loader. */
|
|
166
|
+
export function isHttpsUrl(val) {
|
|
167
|
+
try {
|
|
168
|
+
return new URL(val).protocol === 'https:';
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
165
174
|
const ManifestConnectionSchema = z
|
|
166
175
|
.object({
|
|
167
176
|
slug: z.string().regex(CONNECTION_SLUG_RE),
|
|
@@ -183,9 +192,36 @@ const ManifestConnectionSchema = z
|
|
|
183
192
|
oauth: ManifestConnectionOAuthSchema.optional(),
|
|
184
193
|
jwtRefresh: ManifestJwtRefreshSchema.optional(),
|
|
185
194
|
nativeBuiltin: z.boolean().optional(),
|
|
195
|
+
mcpServer: z.object({ url: z.string() }).optional(),
|
|
186
196
|
override: z.boolean().optional(),
|
|
187
197
|
})
|
|
188
198
|
.superRefine((c, ctx) => {
|
|
199
|
+
// A hosted MCP server connection (mirrors defineConnection): https url, auth via the server's
|
|
200
|
+
// own discovered OAuth or none, and no credential-shaped field of its own.
|
|
201
|
+
if (c.mcpServer !== undefined) {
|
|
202
|
+
if (!isHttpsUrl(c.mcpServer.url)) {
|
|
203
|
+
ctx.addIssue({ code: 'custom', path: ['mcpServer', 'url'], message: 'must be an https URL' });
|
|
204
|
+
}
|
|
205
|
+
if (c.authKind === 'apiKey') {
|
|
206
|
+
ctx.addIssue({ code: 'custom', path: ['authKind'], message: "authKind 'apiKey' is not supported with mcpServer" });
|
|
207
|
+
}
|
|
208
|
+
if (c.oauth !== undefined) {
|
|
209
|
+
ctx.addIssue({ code: 'custom', path: ['oauth'], message: 'oauth must not be set with mcpServer' });
|
|
210
|
+
}
|
|
211
|
+
if (c.secrets !== undefined && c.secrets.length > 0) {
|
|
212
|
+
ctx.addIssue({ code: 'custom', path: ['secrets'], message: 'secrets must not be set with mcpServer' });
|
|
213
|
+
}
|
|
214
|
+
if (c.apiKeyHeader !== undefined) {
|
|
215
|
+
ctx.addIssue({ code: 'custom', path: ['apiKeyHeader'], message: 'apiKeyHeader must not be set with mcpServer' });
|
|
216
|
+
}
|
|
217
|
+
if (c.jwtRefresh !== undefined) {
|
|
218
|
+
ctx.addIssue({ code: 'custom', path: ['jwtRefresh'], message: 'jwtRefresh must not be set with mcpServer' });
|
|
219
|
+
}
|
|
220
|
+
if (c.nativeBuiltin === true) {
|
|
221
|
+
ctx.addIssue({ code: 'custom', path: ['nativeBuiltin'], message: 'nativeBuiltin must not be true with mcpServer' });
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
189
225
|
// Mirror the defineConnection invariants so an embed that would project a
|
|
190
226
|
// nonsensical wire shape degrades to eager rather than validating: oauth is
|
|
191
227
|
// required for oauth2 and forbidden otherwise; jwtRefresh is the non-oauth2
|