@stigmer/outbound 0.1.0-dev.20261017020314.g644422724c27
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/LICENSE +194 -0
- package/README.md +23 -0
- package/dial/index.d.ts +10 -0
- package/dial/index.d.ts.map +1 -0
- package/dial/index.js +10 -0
- package/dial/index.js.map +1 -0
- package/dial/pinned-fetch.d.ts +83 -0
- package/dial/pinned-fetch.d.ts.map +1 -0
- package/dial/pinned-fetch.js +204 -0
- package/dial/pinned-fetch.js.map +1 -0
- package/egress/address.d.ts +23 -0
- package/egress/address.d.ts.map +1 -0
- package/egress/address.js +152 -0
- package/egress/address.js.map +1 -0
- package/egress/check.d.ts +78 -0
- package/egress/check.d.ts.map +1 -0
- package/egress/check.js +192 -0
- package/egress/check.js.map +1 -0
- package/egress/fetch.d.ts +67 -0
- package/egress/fetch.d.ts.map +1 -0
- package/egress/fetch.js +92 -0
- package/egress/fetch.js.map +1 -0
- package/egress/index.d.ts +10 -0
- package/egress/index.d.ts.map +1 -0
- package/egress/index.js +10 -0
- package/egress/index.js.map +1 -0
- package/egress/node-lookup.d.ts +4 -0
- package/egress/node-lookup.d.ts.map +1 -0
- package/egress/node-lookup.js +20 -0
- package/egress/node-lookup.js.map +1 -0
- package/index.d.ts +11 -0
- package/index.d.ts.map +1 -0
- package/index.js +11 -0
- package/index.js.map +1 -0
- package/mcp-oauth/challenge.d.ts +25 -0
- package/mcp-oauth/challenge.d.ts.map +1 -0
- package/mcp-oauth/challenge.js +33 -0
- package/mcp-oauth/challenge.js.map +1 -0
- package/mcp-oauth/index.d.ts +11 -0
- package/mcp-oauth/index.d.ts.map +1 -0
- package/mcp-oauth/index.js +11 -0
- package/mcp-oauth/index.js.map +1 -0
- package/mcp-oauth/metadata.d.ts +107 -0
- package/mcp-oauth/metadata.d.ts.map +1 -0
- package/mcp-oauth/metadata.js +151 -0
- package/mcp-oauth/metadata.js.map +1 -0
- package/mcp-oauth/probe.d.ts +68 -0
- package/mcp-oauth/probe.d.ts.map +1 -0
- package/mcp-oauth/probe.js +35 -0
- package/mcp-oauth/probe.js.map +1 -0
- package/mcp-oauth/request.d.ts +44 -0
- package/mcp-oauth/request.d.ts.map +1 -0
- package/mcp-oauth/request.js +71 -0
- package/mcp-oauth/request.js.map +1 -0
- package/package.json +52 -0
- package/src/dial/index.ts +9 -0
- package/src/dial/pinned-fetch.ts +229 -0
- package/src/egress/address.ts +173 -0
- package/src/egress/check.ts +238 -0
- package/src/egress/fetch.ts +154 -0
- package/src/egress/index.ts +20 -0
- package/src/egress/node-lookup.ts +22 -0
- package/src/index.ts +10 -0
- package/src/mcp-oauth/challenge.ts +33 -0
- package/src/mcp-oauth/index.ts +26 -0
- package/src/mcp-oauth/metadata.ts +248 -0
- package/src/mcp-oauth/probe.ts +91 -0
- package/src/mcp-oauth/request.ts +81 -0
- 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/LICENSE
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Stigmer Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
191
|
+
|
|
192
|
+
Except for the contents of the ee/ directory, which are licensed under the
|
|
193
|
+
Stigmer Enterprise License (see ee/LICENSE), everything in this repository
|
|
194
|
+
is licensed under the Apache License, Version 2.0, above.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @stigmer/outbound
|
|
2
|
+
|
|
3
|
+
The rules a Stigmer process follows when it dials a URL a user supplied, shared by the control plane (`@stigmer/server`), the runner (`@stigmer/runner`) and the catalogue audit (`plugins/scripts/audit`).
|
|
4
|
+
|
|
5
|
+
Three entry points:
|
|
6
|
+
|
|
7
|
+
- `@stigmer/outbound/egress`: which addresses a process refuses to dial (`blockedReason`, two postures, `strict` for managed cloud processes and `relaxed` for a machine that belongs to the user), the check that applies a policy to a URL after resolving every address it has (`checkEgress`), and the fetch that applies it to every redirect hop and bounds every response body (`guardedFetch`). A process composes one guarded fetch at its root and hands it to every module that dials; the modules hold no `fetch` of their own.
|
|
8
|
+
- `@stigmer/outbound/dial`: the pinned dialer (`pinnedFetch`), whose every socket opens to an address the policy judged at connect time, and `nodeGuardedFetch`, the guarded fetch over it that a server composes at its root. The check alone would leave a window: a name can resolve to a public address for the check and a private one for the socket. This entry stands apart because importing it loads undici, which registers itself as the process's dispatcher; a server already carries undici, while a process that does not would change every `fetch` it makes by importing the egress rules.
|
|
9
|
+
- `@stigmer/outbound/mcp-oauth`: how an MCP endpoint's authentication is read without a credential (`isOAuthChallenge`, the complete `initializeRequest`, `probeEndpointAuth`) and how its login server is found (`resolveAuthorizationServers` over RFC 9728, `readAuthorizationServerMetadata` over RFC 8414 with the issuer's path and OpenID's document).
|
|
10
|
+
|
|
11
|
+
## Why one library
|
|
12
|
+
|
|
13
|
+
Each rule here was first written where it was first needed: the address classification in the runner's `web_fetch` guard, the OAuth-challenge rule in the runner's failed-tool-call path, the complete handshake and the metadata walk in the catalogue audit. The control plane then needed all of them at once, to complete a URL-only server's `auth` at save time and to reach login servers on another origin, and a third copy would have let the storefront call OAuth what the runner called a bad token. So the rules moved here and every consumer imports them; the consumers keep only what is theirs (the runner its posture from its mode and its user-facing sentence, the control plane its edition driver point and its pinned validation copy, the audit its evidence and retry).
|
|
14
|
+
|
|
15
|
+
## Shape
|
|
16
|
+
|
|
17
|
+
Pure over injected `fetch` and `lookup`; the Node-bound modules are `egress/node-lookup.ts` and the dialer, `dial/pinned-fetch.ts`, which is the library's one runtime dependency (undici, pinned to the exact version the server already resolves) and its one module with side effects. Every function that can fail on the network returns a value (`EgressCheck`, `EndpointAuthOutcome`, `MetadataRead`) rather than throwing, so a caller renders its own sentence; `EgressError` wraps a refusal for the guarded fetch. `OutboundFetch` is the fetch shape consumers take (`(url: string | URL, init?) => Promise<Response>`); the global `fetch` satisfies it.
|
|
18
|
+
|
|
19
|
+
Published in lockstep with the other `backend/libs/ts` libraries by `scripts/publish-libs.mjs`; the server and runner link it with `file:` and pin the release version at stamp time.
|
|
20
|
+
|
|
21
|
+
## Verify
|
|
22
|
+
|
|
23
|
+
`npm run typecheck && npm test` here. The consumers' suites when a rule changes: `make test-server`, `make test-runner`, `make test-plugins-static`.
|
package/dial/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@stigmer/outbound/dial`: the pinned dialer, whose every socket opens to
|
|
3
|
+
* an address the egress policy judged, and `nodeGuardedFetch`, the guarded
|
|
4
|
+
* fetch over it that a process composes at its root. Importing this entry
|
|
5
|
+
* loads undici, which registers itself as the process's dispatcher; the
|
|
6
|
+
* module header of `pinned-fetch.ts` says why that keeps it off the other
|
|
7
|
+
* entries.
|
|
8
|
+
*/
|
|
9
|
+
export { nodeGuardedFetch, pinnedFetch, type NodeGuardedFetchOptions, type PinnedFetchOptions } from "./pinned-fetch.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/dial/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,KAAK,uBAAuB,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dial/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@stigmer/outbound/dial`: the pinned dialer, whose every socket opens to
|
|
3
|
+
* an address the egress policy judged, and `nodeGuardedFetch`, the guarded
|
|
4
|
+
* fetch over it that a process composes at its root. Importing this entry
|
|
5
|
+
* loads undici, which registers itself as the process's dispatcher; the
|
|
6
|
+
* module header of `pinned-fetch.ts` says why that keeps it off the other
|
|
7
|
+
* entries.
|
|
8
|
+
*/
|
|
9
|
+
export { nodeGuardedFetch, pinnedFetch } from "./pinned-fetch.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/dial/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAyD,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pinned dialer: an `OutboundFetch` whose every socket opens to an
|
|
3
|
+
* address it judged, under the same policy and rule as the egress check.
|
|
4
|
+
*
|
|
5
|
+
* Importing this module loads undici, and undici registers itself as the
|
|
6
|
+
* process's dispatcher on import (the slot Node's built-in `fetch` reads)
|
|
7
|
+
* when nothing registered one first. A Stigmer server process already
|
|
8
|
+
* carries undici from its Kubernetes client, so nothing changes there; a
|
|
9
|
+
* process without it (the runner) would change every `fetch` it makes by
|
|
10
|
+
* importing this. That is why the dialer is its own entry,
|
|
11
|
+
* `@stigmer/outbound/dial`, on neither the root barrel nor `./egress`, and
|
|
12
|
+
* why `package.json` lists it as the library's one module with side effects.
|
|
13
|
+
*
|
|
14
|
+
* Why it exists: the guarded fetch (`../egress/fetch.ts`) checks a URL's
|
|
15
|
+
* addresses and then asks a `fetch` to dial its hostname, which resolves
|
|
16
|
+
* the name again. A name that answers public to the check and private to
|
|
17
|
+
* the socket (DNS rebinding) would reach the address the check refused.
|
|
18
|
+
* Here the resolution that feeds the socket is the judged one: an undici
|
|
19
|
+
* `Agent` whose connector resolves through the injected `LookupFn`, judges
|
|
20
|
+
* every address with `refusedAddress`, and hands the socket only judged
|
|
21
|
+
* addresses. Any refused address refuses the dial, as the check does; a
|
|
22
|
+
* name that resolves to nothing, or a resolver that fails, refuses it as
|
|
23
|
+
* unresolvable. A literal IP host resolves nothing, so the connector judges
|
|
24
|
+
* it as it stands. The connector sits under every connection the Agent
|
|
25
|
+
* makes, so a redirect undici follows itself is judged too. A resolver
|
|
26
|
+
* that hangs is bounded by undici's connect timeout and the request's own
|
|
27
|
+
* signal. TLS is untouched: the lookup decides which IP a socket opens,
|
|
28
|
+
* never the server name, and the certificate is still checked against the
|
|
29
|
+
* URL's host.
|
|
30
|
+
*
|
|
31
|
+
* A connect-time refusal comes back as the same `EgressError` the check
|
|
32
|
+
* throws (`blocked` or `unresolvable`, for the URL this dialer was asked
|
|
33
|
+
* for), so every caller's refusal arm answers a rebinding exactly as a
|
|
34
|
+
* refused name and the strict posture's sentence withholds the address as
|
|
35
|
+
* before. Any other failure (a refused port, a TLS error) stays the
|
|
36
|
+
* platform's `TypeError`.
|
|
37
|
+
*
|
|
38
|
+
* It dials with undici's own `fetch` and Agent, never the platform `fetch`
|
|
39
|
+
* with this Agent as its dispatcher: undici 8 and the undici a Node 22
|
|
40
|
+
* bundles speak different handler interfaces, and the pairing fails at run
|
|
41
|
+
* time. The two `fetch`es do not share request and response types either,
|
|
42
|
+
* so an explicit adapter sits at the boundary. It carries the method,
|
|
43
|
+
* headers, redirect mode and signal, and the bodies this library's callers
|
|
44
|
+
* send (a string, form parameters, bytes); any other body is refused before
|
|
45
|
+
* a connection opens, the way `asFetch` refuses a `Request`. The answer is
|
|
46
|
+
* rebuilt as a platform `Response`.
|
|
47
|
+
*
|
|
48
|
+
* `nodeGuardedFetch` is how a process composes it: the guarded fetch over
|
|
49
|
+
* this dialer, both judging under one policy and one resolver, so the
|
|
50
|
+
* check and the connect cannot disagree by construction.
|
|
51
|
+
*
|
|
52
|
+
* Proven by __tests__/pinned-fetch.test.ts, against a real server.
|
|
53
|
+
*/
|
|
54
|
+
import { type LookupFunction } from "node:net";
|
|
55
|
+
import type { EgressPolicy } from "../egress/address.js";
|
|
56
|
+
import { type LookupFn } from "../egress/check.js";
|
|
57
|
+
import { type OutboundFetch } from "../egress/fetch.js";
|
|
58
|
+
export interface PinnedFetchOptions {
|
|
59
|
+
readonly lookup: LookupFn;
|
|
60
|
+
}
|
|
61
|
+
export interface NodeGuardedFetchOptions {
|
|
62
|
+
/** The dial under the guard; default the pinned dialer. The composition roots' test seam. */
|
|
63
|
+
readonly fetchImpl?: OutboundFetch;
|
|
64
|
+
/** The resolver both the check and the connect use; default the process's own. */
|
|
65
|
+
readonly lookup?: LookupFn;
|
|
66
|
+
/** Hops followed before refusing; the guarded fetch's default when absent. */
|
|
67
|
+
readonly maxRedirects?: number;
|
|
68
|
+
/** Bytes of a response body read before refusing; the guarded fetch's default when absent. */
|
|
69
|
+
readonly maxResponseBytes?: number;
|
|
70
|
+
}
|
|
71
|
+
/** The guarded fetch over the pinned dialer: what a process composes at its root. */
|
|
72
|
+
export declare function nodeGuardedFetch(policy: EgressPolicy, options?: NodeGuardedFetchOptions): OutboundFetch;
|
|
73
|
+
/** A fetch whose every socket opens only to an address `policy` allows, as `lookup` resolved it. */
|
|
74
|
+
export declare function pinnedFetch(policy: EgressPolicy, options: PinnedFetchOptions): OutboundFetch;
|
|
75
|
+
/**
|
|
76
|
+
* A Node lookup that resolves through `lookup`, judges every address, and
|
|
77
|
+
* answers only with judged ones. It honours the options a socket passes:
|
|
78
|
+
* `all` (a list, which `autoSelectFamily` asks for) or one address, and
|
|
79
|
+
* `family` as a filter over the judged list that never widens it. Exported
|
|
80
|
+
* for its tests; a process takes it through `pinnedFetch`.
|
|
81
|
+
*/
|
|
82
|
+
export declare function judgingLookup(policy: EgressPolicy, lookup: LookupFn): LookupFunction;
|
|
83
|
+
//# sourceMappingURL=pinned-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinned-fetch.d.ts","sourceRoot":"","sources":["../src/dial/pinned-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,OAAO,EAAQ,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAIrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAA+B,KAAK,QAAQ,EAAuB,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGtE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3B;AAED,MAAM,WAAW,uBAAuB;IACtC,6FAA6F;IAC7F,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;IACnC,kFAAkF;IAClF,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,8FAA8F;IAC9F,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAiBD,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,uBAA4B,GAAG,aAAa,CAQ3G;AAED,oGAAoG;AACpG,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,kBAAkB,GAAG,aAAa,CAuC5F;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,GAAG,cAAc,CAepF"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pinned dialer: an `OutboundFetch` whose every socket opens to an
|
|
3
|
+
* address it judged, under the same policy and rule as the egress check.
|
|
4
|
+
*
|
|
5
|
+
* Importing this module loads undici, and undici registers itself as the
|
|
6
|
+
* process's dispatcher on import (the slot Node's built-in `fetch` reads)
|
|
7
|
+
* when nothing registered one first. A Stigmer server process already
|
|
8
|
+
* carries undici from its Kubernetes client, so nothing changes there; a
|
|
9
|
+
* process without it (the runner) would change every `fetch` it makes by
|
|
10
|
+
* importing this. That is why the dialer is its own entry,
|
|
11
|
+
* `@stigmer/outbound/dial`, on neither the root barrel nor `./egress`, and
|
|
12
|
+
* why `package.json` lists it as the library's one module with side effects.
|
|
13
|
+
*
|
|
14
|
+
* Why it exists: the guarded fetch (`../egress/fetch.ts`) checks a URL's
|
|
15
|
+
* addresses and then asks a `fetch` to dial its hostname, which resolves
|
|
16
|
+
* the name again. A name that answers public to the check and private to
|
|
17
|
+
* the socket (DNS rebinding) would reach the address the check refused.
|
|
18
|
+
* Here the resolution that feeds the socket is the judged one: an undici
|
|
19
|
+
* `Agent` whose connector resolves through the injected `LookupFn`, judges
|
|
20
|
+
* every address with `refusedAddress`, and hands the socket only judged
|
|
21
|
+
* addresses. Any refused address refuses the dial, as the check does; a
|
|
22
|
+
* name that resolves to nothing, or a resolver that fails, refuses it as
|
|
23
|
+
* unresolvable. A literal IP host resolves nothing, so the connector judges
|
|
24
|
+
* it as it stands. The connector sits under every connection the Agent
|
|
25
|
+
* makes, so a redirect undici follows itself is judged too. A resolver
|
|
26
|
+
* that hangs is bounded by undici's connect timeout and the request's own
|
|
27
|
+
* signal. TLS is untouched: the lookup decides which IP a socket opens,
|
|
28
|
+
* never the server name, and the certificate is still checked against the
|
|
29
|
+
* URL's host.
|
|
30
|
+
*
|
|
31
|
+
* A connect-time refusal comes back as the same `EgressError` the check
|
|
32
|
+
* throws (`blocked` or `unresolvable`, for the URL this dialer was asked
|
|
33
|
+
* for), so every caller's refusal arm answers a rebinding exactly as a
|
|
34
|
+
* refused name and the strict posture's sentence withholds the address as
|
|
35
|
+
* before. Any other failure (a refused port, a TLS error) stays the
|
|
36
|
+
* platform's `TypeError`.
|
|
37
|
+
*
|
|
38
|
+
* It dials with undici's own `fetch` and Agent, never the platform `fetch`
|
|
39
|
+
* with this Agent as its dispatcher: undici 8 and the undici a Node 22
|
|
40
|
+
* bundles speak different handler interfaces, and the pairing fails at run
|
|
41
|
+
* time. The two `fetch`es do not share request and response types either,
|
|
42
|
+
* so an explicit adapter sits at the boundary. It carries the method,
|
|
43
|
+
* headers, redirect mode and signal, and the bodies this library's callers
|
|
44
|
+
* send (a string, form parameters, bytes); any other body is refused before
|
|
45
|
+
* a connection opens, the way `asFetch` refuses a `Request`. The answer is
|
|
46
|
+
* rebuilt as a platform `Response`.
|
|
47
|
+
*
|
|
48
|
+
* `nodeGuardedFetch` is how a process composes it: the guarded fetch over
|
|
49
|
+
* this dialer, both judging under one policy and one resolver, so the
|
|
50
|
+
* check and the connect cannot disagree by construction.
|
|
51
|
+
*
|
|
52
|
+
* Proven by __tests__/pinned-fetch.test.ts, against a real server.
|
|
53
|
+
*/
|
|
54
|
+
import { isIP } from "node:net";
|
|
55
|
+
import { Agent, buildConnector, fetch as undiciFetch } from "undici";
|
|
56
|
+
import { EgressError, refusedAddress } from "../egress/check.js";
|
|
57
|
+
import { guardedFetch } from "../egress/fetch.js";
|
|
58
|
+
import { nodeLookup } from "../egress/node-lookup.js";
|
|
59
|
+
/**
|
|
60
|
+
* Why the connector refused a socket. Module-private: `pinnedFetch` finds it
|
|
61
|
+
* in the failed fetch's `cause` and answers with an `EgressError`, because
|
|
62
|
+
* only it knows the URL the refusal is about.
|
|
63
|
+
*/
|
|
64
|
+
class ConnectRefusal extends Error {
|
|
65
|
+
hostname;
|
|
66
|
+
refused;
|
|
67
|
+
constructor(hostname, refused) {
|
|
68
|
+
super(refused === null ? `${hostname} has no address to dial` : `${hostname} resolves to a refused address`);
|
|
69
|
+
this.hostname = hostname;
|
|
70
|
+
this.refused = refused;
|
|
71
|
+
this.name = "ConnectRefusal";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** The guarded fetch over the pinned dialer: what a process composes at its root. */
|
|
75
|
+
export function nodeGuardedFetch(policy, options = {}) {
|
|
76
|
+
const lookup = options.lookup ?? nodeLookup();
|
|
77
|
+
return guardedFetch(policy, {
|
|
78
|
+
fetchImpl: options.fetchImpl ?? pinnedFetch(policy, { lookup }),
|
|
79
|
+
lookup,
|
|
80
|
+
maxRedirects: options.maxRedirects,
|
|
81
|
+
maxResponseBytes: options.maxResponseBytes,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** A fetch whose every socket opens only to an address `policy` allows, as `lookup` resolved it. */
|
|
85
|
+
export function pinnedFetch(policy, options) {
|
|
86
|
+
const connect = buildConnector({ lookup: judgingLookup(policy, options.lookup) });
|
|
87
|
+
const agent = new Agent({
|
|
88
|
+
connect: (connectOptions, callback) => {
|
|
89
|
+
// undici hands an IPv6 literal without its brackets; a literal host never reaches the lookup.
|
|
90
|
+
if (isIP(connectOptions.hostname) !== 0) {
|
|
91
|
+
const refused = refusedAddress([connectOptions.hostname], policy);
|
|
92
|
+
if (refused !== null) {
|
|
93
|
+
callback(new ConnectRefusal(connectOptions.hostname, refused), null);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
connect(connectOptions, callback);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
return async (input, init) => {
|
|
101
|
+
const url = new URL(input);
|
|
102
|
+
const request = undiciInit(init);
|
|
103
|
+
let response;
|
|
104
|
+
try {
|
|
105
|
+
response = await undiciFetch(url, { ...request, dispatcher: agent });
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
const refusal = connectRefusalIn(error);
|
|
109
|
+
if (refusal === undefined)
|
|
110
|
+
throw error;
|
|
111
|
+
throw new EgressError(refusal.refused === null
|
|
112
|
+
? { kind: "unresolvable", url, hostname: refusal.hostname, policy: policy.name }
|
|
113
|
+
: { kind: "blocked", url, hostname: refusal.hostname, ...refusal.refused, policy: policy.name });
|
|
114
|
+
}
|
|
115
|
+
// undici answers a null body for the null-body statuses (204, 205, 304)
|
|
116
|
+
// itself, as the fetch standard says, so the platform Response accepts it.
|
|
117
|
+
return new Response(response.body, {
|
|
118
|
+
status: response.status,
|
|
119
|
+
statusText: response.statusText,
|
|
120
|
+
headers: [...response.headers],
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A Node lookup that resolves through `lookup`, judges every address, and
|
|
126
|
+
* answers only with judged ones. It honours the options a socket passes:
|
|
127
|
+
* `all` (a list, which `autoSelectFamily` asks for) or one address, and
|
|
128
|
+
* `family` as a filter over the judged list that never widens it. Exported
|
|
129
|
+
* for its tests; a process takes it through `pinnedFetch`.
|
|
130
|
+
*/
|
|
131
|
+
export function judgingLookup(policy, lookup) {
|
|
132
|
+
return (hostname, options, callback) => {
|
|
133
|
+
void judge(hostname, familyNumber(options.family), policy, lookup).then((judged) => {
|
|
134
|
+
if (judged instanceof ConnectRefusal) {
|
|
135
|
+
callback(judged, "", 0);
|
|
136
|
+
}
|
|
137
|
+
else if (options.all === true) {
|
|
138
|
+
callback(null, judged.all.map((address) => ({ address, family: isIP(address) })));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
callback(null, judged.first, isIP(judged.first));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** The addresses a socket may open for `hostname`, or why it may open none. */
|
|
147
|
+
async function judge(hostname, family, policy, lookup) {
|
|
148
|
+
let addresses;
|
|
149
|
+
try {
|
|
150
|
+
addresses = await lookup(hostname);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return new ConnectRefusal(hostname, null);
|
|
154
|
+
}
|
|
155
|
+
const refused = refusedAddress(addresses, policy);
|
|
156
|
+
if (refused !== null)
|
|
157
|
+
return new ConnectRefusal(hostname, refused);
|
|
158
|
+
const all = family === 0 ? addresses : addresses.filter((address) => isIP(address) === family);
|
|
159
|
+
const [first] = all;
|
|
160
|
+
if (first === undefined)
|
|
161
|
+
return new ConnectRefusal(hostname, null);
|
|
162
|
+
return { first, all };
|
|
163
|
+
}
|
|
164
|
+
/** A lookup's `family` option as 0 (any), 4 or 6. */
|
|
165
|
+
function familyNumber(family) {
|
|
166
|
+
if (family === "IPv4")
|
|
167
|
+
return 4;
|
|
168
|
+
if (family === "IPv6")
|
|
169
|
+
return 6;
|
|
170
|
+
return family ?? 0;
|
|
171
|
+
}
|
|
172
|
+
/** The connector's refusal behind a failed fetch: undici reports a failed connect as `TypeError("fetch failed")` with the connector's error as its cause. */
|
|
173
|
+
function connectRefusalIn(error) {
|
|
174
|
+
let current = error;
|
|
175
|
+
for (let depth = 0; depth < 4 && current instanceof Error; depth += 1) {
|
|
176
|
+
if (current instanceof ConnectRefusal)
|
|
177
|
+
return current;
|
|
178
|
+
current = current.cause;
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The platform request as undici's: the fields this library's callers set.
|
|
184
|
+
* A body other than a string, form parameters or bytes is refused here,
|
|
185
|
+
* before any connection, rather than flattened.
|
|
186
|
+
*/
|
|
187
|
+
function undiciInit(init) {
|
|
188
|
+
return {
|
|
189
|
+
method: init?.method,
|
|
190
|
+
headers: [...new Headers(init?.headers)],
|
|
191
|
+
body: undiciBody(init?.body),
|
|
192
|
+
redirect: init?.redirect,
|
|
193
|
+
signal: init?.signal,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function undiciBody(body) {
|
|
197
|
+
if (body === undefined || body === null)
|
|
198
|
+
return body;
|
|
199
|
+
if (typeof body === "string" || body instanceof URLSearchParams || body instanceof Uint8Array || body instanceof ArrayBuffer) {
|
|
200
|
+
return body;
|
|
201
|
+
}
|
|
202
|
+
throw new TypeError(`The pinned dialer carries a string, URLSearchParams or bytes body, not ${body.constructor.name}`);
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=pinned-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinned-fetch.js","sourceRoot":"","sources":["../src/dial/pinned-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,OAAO,EAAE,IAAI,EAAuB,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,IAAI,WAAW,EAAyC,MAAM,QAAQ,CAAC;AAG5G,OAAO,EAAE,WAAW,EAAE,cAAc,EAAsC,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAE,YAAY,EAAsB,MAAM,oBAAoB,C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AI,EAAE,MAAM;QACpB,OAAO,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC;QAC5B,QAAQ,EAAE,IAAI,EAAE,QAAQ;QACxB,MAAM,EAAE,IAAI,EAAE,MAAM;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,IAAyB;IAC3C,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,YAAY,eAAe,IAAI,IAAI,YAAY,UAAU,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;QAC7H,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,0EAA0E,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;AACzH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The two egress postures; the caller derives one from where it runs. */
|
|
2
|
+
export type EgressPosture = "strict" | "relaxed";
|
|
3
|
+
/**
|
|
4
|
+
* An egress policy: the synchronous address judgement a process dials
|
|
5
|
+
* under. `blockedReason` answers for every string (an unparseable one is
|
|
6
|
+
* refused as "unrecognized"), never throws, and does no I/O. A policy that
|
|
7
|
+
* would need a network or a hostname to answer is a different seam.
|
|
8
|
+
*/
|
|
9
|
+
export interface EgressPolicy {
|
|
10
|
+
/** The posture it judges under: for logs, and for how much a refusal's sentence may say. */
|
|
11
|
+
readonly name: EgressPosture;
|
|
12
|
+
/** A human-readable range name when the address is refused, null when allowed. */
|
|
13
|
+
blockedReason(address: string): string | null;
|
|
14
|
+
}
|
|
15
|
+
/** The policy for a posture: the two shapes every consumer composes. */
|
|
16
|
+
export declare function egressPolicyForPosture(posture: EgressPosture): EgressPolicy;
|
|
17
|
+
/**
|
|
18
|
+
* Classify an IP address against the posture's refused ranges.
|
|
19
|
+
*
|
|
20
|
+
* @returns a human-readable range name when refused, or null when allowed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function blockedReason(address: string, posture: EgressPosture): string | null;
|
|
23
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +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,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"}
|