@stigmer/outbound 3.40.0 → 3.41.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/egress/address.d.ts +2 -2
- package/egress/address.d.ts.map +1 -1
- package/egress/check.d.ts +14 -3
- package/egress/check.d.ts.map +1 -1
- package/egress/check.js +58 -10
- package/egress/check.js.map +1 -1
- package/egress/index.d.ts +1 -1
- package/egress/index.d.ts.map +1 -1
- package/egress/index.js +1 -1
- package/egress/index.js.map +1 -1
- package/package.json +1 -1
- package/src/egress/address.ts +2 -2
- package/src/egress/check.ts +64 -13
- package/src/egress/index.ts +1 -0
package/egress/address.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export type EgressPosture = "strict" | "relaxed";
|
|
|
7
7
|
* would need a network or a hostname to answer is a different seam.
|
|
8
8
|
*/
|
|
9
9
|
export interface EgressPolicy {
|
|
10
|
-
/** The posture
|
|
11
|
-
readonly name:
|
|
10
|
+
/** The posture it judges under: for logs, and for how much a refusal's sentence may say. */
|
|
11
|
+
readonly name: EgressPosture;
|
|
12
12
|
/** A human-readable range name when the address is refused, null when allowed. */
|
|
13
13
|
blockedReason(address: string): string | null;
|
|
14
14
|
}
|
package/egress/address.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/egress/address.ts"],"names":[],"mappings":"AAkCA,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/egress/address.ts"],"names":[],"mappings":"AAkCA,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,kFAAkF;IAClF,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC/C;AAED,wEAAwE;AACxE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAK3E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAoBpF"}
|
package/egress/check.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EgressPolicy } from "./address.js";
|
|
1
|
+
import type { EgressPolicy, EgressPosture } from "./address.js";
|
|
2
2
|
/** Resolve a hostname to every address it has; rejects when it has none. */
|
|
3
3
|
export type LookupFn = (hostname: string) => Promise<readonly string[]>;
|
|
4
4
|
/** Why a URL was refused; one shape per cause, each carrying what a sentence needs. */
|
|
@@ -13,13 +13,14 @@ export type EgressRefusal = {
|
|
|
13
13
|
readonly kind: "unresolvable";
|
|
14
14
|
readonly url: URL;
|
|
15
15
|
readonly hostname: string;
|
|
16
|
+
readonly policy: EgressPosture;
|
|
16
17
|
} | {
|
|
17
18
|
readonly kind: "blocked";
|
|
18
19
|
readonly url: URL;
|
|
19
20
|
readonly hostname: string;
|
|
20
21
|
readonly address: string;
|
|
21
22
|
readonly reason: string;
|
|
22
|
-
readonly policy:
|
|
23
|
+
readonly policy: EgressPosture;
|
|
23
24
|
} | {
|
|
24
25
|
readonly kind: "too-many-redirects";
|
|
25
26
|
readonly url: URL;
|
|
@@ -42,8 +43,18 @@ export interface EgressCheckOptions {
|
|
|
42
43
|
/** Bounds the resolution; an abort propagates as the signal's reason. */
|
|
43
44
|
readonly signal?: AbortSignal | null | undefined;
|
|
44
45
|
}
|
|
45
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* One sentence per refusal, safe to show a user or a model: under the strict
|
|
48
|
+
* posture an unresolvable name and a refused address read alike (the module
|
|
49
|
+
* header says why).
|
|
50
|
+
*/
|
|
46
51
|
export declare function describeRefusal(refusal: EgressRefusal): string;
|
|
52
|
+
/**
|
|
53
|
+
* Whether a refusal's sentence must withhold what resolution found: a strict
|
|
54
|
+
* refusal of a name (unresolvable, or resolved to a refused address). Every
|
|
55
|
+
* caller that renders its own sentence asks this, so the rule has one home.
|
|
56
|
+
*/
|
|
57
|
+
export declare function refusalWithholdsResolution(refusal: EgressRefusal): boolean;
|
|
47
58
|
/** A refusal as a throwable, for callers that want one. */
|
|
48
59
|
export declare class EgressError extends Error {
|
|
49
60
|
readonly refusal: EgressRefusal;
|
package/egress/check.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/egress/check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/egress/check.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEhE,4EAA4E;AAC5E,MAAM,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;AAExE,uFAAuF;AACvF,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnF;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAAE,G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,QAAQ,CAAC,OAAO,EAAE,aAAa;gBAAtB,OAAO,EAAE,aAAa;CAI5C;AAED,uEAAuE;AACvE,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAyB/H"}
|
package/egress/check.js
CHANGED
|
@@ -3,9 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The answer is a value, not a throw, so a caller can render its own
|
|
5
5
|
* sentence (the runner tells a model "this runner does not fetch from", the
|
|
6
|
-
* control plane tells a user
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* control plane tells a user why it will not dial) while the judgement
|
|
7
|
+
* itself has one home. `EgressError` wraps a refusal for the callers that
|
|
8
|
+
* want a throw (the guarded fetch).
|
|
9
|
+
*
|
|
10
|
+
* What a sentence may say depends on the posture. Under strict, the process
|
|
11
|
+
* resolves names through a network the caller does not own (a hosted
|
|
12
|
+
* cluster's DNS), so a sentence that named the address a name resolved to,
|
|
13
|
+
* or told "does not resolve" apart from "resolves to a refused address",
|
|
14
|
+
* would answer whether an internal hostname exists and where it points. A
|
|
15
|
+
* strict refusal of either kind reads as one sentence that names neither;
|
|
16
|
+
* the refusal value keeps the address and the reason for the caller's log.
|
|
17
|
+
* A literal IP host resolved nothing and is the caller's own input, so its
|
|
18
|
+
* refusal still names the range it falls in.
|
|
19
|
+
* Under relaxed the network is the operator's own, and the detail is theirs.
|
|
9
20
|
*
|
|
10
21
|
* The check resolves the hostname and judges EVERY address it resolves to:
|
|
11
22
|
* a name with one public and one private record must be refused, or the
|
|
@@ -26,7 +37,11 @@
|
|
|
26
37
|
* Proven by __tests__/check.test.ts.
|
|
27
38
|
*/
|
|
28
39
|
import { isIP } from "node:net";
|
|
29
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* One sentence per refusal, safe to show a user or a model: under the strict
|
|
42
|
+
* posture an unresolvable name and a refused address read alike (the module
|
|
43
|
+
* header says why).
|
|
44
|
+
*/
|
|
30
45
|
export function describeRefusal(refusal) {
|
|
31
46
|
switch (refusal.kind) {
|
|
32
47
|
case "invalid-url":
|
|
@@ -34,9 +49,13 @@ export function describeRefusal(refusal) {
|
|
|
34
49
|
case "unsupported-scheme":
|
|
35
50
|
return `Unsupported URL scheme "${refusal.scheme}": only http and https are allowed.`;
|
|
36
51
|
case "unresolvable":
|
|
37
|
-
return
|
|
52
|
+
return refusalWithholdsResolution(refusal)
|
|
53
|
+
? noPublicAddress(refusal.hostname)
|
|
54
|
+
: `Could not resolve hostname: ${refusal.hostname}`;
|
|
38
55
|
case "blocked":
|
|
39
|
-
return
|
|
56
|
+
return refusalWithholdsResolution(refusal)
|
|
57
|
+
? noPublicAddress(refusal.hostname)
|
|
58
|
+
: `Refusing to reach ${refusal.hostname}: it resolves to ${refusal.address}, a ${refusal.reason} address the ${refusal.policy} egress policy does not dial.`;
|
|
40
59
|
case "too-many-redirects":
|
|
41
60
|
return `Refusing to follow more than ${refusal.hops} redirects from ${refusal.url.href}.`;
|
|
42
61
|
case "response-too-large":
|
|
@@ -47,6 +66,36 @@ export function describeRefusal(refusal) {
|
|
|
47
66
|
}
|
|
48
67
|
}
|
|
49
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether a refusal's sentence must withhold what resolution found: a strict
|
|
71
|
+
* refusal of a name (unresolvable, or resolved to a refused address). Every
|
|
72
|
+
* caller that renders its own sentence asks this, so the rule has one home.
|
|
73
|
+
*/
|
|
74
|
+
export function refusalWithholdsResolution(refusal) {
|
|
75
|
+
switch (refusal.kind) {
|
|
76
|
+
case "unresolvable":
|
|
77
|
+
return refusal.policy === "strict";
|
|
78
|
+
case "blocked":
|
|
79
|
+
return refusal.policy === "strict" && !isLiteralHost(refusal.hostname);
|
|
80
|
+
case "invalid-url":
|
|
81
|
+
case "unsupported-scheme":
|
|
82
|
+
case "too-many-redirects":
|
|
83
|
+
case "response-too-large":
|
|
84
|
+
return false;
|
|
85
|
+
default: {
|
|
86
|
+
const exhaustive = refusal;
|
|
87
|
+
return exhaustive;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The strict posture's one sentence for a name it will not dial: true of both causes, naming neither. */
|
|
92
|
+
function noPublicAddress(hostname) {
|
|
93
|
+
return `Refusing to reach ${hostname}: it does not resolve to a public address.`;
|
|
94
|
+
}
|
|
95
|
+
/** Whether a URL's host is an IP literal (a bracketed IPv6 host arrives from URL.hostname still bracketed). */
|
|
96
|
+
function isLiteralHost(hostname) {
|
|
97
|
+
return isIP(hostname.replace(/^\[|\]$/g, "")) !== 0;
|
|
98
|
+
}
|
|
50
99
|
/** A refusal as a throwable, for callers that want one. */
|
|
51
100
|
export class EgressError extends Error {
|
|
52
101
|
refusal;
|
|
@@ -70,7 +119,7 @@ export async function checkEgress(rawUrl, policy, options) {
|
|
|
70
119
|
}
|
|
71
120
|
const addresses = await resolveAddresses(url.hostname, options);
|
|
72
121
|
if (addresses === undefined) {
|
|
73
|
-
return { ok: false, refusal: { kind: "unresolvable", url, hostname: url.hostname } };
|
|
122
|
+
return { ok: false, refusal: { kind: "unresolvable", url, hostname: url.hostname, policy: policy.name } };
|
|
74
123
|
}
|
|
75
124
|
for (const address of addresses) {
|
|
76
125
|
const reason = policy.blockedReason(address);
|
|
@@ -86,9 +135,8 @@ export async function checkEgress(rawUrl, policy, options) {
|
|
|
86
135
|
* does not resolve; an aborted signal throws its reason.
|
|
87
136
|
*/
|
|
88
137
|
async function resolveAddresses(hostname, options) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return [literal];
|
|
138
|
+
if (isLiteralHost(hostname)) {
|
|
139
|
+
return [hostname.replace(/^\[|\]$/g, "")];
|
|
92
140
|
}
|
|
93
141
|
try {
|
|
94
142
|
const records = await raceSignal(options.lookup(hostname), options.signal);
|
package/egress/check.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/egress/check.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/egress/check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAiChC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAAsB;IACpD,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,aAAa;YAChB,OAAO,gBAAgB,OAAO,CAAC,GAAG,EAAE,CAAC;QACvC,KAAK,oBAAoB;YACvB,OAAO,2BAA2B,OAAO,CAAC,MAAM,qCAAqC,CAAC;QACxF,KAAK,cAAc;YACjB,OAAO,0BAA0B,CAAC,OAAO,CAAC;gBACxC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC;gBACnC,CAAC,CAAC,+BAA+B,OAAO,CAAC,QAAQ,EAAE,CAAC;QACxD,KAAK,SAAS;YACZ,OAAO,0BAA0B,CAAC,OAAO,CAAC;gBACxC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC;gBACnC,CAAC,CAAC,qBAAqB,OAAO,CAAC,QAAQ,oBAAoB,OAAO,CAAC,OAAO,OAAO,OAAO,CAAC,MAAM,gBAAgB,OAAO,CAAC,MAAM,+BAA+B,CAAC;QACjK,KAAK,oBAAoB;YACvB,OAAO,gCAAgC,OAAO,CAAC,IAAI,mBAAmB,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;QAC5F,KAAK,oBAAoB;YACvB,OAAO,8BAA8B,OAAO,CAAC,QAAQ,eAAe,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;QAC1F,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,UAAU,GAAU,OAAO,CAAC;YAClC,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC;AAED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,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CACV,CAAC,KAAK,EAAE,EAAE;YACR,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;YACjB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAC;AACvF,CAAC"}
|
package/egress/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* fetch that applies it to every hop. See each module's header.
|
|
5
5
|
*/
|
|
6
6
|
export { blockedReason, egressPolicyForPosture, type EgressPolicy, type EgressPosture } from "./address.js";
|
|
7
|
-
export { checkEgress, describeRefusal, EgressError, type EgressCheck, type EgressCheckOptions, type EgressRefusal, type LookupFn, } from "./check.js";
|
|
7
|
+
export { checkEgress, describeRefusal, EgressError, refusalWithholdsResolution, type EgressCheck, type EgressCheckOptions, type EgressRefusal, type LookupFn, } from "./check.js";
|
|
8
8
|
export { asFetch, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RESPONSE_BYTES, guardedFetch, type GuardedFetchOptions, type OutboundFetch } from "./fetch.js";
|
|
9
9
|
export { nodeLookup } from "./node-lookup.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/egress/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/egress/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,eAAe,EACf,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACpJ,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/egress/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,eAAe,EACf,WAAW,EACX,0BAA0B,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACpJ,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/egress/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* fetch that applies it to every hop. See each module's header.
|
|
5
5
|
*/
|
|
6
6
|
export { blockedReason, egressPolicyForPosture } from "./address.js";
|
|
7
|
-
export { checkEgress, describeRefusal, EgressError, } from "./check.js";
|
|
7
|
+
export { checkEgress, describeRefusal, EgressError, refusalWithholdsResolution, } from "./check.js";
|
|
8
8
|
export { asFetch, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RESPONSE_BYTES, guardedFetch } from "./fetch.js";
|
|
9
9
|
export { nodeLookup } from "./node-lookup.js";
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/egress/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/egress/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAyC,MAAM,cAAc,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,eAAe,EACf,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/egress/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAyC,MAAM,cAAc,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,eAAe,EACf,WAAW,EACX,0BAA0B,GAK3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,YAAY,EAAgD,MAAM,YAAY,CAAC;AACpJ,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigmer/outbound",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.41.0",
|
|
4
4
|
"description": "The rules Stigmer's TypeScript processes dial a user-supplied endpoint by, shared by the control plane, the runner and the catalogue audit: the egress address policy and its guarded fetch, and the way an MCP endpoint's authentication is read (the OAuth-challenge rule, the complete initialize handshake, the RFC 9728 / RFC 8414 / OpenID resolution of its login server)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
package/src/egress/address.ts
CHANGED
|
@@ -42,8 +42,8 @@ export type EgressPosture = "strict" | "relaxed";
|
|
|
42
42
|
* would need a network or a hostname to answer is a different seam.
|
|
43
43
|
*/
|
|
44
44
|
export interface EgressPolicy {
|
|
45
|
-
/** The posture
|
|
46
|
-
readonly name:
|
|
45
|
+
/** The posture it judges under: for logs, and for how much a refusal's sentence may say. */
|
|
46
|
+
readonly name: EgressPosture;
|
|
47
47
|
/** A human-readable range name when the address is refused, null when allowed. */
|
|
48
48
|
blockedReason(address: string): string | null;
|
|
49
49
|
}
|
package/src/egress/check.ts
CHANGED
|
@@ -3,9 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The answer is a value, not a throw, so a caller can render its own
|
|
5
5
|
* sentence (the runner tells a model "this runner does not fetch from", the
|
|
6
|
-
* control plane tells a user
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* control plane tells a user why it will not dial) while the judgement
|
|
7
|
+
* itself has one home. `EgressError` wraps a refusal for the callers that
|
|
8
|
+
* want a throw (the guarded fetch).
|
|
9
|
+
*
|
|
10
|
+
* What a sentence may say depends on the posture. Under strict, the process
|
|
11
|
+
* resolves names through a network the caller does not own (a hosted
|
|
12
|
+
* cluster's DNS), so a sentence that named the address a name resolved to,
|
|
13
|
+
* or told "does not resolve" apart from "resolves to a refused address",
|
|
14
|
+
* would answer whether an internal hostname exists and where it points. A
|
|
15
|
+
* strict refusal of either kind reads as one sentence that names neither;
|
|
16
|
+
* the refusal value keeps the address and the reason for the caller's log.
|
|
17
|
+
* A literal IP host resolved nothing and is the caller's own input, so its
|
|
18
|
+
* refusal still names the range it falls in.
|
|
19
|
+
* Under relaxed the network is the operator's own, and the detail is theirs.
|
|
9
20
|
*
|
|
10
21
|
* The check resolves the hostname and judges EVERY address it resolves to:
|
|
11
22
|
* a name with one public and one private record must be refused, or the
|
|
@@ -27,7 +38,7 @@
|
|
|
27
38
|
*/
|
|
28
39
|
import { isIP } from "node:net";
|
|
29
40
|
|
|
30
|
-
import type { EgressPolicy } from "./address.js";
|
|
41
|
+
import type { EgressPolicy, EgressPosture } from "./address.js";
|
|
31
42
|
|
|
32
43
|
/** Resolve a hostname to every address it has; rejects when it has none. */
|
|
33
44
|
export type LookupFn = (hostname: string) => Promise<readonly string[]>;
|
|
@@ -36,14 +47,14 @@ export type LookupFn = (hostname: string) => Promise<readonly string[]>;
|
|
|
36
47
|
export type EgressRefusal =
|
|
37
48
|
| { readonly kind: "invalid-url"; readonly url: string }
|
|
38
49
|
| { readonly kind: "unsupported-scheme"; readonly url: URL; readonly scheme: string }
|
|
39
|
-
| { readonly kind: "unresolvable"; readonly url: URL; readonly hostname: string }
|
|
50
|
+
| { readonly kind: "unresolvable"; readonly url: URL; readonly hostname: string; readonly policy: EgressPosture }
|
|
40
51
|
| {
|
|
41
52
|
readonly kind: "blocked";
|
|
42
53
|
readonly url: URL;
|
|
43
54
|
readonly hostname: string;
|
|
44
55
|
readonly address: string;
|
|
45
56
|
readonly reason: string;
|
|
46
|
-
readonly policy:
|
|
57
|
+
readonly policy: EgressPosture;
|
|
47
58
|
}
|
|
48
59
|
| { readonly kind: "too-many-redirects"; readonly url: URL; readonly hops: number }
|
|
49
60
|
| { readonly kind: "response-too-large"; readonly url: URL; readonly maxBytes: number };
|
|
@@ -58,7 +69,11 @@ export interface EgressCheckOptions {
|
|
|
58
69
|
readonly signal?: AbortSignal | null | undefined;
|
|
59
70
|
}
|
|
60
71
|
|
|
61
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* One sentence per refusal, safe to show a user or a model: under the strict
|
|
74
|
+
* posture an unresolvable name and a refused address read alike (the module
|
|
75
|
+
* header says why).
|
|
76
|
+
*/
|
|
62
77
|
export function describeRefusal(refusal: EgressRefusal): string {
|
|
63
78
|
switch (refusal.kind) {
|
|
64
79
|
case "invalid-url":
|
|
@@ -66,9 +81,13 @@ export function describeRefusal(refusal: EgressRefusal): string {
|
|
|
66
81
|
case "unsupported-scheme":
|
|
67
82
|
return `Unsupported URL scheme "${refusal.scheme}": only http and https are allowed.`;
|
|
68
83
|
case "unresolvable":
|
|
69
|
-
return
|
|
84
|
+
return refusalWithholdsResolution(refusal)
|
|
85
|
+
? noPublicAddress(refusal.hostname)
|
|
86
|
+
: `Could not resolve hostname: ${refusal.hostname}`;
|
|
70
87
|
case "blocked":
|
|
71
|
-
return
|
|
88
|
+
return refusalWithholdsResolution(refusal)
|
|
89
|
+
? noPublicAddress(refusal.hostname)
|
|
90
|
+
: `Refusing to reach ${refusal.hostname}: it resolves to ${refusal.address}, a ${refusal.reason} address the ${refusal.policy} egress policy does not dial.`;
|
|
72
91
|
case "too-many-redirects":
|
|
73
92
|
return `Refusing to follow more than ${refusal.hops} redirects from ${refusal.url.href}.`;
|
|
74
93
|
case "response-too-large":
|
|
@@ -80,6 +99,39 @@ export function describeRefusal(refusal: EgressRefusal): string {
|
|
|
80
99
|
}
|
|
81
100
|
}
|
|
82
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Whether a refusal's sentence must withhold what resolution found: a strict
|
|
104
|
+
* refusal of a name (unresolvable, or resolved to a refused address). Every
|
|
105
|
+
* caller that renders its own sentence asks this, so the rule has one home.
|
|
106
|
+
*/
|
|
107
|
+
export function refusalWithholdsResolution(refusal: EgressRefusal): boolean {
|
|
108
|
+
switch (refusal.kind) {
|
|
109
|
+
case "unresolvable":
|
|
110
|
+
return refusal.policy === "strict";
|
|
111
|
+
case "blocked":
|
|
112
|
+
return refusal.policy === "strict" && !isLiteralHost(refusal.hostname);
|
|
113
|
+
case "invalid-url":
|
|
114
|
+
case "unsupported-scheme":
|
|
115
|
+
case "too-many-redirects":
|
|
116
|
+
case "response-too-large":
|
|
117
|
+
return false;
|
|
118
|
+
default: {
|
|
119
|
+
const exhaustive: never = refusal;
|
|
120
|
+
return exhaustive;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The strict posture's one sentence for a name it will not dial: true of both causes, naming neither. */
|
|
126
|
+
function noPublicAddress(hostname: string): string {
|
|
127
|
+
return `Refusing to reach ${hostname}: it does not resolve to a public address.`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Whether a URL's host is an IP literal (a bracketed IPv6 host arrives from URL.hostname still bracketed). */
|
|
131
|
+
function isLiteralHost(hostname: string): boolean {
|
|
132
|
+
return isIP(hostname.replace(/^\[|\]$/g, "")) !== 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
83
135
|
/** A refusal as a throwable, for callers that want one. */
|
|
84
136
|
export class EgressError extends Error {
|
|
85
137
|
constructor(readonly refusal: EgressRefusal) {
|
|
@@ -103,7 +155,7 @@ export async function checkEgress(rawUrl: string | URL, policy: EgressPolicy, op
|
|
|
103
155
|
|
|
104
156
|
const addresses = await resolveAddresses(url.hostname, options);
|
|
105
157
|
if (addresses === undefined) {
|
|
106
|
-
return { ok: false, refusal: { kind: "unresolvable", url, hostname: url.hostname } };
|
|
158
|
+
return { ok: false, refusal: { kind: "unresolvable", url, hostname: url.hostname, policy: policy.name } };
|
|
107
159
|
}
|
|
108
160
|
|
|
109
161
|
for (const address of addresses) {
|
|
@@ -122,9 +174,8 @@ export async function checkEgress(rawUrl: string | URL, policy: EgressPolicy, op
|
|
|
122
174
|
* does not resolve; an aborted signal throws its reason.
|
|
123
175
|
*/
|
|
124
176
|
async function resolveAddresses(hostname: string, options: EgressCheckOptions): Promise<readonly string[] | undefined> {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return [literal];
|
|
177
|
+
if (isLiteralHost(hostname)) {
|
|
178
|
+
return [hostname.replace(/^\[|\]$/g, "")];
|
|
128
179
|
}
|
|
129
180
|
try {
|
|
130
181
|
const records = await raceSignal(options.lookup(hostname), options.signal);
|