@stigmer/outbound 3.40.1 → 3.41.1-dev.20261003094357.g39d6aa748646
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/address.js +7 -3
- package/egress/address.js.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/mcp-oauth/metadata.d.ts.map +1 -1
- package/mcp-oauth/metadata.js +3 -2
- package/mcp-oauth/metadata.js.map +1 -1
- package/package.json +1 -1
- package/src/egress/address.ts +10 -5
- package/src/egress/check.ts +64 -13
- package/src/egress/index.ts +1 -0
- package/src/mcp-oauth/metadata.ts +3 -2
- package/src/trim.ts +10 -0
- package/trim.d.ts +7 -0
- package/trim.d.ts.map +1 -0
- package/trim.js +12 -0
- package/trim.js.map +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/address.js
CHANGED
|
@@ -104,15 +104,19 @@ function blockedReasonV6(groups, posture) {
|
|
|
104
104
|
return "private (unique local)";
|
|
105
105
|
return null;
|
|
106
106
|
}
|
|
107
|
+
/** A dotted IPv4 address, matched against a whole candidate string. */
|
|
108
|
+
const DOTTED_QUAD = /^\d+\.\d+\.\d+\.\d+$/;
|
|
107
109
|
/**
|
|
108
110
|
* Expand an IPv6 address (already validated by isIP) into its 8 groups.
|
|
109
111
|
* Handles `::` compression, a trailing dotted-IPv4 tail, and zone suffixes.
|
|
110
112
|
*/
|
|
111
113
|
function expandV6(address) {
|
|
112
114
|
let text = address.toLowerCase().split("%")[0] ?? "";
|
|
113
|
-
// Convert a dotted-IPv4 tail (for example ::ffff:127.0.0.1) into two hex
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
// Convert a dotted-IPv4 tail (for example ::ffff:127.0.0.1) into two hex
|
|
116
|
+
// groups. The tail is the text after the last colon, matched whole: an
|
|
117
|
+
// unanchored search for it would retry at every position of the address.
|
|
118
|
+
const lastGroup = text.slice(text.lastIndexOf(":") + 1);
|
|
119
|
+
const tail4 = DOTTED_QUAD.test(lastGroup) ? lastGroup : undefined;
|
|
116
120
|
if (tail4 !== undefined) {
|
|
117
121
|
const octets = tail4.split(".").map(Number);
|
|
118
122
|
if (octets.length !== 4 || octets.some((o) => o > 255))
|
package/egress/address.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/egress/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAkBhC,wEAAwE;AACxE,MAAM,UAAU,sBAAsB,CAAC,OAAsB;IAC3D,OAAO;QACL,IAAI,EAAE,OAAO;QACb,aAAa,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC;KAC5D,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,OAAsB;IACnE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAE7B,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM;YAAE,OAAO,cAAc,CAAC;QAEnC,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,6DAA6D;IAC7D,OAAO,cAAc,CAAC;AACxB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CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gFAAgF;AAChF,SAAS,eAAe,CAAC,MAAyB;IAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;IAClF,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC1B,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC1B,OAAO,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;AAC3D,CAAC"}
|
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,CA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AC;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;CAClD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAuB9D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAgB1E;AAYD,2DAA2D;AAC3D,qBAAa,WAAY,SAAQ,KAAK;IACxB,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,gCA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C,CAAC;IACD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC/B,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9B,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/mcp-oauth/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM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QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,mBAAmB;IACnB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,yEAAyE;AACzE,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,GAAG,GAAG,SAAS,MAAM,EAAE,CAI9E;AAED,iHAAiH;AACjH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,GAAG,GAAG,SAAS,MAAM,EAAE,CAS9E;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,CAAA;CAAE,CAAC,CAUjG;AAED,wFAAwF;AACxF,wBAAsB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAiCnH"}
|
package/mcp-oauth/metadata.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { trimTrailing } from "../trim.js";
|
|
1
2
|
/** The RFC 9728 documents describing a resource, most specific first. */
|
|
2
3
|
export function protectedResourceMetadataUrls(resource) {
|
|
3
4
|
const bare = `${resource.origin}/.well-known/oauth-protected-resource`;
|
|
4
|
-
const path = resource.pathname
|
|
5
|
+
const path = trimTrailing(resource.pathname, "/");
|
|
5
6
|
return path === "" ? [bare] : [`${bare}${path}`, bare];
|
|
6
7
|
}
|
|
7
8
|
/** The documents describing an issuer, RFC 8414 (path inserted, then origin) then OpenID (path, then origin). */
|
|
8
9
|
export function authorizationServerMetadataUrls(issuer) {
|
|
9
|
-
const path = issuer.pathname
|
|
10
|
+
const path = trimTrailing(issuer.pathname, "/");
|
|
10
11
|
const urls = [
|
|
11
12
|
...(path === "" ? [] : [`${issuer.origin}/.well-known/oauth-authorization-server${path}`]),
|
|
12
13
|
`${issuer.origin}/.well-known/oauth-authorization-server`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/mcp-oauth/metadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/mcp-oauth/metadata.ts"],"names":[],"mappings":"AAoCA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkC1C,yEAAyE;AACzE,MAAM,UAAU,6BAA6B,CAAC,QAAa;IACzD,MAAM,IAAI,GAAG,GAAG,QAAQ,CAAC,MAAM,uCAAuC,CAAC;IACvE,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAClD,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,+BAA+B,CAAC,MAAW;IACzD,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG;QACX,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,0CAA0C,IAAI,EAAE,CAAC,CAAC;QAC1F,GAAG,MAAM,CAAC,MAAM,yCAAyC;QACzD,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,mCAAmC,CAAC,CAAC;QACpF,GAAG,MAAM,CAAC,MAAM,mCAAmC;KACpD,CAAC;IACF,OAAO,CAAC,GAAG,IAA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AAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpG,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigmer/outbound",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.41.1-dev.20261003094357.g39d6aa748646",
|
|
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
|
}
|
|
@@ -123,6 +123,9 @@ function blockedReasonV6(groups: readonly number[], posture: EgressPosture): str
|
|
|
123
123
|
return null;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/** A dotted IPv4 address, matched against a whole candidate string. */
|
|
127
|
+
const DOTTED_QUAD = /^\d+\.\d+\.\d+\.\d+$/;
|
|
128
|
+
|
|
126
129
|
/**
|
|
127
130
|
* Expand an IPv6 address (already validated by isIP) into its 8 groups.
|
|
128
131
|
* Handles `::` compression, a trailing dotted-IPv4 tail, and zone suffixes.
|
|
@@ -130,9 +133,11 @@ function blockedReasonV6(groups: readonly number[], posture: EgressPosture): str
|
|
|
130
133
|
function expandV6(address: string): number[] | null {
|
|
131
134
|
let text = address.toLowerCase().split("%")[0] ?? "";
|
|
132
135
|
|
|
133
|
-
// Convert a dotted-IPv4 tail (for example ::ffff:127.0.0.1) into two hex
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
// Convert a dotted-IPv4 tail (for example ::ffff:127.0.0.1) into two hex
|
|
137
|
+
// groups. The tail is the text after the last colon, matched whole: an
|
|
138
|
+
// unanchored search for it would retry at every position of the address.
|
|
139
|
+
const lastGroup = text.slice(text.lastIndexOf(":") + 1);
|
|
140
|
+
const tail4 = DOTTED_QUAD.test(lastGroup) ? lastGroup : undefined;
|
|
136
141
|
if (tail4 !== undefined) {
|
|
137
142
|
const octets = tail4.split(".").map(Number);
|
|
138
143
|
if (octets.length !== 4 || octets.some((o) => o > 255)) return null;
|
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);
|
package/src/egress/index.ts
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
* Proven by __tests__/metadata.test.ts.
|
|
35
35
|
*/
|
|
36
36
|
import type { OutboundFetch } from "../egress/fetch.js";
|
|
37
|
+
import { trimTrailing } from "../trim.js";
|
|
37
38
|
|
|
38
39
|
/** RFC 8414 metadata in the fields Sign in reads; snake_case on the wire, camelCase here. */
|
|
39
40
|
export interface AuthorizationServerMetadata {
|
|
@@ -70,13 +71,13 @@ export interface MetadataReadDeps {
|
|
|
70
71
|
/** The RFC 9728 documents describing a resource, most specific first. */
|
|
71
72
|
export function protectedResourceMetadataUrls(resource: URL): readonly string[] {
|
|
72
73
|
const bare = `${resource.origin}/.well-known/oauth-protected-resource`;
|
|
73
|
-
const path = resource.pathname
|
|
74
|
+
const path = trimTrailing(resource.pathname, "/");
|
|
74
75
|
return path === "" ? [bare] : [`${bare}${path}`, bare];
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/** The documents describing an issuer, RFC 8414 (path inserted, then origin) then OpenID (path, then origin). */
|
|
78
79
|
export function authorizationServerMetadataUrls(issuer: URL): readonly string[] {
|
|
79
|
-
const path = issuer.pathname
|
|
80
|
+
const path = trimTrailing(issuer.pathname, "/");
|
|
80
81
|
const urls = [
|
|
81
82
|
...(path === "" ? [] : [`${issuer.origin}/.well-known/oauth-authorization-server${path}`]),
|
|
82
83
|
`${issuer.origin}/.well-known/oauth-authorization-server`,
|
package/src/trim.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `value` without its trailing run of `char`. A `/x+$/` regex rescans the run
|
|
3
|
+
* from every starting position, so a long run costs quadratic time; this walks
|
|
4
|
+
* it once.
|
|
5
|
+
*/
|
|
6
|
+
export function trimTrailing(value: string, char: string): string {
|
|
7
|
+
let end = value.length;
|
|
8
|
+
while (end > 0 && value[end - 1] === char) end -= 1;
|
|
9
|
+
return end === value.length ? value : value.slice(0, end);
|
|
10
|
+
}
|
package/trim.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `value` without its trailing run of `char`. A `/x+$/` regex rescans the run
|
|
3
|
+
* from every starting position, so a long run costs quadratic time; this walks
|
|
4
|
+
* it once.
|
|
5
|
+
*/
|
|
6
|
+
export declare function trimTrailing(value: string, char: string): string;
|
|
7
|
+
//# sourceMappingURL=trim.d.ts.map
|
package/trim.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["src/trim.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIhE"}
|
package/trim.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `value` without its trailing run of `char`. A `/x+$/` regex rescans the run
|
|
3
|
+
* from every starting position, so a long run costs quadratic time; this walks
|
|
4
|
+
* it once.
|
|
5
|
+
*/
|
|
6
|
+
export function trimTrailing(value, char) {
|
|
7
|
+
let end = value.length;
|
|
8
|
+
while (end > 0 && value[end - 1] === char)
|
|
9
|
+
end -= 1;
|
|
10
|
+
return end === value.length ? value : value.slice(0, end);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=trim.js.map
|
package/trim.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.js","sourceRoot":"","sources":["src/trim.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,IAAY;IACtD,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI;QAAE,GAAG,IAAI,CAAC,CAAC;IACpD,OAAO,GAAG,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC"}
|