@webpieces/http-client-node 0.4.964 → 0.4.966
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -15
- package/package.json +5 -5
- package/src/ClientHttpFactory.d.ts +1 -1
- package/src/ClientHttpFactory.js +1 -1
- package/src/ClientHttpFactory.js.map +1 -1
- package/src/DeletedAuthCompileAssertions.d.ts +13 -4
- package/src/DeletedAuthCompileAssertions.js +26 -7
- package/src/DeletedAuthCompileAssertions.js.map +1 -1
- package/src/NodeProxyClient.d.ts +3 -3
- package/src/NodeProxyClient.js +7 -7
- package/src/NodeProxyClient.js.map +1 -1
- package/src/OutboundAuthErrors.d.ts +5 -5
- package/src/OutboundAuthErrors.js +8 -8
- package/src/OutboundAuthErrors.js.map +1 -1
- package/src/OutboundAuthFilter.d.ts +16 -10
- package/src/OutboundAuthFilter.js +20 -16
- package/src/OutboundAuthFilter.js.map +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.js +8 -7
- package/src/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -119,7 +119,7 @@ for (const webhook of webhooks) {
|
|
|
119
119
|
`new ContextFullUrlFilter(new SsrfTestingPolicy('local fake in the delivery e2e'))`.
|
|
120
120
|
- **Every auth mode still works.** `oidcSameProject()` / `oidcSvcs(...)` mint for the FINAL base URL, `sharedSecret(...)`
|
|
121
121
|
sends the value this client holds (N services implementing one contract behind one agreed secret is
|
|
122
|
-
a real topology), and `@WpAuth([vendorAuth(name)])` calls your bound `
|
|
122
|
+
a real topology), and `@WpAuth([vendorAuth(name)])` calls your bound `VendorAuthMinter.mint`. The minter runs
|
|
123
123
|
BELOW the SSRF guard, so a destination that is going to be refused never causes a credential to be
|
|
124
124
|
created.
|
|
125
125
|
- **The hop is VISIBLE.** `@externalSystem runtime <identity>` on the contract draws the destination
|
|
@@ -138,37 +138,73 @@ for deployment assumptions and why a direct application-verifier test does not t
|
|
|
138
138
|
|
|
139
139
|
## A vendor's credential, both ways — `vendorAuth(...)`
|
|
140
140
|
|
|
141
|
-
`@WpAuth([vendorAuth(name)])` names a vendor's credential SCHEME, not a direction.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
`@WpAuth([vendorAuth(name)])` names a vendor's credential SCHEME, not a direction. The direction is
|
|
142
|
+
decided by whether THIS runtime is sending or receiving, and each direction is its OWN optional DI
|
|
143
|
+
role (both defined in `@webpieces/core-context`):
|
|
144
|
+
|
|
145
|
+
| role | token | methods | who binds it | re-exported by |
|
|
146
|
+
|---|---|---|---|---|
|
|
147
|
+
| `VendorAuthMinter` | `VENDOR_AUTH_MINTER` | `mint`, `refresh` | a process that SENDS `vendorAuth(...)` calls (a CLI, a worker, a server calling a vendor) | `@webpieces/http-client-node` |
|
|
148
|
+
| `VendorAuthVerifier` | `VENDOR_AUTH_VERIFIER` | `verify` | a server that RECEIVES `vendorAuth(...)` calls | `@webpieces/http-routing` |
|
|
149
|
+
|
|
150
|
+
A process binds neither, one, or both. `mint` produces the credential WE present when we call the
|
|
151
|
+
vendor (a per-merchant OAuth bearer, a partner's HMAC over the final URL and the exact wire bytes),
|
|
152
|
+
and `refresh` renews it when the vendor answers our call with a `401`:
|
|
146
153
|
|
|
147
154
|
```ts
|
|
148
155
|
@provideSingleton()
|
|
149
|
-
export class
|
|
156
|
+
export class PartnerAuthMinter extends VendorAuthMinter {
|
|
150
157
|
async mint(name: string, request: SignableRequest): Promise<Map<string, string>> {
|
|
151
158
|
const mac = createHmac('sha256', secretFor(name)).update(request.body ?? '').digest('hex');
|
|
152
159
|
return new Map([['x-partner-signature', `sha256=${mac}`]]);
|
|
153
160
|
}
|
|
154
161
|
async refresh(name: string): Promise<void> { /* renew the OAuth token, log in again */ }
|
|
155
|
-
async verify(name: string, request: RawHttpRequest): Promise<AuthenticatedCaller> { /* ... */ }
|
|
156
162
|
}
|
|
157
163
|
|
|
158
|
-
//
|
|
159
|
-
|
|
164
|
+
// the SENDING process's BindModule
|
|
165
|
+
binder.bind(VENDOR_AUTH_MINTER).to(PartnerAuthMinter).inSingletonScope();
|
|
160
166
|
```
|
|
161
167
|
|
|
168
|
+
**Why two roles (#1358).** Every typed RPC client this package builds is a `NodeProxyClient`, and it
|
|
169
|
+
depends on the OUTBOUND role only. When one `VendorAuthHook` served both directions, every proxy —
|
|
170
|
+
including an ordinary `oidcSameProject()` client — constructed the server's inbound verifier, and a
|
|
171
|
+
verifier that looks a credential up through such a client closed a DI cycle
|
|
172
|
+
(`Circular dependency found`) before the server could listen. With the roles split, a
|
|
173
|
+
`VendorAuthVerifier` may depend on any RPC client, in any binding order, and the graph stays acyclic.
|
|
174
|
+
|
|
175
|
+
| configuration | minter required? | verifier required? |
|
|
176
|
+
|---|---|---|
|
|
177
|
+
| OIDC-only or public-only outbound client | no | no |
|
|
178
|
+
| outbound call selecting `vendorAuth(name)` | yes, to send that call | no |
|
|
179
|
+
| server receiving a `vendorAuth(name)` request | no | yes |
|
|
180
|
+
| server receiving vendor calls and calling an OIDC-only API downstream | no (not for the OIDC hop) | yes |
|
|
181
|
+
| process both sending and receiving vendor calls | yes | yes |
|
|
182
|
+
|
|
183
|
+
### Migrating from `VendorAuthHook` / `VENDOR_AUTH_HOOK`
|
|
184
|
+
|
|
185
|
+
The unified hook is DELETED (no alias): the old import stops compiling, which is the migration.
|
|
186
|
+
|
|
187
|
+
- A CLIENT process (e.g. a CLI holding a worker token): `extends VendorAuthMinter`, keep `mint` and
|
|
188
|
+
`refresh`, delete the meaningless `verify`, and bind `VENDOR_AUTH_MINTER`. The minter keeps reading
|
|
189
|
+
the credential it already holds — it never validates it server-side.
|
|
190
|
+
- A SERVER process: `extends VendorAuthVerifier`, keep `verify`, delete the meaningless
|
|
191
|
+
`mint`/`refresh`, and bind `VENDOR_AUTH_VERIFIER`. Its constructor may inject the typed
|
|
192
|
+
`oidcSameProject()` RPC client it uses to check the credential.
|
|
193
|
+
- `MissingVendorAuthHookError` is now `MissingVendorAuthMinterError`.
|
|
194
|
+
- Contracts are unchanged: `@WpAuth([vendorAuth(name)])` keeps its meaning.
|
|
195
|
+
|
|
162
196
|
On a raw `401`, `OutboundAuthFilter` cancels the 401's body, calls `refresh(name)` ONCE, mints again
|
|
163
197
|
and re-sends ONCE — never for a streaming upload, and once per logical call (the SSRF redirect loop
|
|
164
198
|
re-enters the filter). A second `401` fails the call exactly as before. Serializing a refresh across
|
|
165
|
-
instances (single-use refresh tokens) is the
|
|
199
|
+
instances (single-use refresh tokens) is the minter's job.
|
|
166
200
|
|
|
167
201
|
The framework ships no vendor crypto, deliberately: Twilio signs the full URL with sorted params,
|
|
168
|
-
Slack signs `v0:{ts}:{body}`, Meta signs the raw body. The scheme lives in your
|
|
169
|
-
the contract. With **no** `
|
|
170
|
-
(`
|
|
171
|
-
401ing every inbound one.
|
|
202
|
+
Slack signs `v0:{ts}:{body}`, Meta signs the raw body. The scheme lives in your minter / verifier and
|
|
203
|
+
the vendor on the contract. With **no** `VendorAuthMinter` bound, every outbound `vendorAuth(...)`
|
|
204
|
+
call THROWS (`MissingVendorAuthMinterError`) before anything is sent, rather than sending
|
|
205
|
+
unauthenticated — the mirror of an unbound `VendorAuthVerifier` 401ing every inbound one. A bound
|
|
206
|
+
verifier never counts as a minter, and an unbound minter never breaks an OIDC, shared-secret or
|
|
207
|
+
public call.
|
|
172
208
|
|
|
173
209
|
Calls have a **30-second default timeout**, including URL resolution, filters/auth, fetch and body
|
|
174
210
|
reading. `ClientRegistry` from `@webpieces/core-util` shares ALL, API and API-method overrides with the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/http-client-node",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.966",
|
|
4
4
|
"description": "Server-side HTTP client for webpieces: inversify-wired, reads RequestContext directly, mints OIDC/shared-secret delivery auth, resolves Cloud Run URLs from a service name",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@webpieces/core-context": "0.4.
|
|
26
|
-
"@webpieces/core-util": "0.4.
|
|
27
|
-
"@webpieces/gcp-identity": "0.4.
|
|
28
|
-
"@webpieces/http-client-core": "0.4.
|
|
25
|
+
"@webpieces/core-context": "0.4.966",
|
|
26
|
+
"@webpieces/core-util": "0.4.966",
|
|
27
|
+
"@webpieces/gcp-identity": "0.4.966",
|
|
28
|
+
"@webpieces/http-client-core": "0.4.966",
|
|
29
29
|
"inversify": "7.10.4",
|
|
30
30
|
"reflect-metadata": "0.2.2"
|
|
31
31
|
}
|
|
@@ -32,7 +32,7 @@ import { NodeProxyClient } from './NodeProxyClient';
|
|
|
32
32
|
* ]);
|
|
33
33
|
* ```
|
|
34
34
|
* The SSRF guard arms itself the moment that filter re-points a request, and the contract's
|
|
35
|
-
* `vendorAuth(name)` selects the app's bound `
|
|
35
|
+
* `vendorAuth(name)` selects the app's bound `VendorAuthMinter` to mint over the exact bytes —
|
|
36
36
|
* neither is something the app registers, orders, or can displace.
|
|
37
37
|
*
|
|
38
38
|
* Every client it builds shares one {@link NodeProxyClient} *shape* but never one instance: the
|
package/src/ClientHttpFactory.js
CHANGED
|
@@ -40,7 +40,7 @@ const NodeProxyClient_1 = require("./NodeProxyClient");
|
|
|
40
40
|
* ]);
|
|
41
41
|
* ```
|
|
42
42
|
* The SSRF guard arms itself the moment that filter re-points a request, and the contract's
|
|
43
|
-
* `vendorAuth(name)` selects the app's bound `
|
|
43
|
+
* `vendorAuth(name)` selects the app's bound `VendorAuthMinter` to mint over the exact bytes —
|
|
44
44
|
* neither is something the app registers, orders, or can displace.
|
|
45
45
|
*
|
|
46
46
|
* Every client it builds shares one {@link NodeProxyClient} *shape* but never one instance: the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientHttpFactory.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/ClientHttpFactory.ts"],"names":[],"mappings":";;;;AAAA,yCAAmC;AACnC,oDAA4E;AAC5E,0DAIiC;AAEjC,kEAA+D;AAE/D,uDAAgF;AAEhF,iGAAiG;AACjG,6EAA6E;AAC7E,IAAA,oCAAqB,EAAC,4CAA0B,EAAE,iCAAe,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAGL;IAFrB,YAEqB,mBAA8C;QAA9C,wBAAmB,GAAnB,mBAAmB,CAA2B;IAChE,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,eAAe,CACX,YAA6B,EAC7B,MAAoB,EACpB,OAA2C;QAE3C,IAAA,gCAAoB,EAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;QACxD,sFAAsF;QACtF,wEAAwE;QACxE,MAAM,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC;QACnD,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;QAClF,OAAO,IAAA,mCAAgB,EAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AA1CY,8CAAiB;4BAAjB,iBAAiB;IAF7B,IAAA,0BAAc,GAAE;IAChB,IAAA,wCAAyB,GAAE;IAGnB,mBAAA,IAAA,kBAAM,EAAC,4CAA0B,CAAC,CAAA;6CACG,uBAAQ;GAHzC,iBAAiB,CA0C7B","sourcesContent":["import { inject } from 'inversify';\nimport { assertNotInternalApi, DocumentDesign } from '@webpieces/core-util';\nimport {\n Provider,\n bindFrameworkProvider,\n provideFrameworkSingleton,\n} from '@webpieces/core-context';\nimport type { ApiPrototype, ClientFilterDefinition } from '@webpieces/http-client-core';\nimport { buildClientProxy } from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\nimport { NODE_PROXY_CLIENT_PROVIDER, NodeProxyClient } from './NodeProxyClient';\n\n// Teach the container how to hand out fresh NodeProxyClients. NodeProxyClient is bound TRANSIENT\n// (@provideFrameworkTransient), so each provider.get() constructs a new one.\nbindFrameworkProvider(NODE_PROXY_CLIENT_PROVIDER, NodeProxyClient);\n\n/**\n * ClientHttpFactory - builds type-safe HTTP clients from API prototypes carrying\n * @ApiPath/@Endpoint decorators. The SERVER-side factory.\n *\n * This is the client-side equivalent of ApiRoutingFactory:\n * - Server routing: ApiRoutingFactory reads decorators -> routes HTTP requests to controllers\n * - Server client: ClientHttpFactory reads decorators -> generates HTTP requests from method calls\n *\n * Inject it and ask for a typed client per contract:\n * ```typescript\n * // same project + region as this container; the URL is derived, you maintain nothing\n * const server2 = factory.createRpcClient(Server2Api, new ClientConfig('server2', ClientRole.SERVER));\n *\n * // to reach somewhere derivation cannot describe (other region/project, non-Cloud-Run, localhost),\n * // register it once at startup — the client still carries only the svcName:\n * // ClientRegistry.addUrlMapping('legacy', 'https://legacy.corp');\n * const legacy = factory.createRpcClient(LegacyApi, new ClientConfig('legacy', ClientRole.SERVER));\n *\n * const response = await server2.fetchValue(req); // inside a RequestContext\n * ```\n *\n * A destination that is DATA rather than deployment — a URL a partner registered — is a FILTER, not\n * a different kind of client. Install `ContextBaseUrlFilter` on the one client that may be\n * re-pointed, and set the URL per call:\n * ```typescript\n * const partner = factory.createRpcClient(PartnerWebhookApi, new ClientConfig('partner-webhooks', ClientRole.SERVER), [\n * new ClientFilterDefinition(1000, new ContextBaseUrlFilter()),\n * ]);\n * ```\n * The SSRF guard arms itself the moment that filter re-points a request, and the contract's\n * `vendorAuth(name)` selects the app's bound `
|
|
1
|
+
{"version":3,"file":"ClientHttpFactory.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/ClientHttpFactory.ts"],"names":[],"mappings":";;;;AAAA,yCAAmC;AACnC,oDAA4E;AAC5E,0DAIiC;AAEjC,kEAA+D;AAE/D,uDAAgF;AAEhF,iGAAiG;AACjG,6EAA6E;AAC7E,IAAA,oCAAqB,EAAC,4CAA0B,EAAE,iCAAe,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAGL;IAFrB,YAEqB,mBAA8C;QAA9C,wBAAmB,GAAnB,mBAAmB,CAA2B;IAChE,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,eAAe,CACX,YAA6B,EAC7B,MAAoB,EACpB,OAA2C;QAE3C,IAAA,gCAAoB,EAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;QACxD,sFAAsF;QACtF,wEAAwE;QACxE,MAAM,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC;QACnD,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;QAClF,OAAO,IAAA,mCAAgB,EAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AA1CY,8CAAiB;4BAAjB,iBAAiB;IAF7B,IAAA,0BAAc,GAAE;IAChB,IAAA,wCAAyB,GAAE;IAGnB,mBAAA,IAAA,kBAAM,EAAC,4CAA0B,CAAC,CAAA;6CACG,uBAAQ;GAHzC,iBAAiB,CA0C7B","sourcesContent":["import { inject } from 'inversify';\nimport { assertNotInternalApi, DocumentDesign } from '@webpieces/core-util';\nimport {\n Provider,\n bindFrameworkProvider,\n provideFrameworkSingleton,\n} from '@webpieces/core-context';\nimport type { ApiPrototype, ClientFilterDefinition } from '@webpieces/http-client-core';\nimport { buildClientProxy } from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\nimport { NODE_PROXY_CLIENT_PROVIDER, NodeProxyClient } from './NodeProxyClient';\n\n// Teach the container how to hand out fresh NodeProxyClients. NodeProxyClient is bound TRANSIENT\n// (@provideFrameworkTransient), so each provider.get() constructs a new one.\nbindFrameworkProvider(NODE_PROXY_CLIENT_PROVIDER, NodeProxyClient);\n\n/**\n * ClientHttpFactory - builds type-safe HTTP clients from API prototypes carrying\n * @ApiPath/@Endpoint decorators. The SERVER-side factory.\n *\n * This is the client-side equivalent of ApiRoutingFactory:\n * - Server routing: ApiRoutingFactory reads decorators -> routes HTTP requests to controllers\n * - Server client: ClientHttpFactory reads decorators -> generates HTTP requests from method calls\n *\n * Inject it and ask for a typed client per contract:\n * ```typescript\n * // same project + region as this container; the URL is derived, you maintain nothing\n * const server2 = factory.createRpcClient(Server2Api, new ClientConfig('server2', ClientRole.SERVER));\n *\n * // to reach somewhere derivation cannot describe (other region/project, non-Cloud-Run, localhost),\n * // register it once at startup — the client still carries only the svcName:\n * // ClientRegistry.addUrlMapping('legacy', 'https://legacy.corp');\n * const legacy = factory.createRpcClient(LegacyApi, new ClientConfig('legacy', ClientRole.SERVER));\n *\n * const response = await server2.fetchValue(req); // inside a RequestContext\n * ```\n *\n * A destination that is DATA rather than deployment — a URL a partner registered — is a FILTER, not\n * a different kind of client. Install `ContextBaseUrlFilter` on the one client that may be\n * re-pointed, and set the URL per call:\n * ```typescript\n * const partner = factory.createRpcClient(PartnerWebhookApi, new ClientConfig('partner-webhooks', ClientRole.SERVER), [\n * new ClientFilterDefinition(1000, new ContextBaseUrlFilter()),\n * ]);\n * ```\n * The SSRF guard arms itself the moment that filter re-points a request, and the contract's\n * `vendorAuth(name)` selects the app's bound `VendorAuthMinter` to mint over the exact bytes —\n * neither is something the app registers, orders, or can displace.\n *\n * Every client it builds shares one {@link NodeProxyClient} *shape* but never one instance: the\n * injected `Provider<NodeProxyClient>` hands out a fresh one per contract, which `createRpcClient`\n * then `init`s. Their collaborators (RequestContextHeaders, Secrets) come from the container, so\n * the whole dependency graph is visible in this package's design.html.\n *\n * Unlike @webpieces/http-client-browser this package is Node-only, so the factory IS the inversify\n * entry point and the magic context is read straight from the RequestContext. A call made outside\n * `RequestContext.run(...)` throws rather than silently dropping the trace.\n */\n@DocumentDesign()\n@provideFrameworkSingleton()\nexport class ClientHttpFactory {\n constructor(\n @inject(NODE_PROXY_CLIENT_PROVIDER)\n private readonly proxyClientProvider: Provider<NodeProxyClient>,\n ) {}\n\n /**\n * Create a type-safe RPC (HTTP) client for one API contract.\n *\n * @param apiPrototype - The API prototype class with @ApiPath/@Endpoint decorators\n * @param config - This client's state: its svcName, which is what `ClientRegistry` resolves\n * @param filters - This client's own OUTBOUND filters, each with the priority it runs at\n * (highest OUTERMOST). They wrap the send, so a filter may rewrite the URL, add or remove\n * headers, log, or replace `ClientRequest.body` — the exact bytes transmitted. What goes\n * here is APP behaviour: url rewriting, headers, logging, and `ContextBaseUrlFilter` when\n * this client's destination arrives per call.\n *\n * OPTIONAL, and omitting it is not a statement about security: the framework's own SSRF\n * guard and credential minter are installed on every client regardless, BENEATH anything\n * passed here, so there is nothing an app can decline by writing nothing.\n *\n * A PLAIN OPTIONAL ARRAY, deliberately. Omitting it, passing `[]`, and passing a list you\n * built up conditionally all mean the same thing and all compile — because the normal way\n * an app arrives at a filter list is to declare a `ClientFilterDefinition[]` and push to\n * it under `if`s, and the declared type of such a local can never be non-empty. A\n * non-empty tuple here would reject that ordinary code and force a cast at the call site.\n * `filters === undefined ? [] : [...filters]` below normalizes the two empty spellings to\n * one value before anything downstream sees them. Pinned in\n * {@link CreateRpcClientCompileAssertions}.\n */\n createRpcClient<T extends object>(\n apiPrototype: ApiPrototype<T>,\n config: ClientConfig,\n filters?: readonly ClientFilterDefinition[],\n ): T {\n assertNotInternalApi(apiPrototype, 'ClientHttpFactory');\n // Fresh instance per contract — NodeProxyClient is transient. init() binds it to this\n // contract + target; the collaborators already came from the container.\n const proxyClient = this.proxyClientProvider.get();\n proxyClient.init(apiPrototype, config, filters === undefined ? [] : [...filters]);\n return buildClientProxy(apiPrototype, proxyClient);\n }\n}\n"]}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { VendorAuthVerifier } from '@webpieces/core-context';
|
|
2
|
+
import { GcpOidc } from '@webpieces/gcp-identity';
|
|
1
3
|
/**
|
|
2
|
-
* COMPILE-TIME proof that the outbound
|
|
3
|
-
* `
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* COMPILE-TIME proof that the deleted outbound auth spellings stay deleted. The outbound half of
|
|
5
|
+
* `webhook(name)` (#1339) and the unified `VendorAuthHook` that replaced it (#1358) are both gone:
|
|
6
|
+
* this client mints with the OUTBOUND role `VendorAuthMinter` (core-context) and nothing else. Each
|
|
7
|
+
* `@ts-expect-error` fails the build (TS2578) the moment its symbol is exported or accepted again. A
|
|
8
|
+
* compiled file, never a `.spec.ts`, because vitest strips types and a spec's `@ts-expect-error` is
|
|
9
|
+
* inert.
|
|
6
10
|
*/
|
|
7
11
|
export declare class DeletedAuthCompileAssertions {
|
|
8
12
|
removedExports(): void;
|
|
13
|
+
/**
|
|
14
|
+
* The outbound filter takes the OUTBOUND role only. Handing it the server's inbound verifier —
|
|
15
|
+
* the shape that put the verifier into every RPC proxy's construction (#1358) — must not compile.
|
|
16
|
+
*/
|
|
17
|
+
outboundFilterRefusesTheVerifier(oidc: GcpOidc, verifier: VendorAuthVerifier): void;
|
|
9
18
|
}
|
|
@@ -3,20 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DeletedAuthCompileAssertions = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ClientNode = tslib_1.__importStar(require("./index"));
|
|
6
|
+
const OutboundAuthFilter_1 = require("./OutboundAuthFilter");
|
|
6
7
|
/**
|
|
7
|
-
* COMPILE-TIME proof that the outbound
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* COMPILE-TIME proof that the deleted outbound auth spellings stay deleted. The outbound half of
|
|
9
|
+
* `webhook(name)` (#1339) and the unified `VendorAuthHook` that replaced it (#1358) are both gone:
|
|
10
|
+
* this client mints with the OUTBOUND role `VendorAuthMinter` (core-context) and nothing else. Each
|
|
11
|
+
* `@ts-expect-error` fails the build (TS2578) the moment its symbol is exported or accepted again. A
|
|
12
|
+
* compiled file, never a `.spec.ts`, because vitest strips types and a spec's `@ts-expect-error` is
|
|
13
|
+
* inert.
|
|
11
14
|
*/
|
|
12
15
|
class DeletedAuthCompileAssertions {
|
|
13
16
|
removedExports() {
|
|
14
|
-
// @ts-expect-error WebhookSignerCallback is replaced by
|
|
17
|
+
// @ts-expect-error WebhookSignerCallback is replaced by VendorAuthMinter.mint (bind VENDOR_AUTH_MINTER)
|
|
15
18
|
void ClientNode.WebhookSignerCallback;
|
|
16
|
-
// @ts-expect-error WEBHOOK_SIGNER_CALLBACK is replaced by
|
|
19
|
+
// @ts-expect-error WEBHOOK_SIGNER_CALLBACK is replaced by VENDOR_AUTH_MINTER
|
|
17
20
|
void ClientNode.WEBHOOK_SIGNER_CALLBACK;
|
|
18
|
-
// @ts-expect-error MissingWebhookSignerError is replaced by
|
|
21
|
+
// @ts-expect-error MissingWebhookSignerError is replaced by MissingVendorAuthMinterError
|
|
19
22
|
void ClientNode.MissingWebhookSignerError;
|
|
23
|
+
// @ts-expect-error VendorAuthHook is DELETED: the client binds the OUTBOUND role VendorAuthMinter
|
|
24
|
+
void ClientNode.VendorAuthHook;
|
|
25
|
+
// @ts-expect-error VENDOR_AUTH_HOOK is DELETED: bind VENDOR_AUTH_MINTER
|
|
26
|
+
void ClientNode.VENDOR_AUTH_HOOK;
|
|
27
|
+
// @ts-expect-error MissingVendorAuthHookError is RENAMED to MissingVendorAuthMinterError
|
|
28
|
+
void ClientNode.MissingVendorAuthHookError;
|
|
29
|
+
// @ts-expect-error the INBOUND role is the server's (http-routing); a client package never exports it
|
|
30
|
+
void ClientNode.VENDOR_AUTH_VERIFIER;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The outbound filter takes the OUTBOUND role only. Handing it the server's inbound verifier —
|
|
34
|
+
* the shape that put the verifier into every RPC proxy's construction (#1358) — must not compile.
|
|
35
|
+
*/
|
|
36
|
+
outboundFilterRefusesTheVerifier(oidc, verifier) {
|
|
37
|
+
// @ts-expect-error a VendorAuthVerifier cannot mint: OutboundAuthFilter takes a VendorAuthMinter
|
|
38
|
+
void new OutboundAuthFilter_1.OutboundAuthFilter(oidc, undefined, verifier);
|
|
20
39
|
}
|
|
21
40
|
}
|
|
22
41
|
exports.DeletedAuthCompileAssertions = DeletedAuthCompileAssertions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeletedAuthCompileAssertions.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/DeletedAuthCompileAssertions.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"DeletedAuthCompileAssertions.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/DeletedAuthCompileAssertions.ts"],"names":[],"mappings":";;;;AAEA,4DAAsC;AACtC,6DAA0D;AAE1D;;;;;;;GAOG;AACH,MAAa,4BAA4B;IACrC,cAAc;QACV,wGAAwG;QACxG,KAAK,UAAU,CAAC,qBAAqB,CAAC;QACtC,6EAA6E;QAC7E,KAAK,UAAU,CAAC,uBAAuB,CAAC;QACxC,yFAAyF;QACzF,KAAK,UAAU,CAAC,yBAAyB,CAAC;QAC1C,kGAAkG;QAClG,KAAK,UAAU,CAAC,cAAc,CAAC;QAC/B,wEAAwE;QACxE,KAAK,UAAU,CAAC,gBAAgB,CAAC;QACjC,yFAAyF;QACzF,KAAK,UAAU,CAAC,0BAA0B,CAAC;QAC3C,sGAAsG;QACtG,KAAK,UAAU,CAAC,oBAAoB,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,gCAAgC,CAAC,IAAa,EAAE,QAA4B;QACxE,iGAAiG;QACjG,KAAK,IAAI,uCAAkB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC3D,CAAC;CACJ;AA1BD,oEA0BC","sourcesContent":["import { VendorAuthVerifier } from '@webpieces/core-context';\nimport { GcpOidc } from '@webpieces/gcp-identity';\nimport * as ClientNode from './index';\nimport { OutboundAuthFilter } from './OutboundAuthFilter';\n\n/**\n * COMPILE-TIME proof that the deleted outbound auth spellings stay deleted. The outbound half of\n * `webhook(name)` (#1339) and the unified `VendorAuthHook` that replaced it (#1358) are both gone:\n * this client mints with the OUTBOUND role `VendorAuthMinter` (core-context) and nothing else. Each\n * `@ts-expect-error` fails the build (TS2578) the moment its symbol is exported or accepted again. A\n * compiled file, never a `.spec.ts`, because vitest strips types and a spec's `@ts-expect-error` is\n * inert.\n */\nexport class DeletedAuthCompileAssertions {\n removedExports(): void {\n // @ts-expect-error WebhookSignerCallback is replaced by VendorAuthMinter.mint (bind VENDOR_AUTH_MINTER)\n void ClientNode.WebhookSignerCallback;\n // @ts-expect-error WEBHOOK_SIGNER_CALLBACK is replaced by VENDOR_AUTH_MINTER\n void ClientNode.WEBHOOK_SIGNER_CALLBACK;\n // @ts-expect-error MissingWebhookSignerError is replaced by MissingVendorAuthMinterError\n void ClientNode.MissingWebhookSignerError;\n // @ts-expect-error VendorAuthHook is DELETED: the client binds the OUTBOUND role VendorAuthMinter\n void ClientNode.VendorAuthHook;\n // @ts-expect-error VENDOR_AUTH_HOOK is DELETED: bind VENDOR_AUTH_MINTER\n void ClientNode.VENDOR_AUTH_HOOK;\n // @ts-expect-error MissingVendorAuthHookError is RENAMED to MissingVendorAuthMinterError\n void ClientNode.MissingVendorAuthHookError;\n // @ts-expect-error the INBOUND role is the server's (http-routing); a client package never exports it\n void ClientNode.VENDOR_AUTH_VERIFIER;\n }\n\n /**\n * The outbound filter takes the OUTBOUND role only. Handing it the server's inbound verifier —\n * the shape that put the verifier into every RPC proxy's construction (#1358) — must not compile.\n */\n outboundFilterRefusesTheVerifier(oidc: GcpOidc, verifier: VendorAuthVerifier): void {\n // @ts-expect-error a VendorAuthVerifier cannot mint: OutboundAuthFilter takes a VendorAuthMinter\n void new OutboundAuthFilter(oidc, undefined, verifier);\n }\n}\n"]}
|
package/src/NodeProxyClient.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DestinationTrust, RouteMetadata, Secrets, ClientRole, HttpCallFactsHolder } from '@webpieces/core-util';
|
|
2
|
-
import { RequestContextHeaders,
|
|
2
|
+
import { RequestContextHeaders, VendorAuthMinter } from '@webpieces/core-context';
|
|
3
3
|
import { GcpOidc } from '@webpieces/gcp-identity';
|
|
4
4
|
import { ApiPrototype, ByteReadableStream, ClientRequest, ClientFilterDefinition, ProxyClient } from '@webpieces/http-client-core';
|
|
5
5
|
import { AddressResolver } from './AddressResolver';
|
|
@@ -17,10 +17,10 @@ export declare class NodeProxyClient extends ProxyClient {
|
|
|
17
17
|
private readonly gcpOidc;
|
|
18
18
|
private readonly addressResolver;
|
|
19
19
|
private readonly secrets?;
|
|
20
|
-
private readonly
|
|
20
|
+
private readonly vendorAuthMinter?;
|
|
21
21
|
protected selectAuthMethod(route: import('@webpieces/core-util').RouteMetadata): import('@webpieces/core-util').AuthMode;
|
|
22
22
|
private config;
|
|
23
|
-
constructor(headers: RequestContextHeaders, gcpOidc: GcpOidc, addressResolver: AddressResolver, secrets?: Secrets | undefined,
|
|
23
|
+
constructor(headers: RequestContextHeaders, gcpOidc: GcpOidc, addressResolver: AddressResolver, secrets?: Secrets | undefined, vendorAuthMinter?: VendorAuthMinter | undefined);
|
|
24
24
|
/**
|
|
25
25
|
* Bind this client to one API contract + target, with the app's outbound filters (url
|
|
26
26
|
* rewriting, header editing, logging, per-call re-pointing).
|
package/src/NodeProxyClient.js
CHANGED
|
@@ -39,14 +39,14 @@ let NodeProxyClient = class NodeProxyClient extends http_client_core_1.ProxyClie
|
|
|
39
39
|
gcpOidc;
|
|
40
40
|
addressResolver;
|
|
41
41
|
secrets;
|
|
42
|
-
|
|
42
|
+
vendorAuthMinter;
|
|
43
43
|
selectAuthMethod(route) {
|
|
44
44
|
const methods = route.authMeta?.methods;
|
|
45
45
|
if (!methods)
|
|
46
46
|
throw new Error('Endpoint requires @WpAuth or @WpAuthPublic.');
|
|
47
47
|
const selected = methods.find((method) => method.kind === 'oidc' || method.kind === 'public' ||
|
|
48
48
|
(method.kind === 'shared-secret' && !!this.secrets?.get(method.secretKey)) ||
|
|
49
|
-
(method.kind === 'vendorAuth' && !!this.
|
|
49
|
+
(method.kind === 'vendorAuth' && !!this.vendorAuthMinter));
|
|
50
50
|
if (selected)
|
|
51
51
|
return selected;
|
|
52
52
|
if (methods.length === 1)
|
|
@@ -54,7 +54,7 @@ let NodeProxyClient = class NodeProxyClient extends http_client_core_1.ProxyClie
|
|
|
54
54
|
throw new Error('No configured Node client credential can satisfy this endpoint; bind a declared service credential.');
|
|
55
55
|
}
|
|
56
56
|
config;
|
|
57
|
-
constructor(headers, gcpOidc, addressResolver, secrets,
|
|
57
|
+
constructor(headers, gcpOidc, addressResolver, secrets, vendorAuthMinter) {
|
|
58
58
|
// This package is node-only and already depends on core-context, so it builds the
|
|
59
59
|
// RequestContext-backed ApiCallContext itself. No startup install, and therefore nothing a
|
|
60
60
|
// non-webpieces host (plain NestJS/Express) can forget.
|
|
@@ -63,7 +63,7 @@ let NodeProxyClient = class NodeProxyClient extends http_client_core_1.ProxyClie
|
|
|
63
63
|
this.gcpOidc = gcpOidc;
|
|
64
64
|
this.addressResolver = addressResolver;
|
|
65
65
|
this.secrets = secrets;
|
|
66
|
-
this.
|
|
66
|
+
this.vendorAuthMinter = vendorAuthMinter;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Bind this client to one API contract + target, with the app's outbound filters (url
|
|
@@ -158,7 +158,7 @@ let NodeProxyClient = class NodeProxyClient extends http_client_core_1.ProxyClie
|
|
|
158
158
|
clientFilters() {
|
|
159
159
|
return [
|
|
160
160
|
new http_client_core_1.ClientFilterDefinition(SSRF_GUARD_PRIORITY, new SsrfGuardFilter_1.SsrfGuardFilter(this.ssrfPolicy(), this.addressResolver)),
|
|
161
|
-
new http_client_core_1.ClientFilterDefinition(OUTBOUND_AUTH_PRIORITY, new OutboundAuthFilter_1.OutboundAuthFilter(this.gcpOidc, this.secrets, this.
|
|
161
|
+
new http_client_core_1.ClientFilterDefinition(OUTBOUND_AUTH_PRIORITY, new OutboundAuthFilter_1.OutboundAuthFilter(this.gcpOidc, this.secrets, this.vendorAuthMinter)),
|
|
162
162
|
];
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
@@ -262,12 +262,12 @@ exports.NodeProxyClient = NodeProxyClient = tslib_1.__decorate([
|
|
|
262
262
|
tslib_1.__param(3, (0, inversify_1.optional)()),
|
|
263
263
|
tslib_1.__param(3, (0, inversify_1.inject)(core_util_1.SECRETS)),
|
|
264
264
|
tslib_1.__param(4, (0, inversify_1.optional)()),
|
|
265
|
-
tslib_1.__param(4, (0, inversify_1.inject)(core_context_1.
|
|
265
|
+
tslib_1.__param(4, (0, inversify_1.inject)(core_context_1.VENDOR_AUTH_MINTER)),
|
|
266
266
|
tslib_1.__metadata("design:paramtypes", [core_context_1.RequestContextHeaders,
|
|
267
267
|
gcp_identity_1.GcpOidc,
|
|
268
268
|
AddressResolver_1.AddressResolver,
|
|
269
269
|
core_util_1.Secrets,
|
|
270
|
-
core_context_1.
|
|
270
|
+
core_context_1.VendorAuthMinter])
|
|
271
271
|
], NodeProxyClient);
|
|
272
272
|
/**
|
|
273
273
|
* DI token for the `Provider<NodeProxyClient>` that hands out RPC clients — one per API contract.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/NodeProxyClient.ts"],"names":[],"mappings":";;;;AAAA,yCAA6C;AAC7C,6CAAmC;AACnC,yCAAoE;AACpE,2CAAqD;AACrD,6CAAuC;AACvC,oDAc8B;AAC9B,0DAOiC;AACj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,MAAM,EAAE,IAAI,CAAC,CAAC;YACtE,QAAQ,CAAC,eAAe,GAAG,QAAQ,CAAC;YACpC,OAAO,QAAQ,CAAC;QACpB,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,mBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,QAAQ,CAAC,eAAe,GAAG,IAAI,yBAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YACxE,MAAM,GAAG,CAAC;QACd,CAAC;IACL,CAAC;CAEJ,CAAA;AArRY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,wCAAyB,GAAE;IAiBnB,mBAAA,IAAA,kBAAM,EAAC,oCAAqB,CAAC,CAAA;IAE7B,mBAAA,IAAA,kBAAM,EAAC,sBAAO,CAAC,CAAA;IAEf,mBAAA,IAAA,kBAAM,EAAC,iCAAe,CAAC,CAAA;IAGvB,mBAAA,IAAA,oBAAQ,GAAE,CAAA;IAAE,mBAAA,IAAA,kBAAM,EAAC,mBAAO,CAAC,CAAA;IAI3B,mBAAA,IAAA,oBAAQ,GAAE,CAAA;IACV,mBAAA,IAAA,kBAAM,EAAC,+BAAgB,CAAC,CAAA;6CAZgC,oCAAqB;QAEnC,sBAAO;QAES,iCAAe;QAGlB,mBAAO;QAM7B,6BAAc;GA7B3C,eAAe,CAqR3B;AAED;;;;;;;GAOG;AACH,gGAAgG;AACnF,QAAA,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC","sourcesContent":["import { inject, optional } from 'inversify';\nimport { once } from 'node:events';\nimport { request as httpRequest, IncomingMessage } from 'node:http';\nimport { request as httpsRequest } from 'node:https';\nimport { Readable } from 'node:stream';\nimport {\n ClientRegistry,\n DestinationTrust,\n ApiImplementationError,\n RecordedEndpoint,\n RecordedError,\n LogApiCallImpl,\n RouteMetadata,\n Secrets,\n SECRETS,\n TestCaseRecorder,\n toError,\n ClientRole,\n HttpCallFactsHolder,\n} from '@webpieces/core-util';\nimport {\n RequestContext,\n RequestContextApiCallContext,\n RequestContextHeaders,\n provideFrameworkTransient,\n VendorAuthHook,\n VENDOR_AUTH_HOOK,\n} from '@webpieces/core-context';\nimport { GcpOidc } from '@webpieces/gcp-identity';\nimport {\n ApiPrototype,\n ByteReadableStream,\n ClientRequest,\n ClientFilterDefinition,\n ProxyClient,\n} from '@webpieces/http-client-core';\nimport { AddressResolver } from './AddressResolver';\nimport { ClientConfig } from './ClientConfig';\nimport { ContextBaseUrlFilter } from './ContextBaseUrlFilter';\nimport { ContextFullUrlFilter } from './ContextFullUrlFilter';\nimport { OutboundAuthFilter } from './OutboundAuthFilter';\nimport { SsrfGuardFilter } from './SsrfGuardFilter';\nimport { SsrfPolicy } from './SsrfPolicy';\n\n/**\n * The two framework built-ins' priorities, RELATIVE TO EACH OTHER and to nothing else — they are\n * ordered beneath every app filter structurally, not by number (see `ProxyClient.initRoutes`).\n *\n * The guard is OUTSIDE the minter deliberately: a destination that is going to be refused must be\n * refused BEFORE a credential is minted for it, so a hostile URL never causes a token to exist.\n */\nconst SSRF_GUARD_PRIORITY = 900;\nconst OUTBOUND_AUTH_PRIORITY = 800;\n\n/**\n * The server-side {@link ProxyClient}. Everything a browser cannot do lives here: reading the\n * ambient RequestContext, minting OIDC tokens, holding shared secrets, and recording test cases.\n *\n * TRANSIENT on purpose. Every `createRpcClient(api, config)` needs its own instance, because `init()`\n * binds one instance to exactly one API contract and one target. {@link ProxyClientProvider} hands\n * them out — see its doc.\n */\n@provideFrameworkTransient()\nexport class NodeProxyClient extends ProxyClient {\n protected override selectAuthMethod(route: import('@webpieces/core-util').RouteMetadata): import('@webpieces/core-util').AuthMode {\n const methods = route.authMeta?.methods;\n if (!methods) throw new Error('Endpoint requires @WpAuth or @WpAuthPublic.');\n const selected = methods.find((method: import('@webpieces/core-util').AuthMode) =>\n method.kind === 'oidc' || method.kind === 'public' ||\n (method.kind === 'shared-secret' && !!this.secrets?.get(method.secretKey)) ||\n (method.kind === 'vendorAuth' && !!this.vendorAuthHook));\n if (selected) return selected;\n if (methods.length === 1) return methods[0];\n throw new Error('No configured Node client credential can satisfy this endpoint; bind a declared service credential.');\n }\n private config!: ClientConfig;\n\n constructor(\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @inject(RequestContextHeaders) private readonly headers: RequestContextHeaders,\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @inject(GcpOidc) private readonly gcpOidc: GcpOidc,\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @inject(AddressResolver) private readonly addressResolver: AddressResolver,\n // @optional: only sharedSecret(...) endpoints need it; the client sends its bound value.\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @optional() @inject(SECRETS) private readonly secrets?: Secrets,\n // @optional: only vendorAuth(...) endpoints need it, and an unbound one makes them THROW\n // rather than send unauthenticated — see VendorAuthHook.\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @optional()\n @inject(VENDOR_AUTH_HOOK)\n private readonly vendorAuthHook?: VendorAuthHook,\n ) {\n // This package is node-only and already depends on core-context, so it builds the\n // RequestContext-backed ApiCallContext itself. No startup install, and therefore nothing a\n // non-webpieces host (plain NestJS/Express) can forget.\n super(new LogApiCallImpl(new RequestContextApiCallContext()));\n }\n\n /**\n * Bind this client to one API contract + target, with the app's outbound filters (url\n * rewriting, header editing, logging, per-call re-pointing).\n */\n init(\n apiPrototype: ApiPrototype<object>,\n config: ClientConfig,\n appFilters: ClientFilterDefinition[],\n ): void {\n this.config = config;\n this.initRoutes(apiPrototype, appFilters);\n }\n\n /**\n * The same chain every client runs — a ClientRegistry mapping, else the installed deriver — but\n * with NODE's fallback: THROW. A server has no \"own origin\" to fall back to the way a browser\n * does, so an unresolvable peer is a setup bug and must fail loudly (the error names the fixes).\n *\n * Resolved per call, never at construction, so building a client stays synchronous. Any metadata\n * read beneath a deriver is memoized process-wide, so only the first call pays.\n */\n protected override clientRole(): ClientRole {\n return this.config.role;\n }\n\n protected override resolveBaseUrl(): Promise<string> {\n return ClientRegistry.resolve(this.config.svcName);\n }\n\n /** Node/undici supports a live ReadableStream body when fetch is given `duplex: 'half'`. */\n protected override supportsConcurrentDuplexFetch(): boolean {\n return true;\n }\n\n /**\n * Node's native HTTP stream is genuinely concurrent: unlike browser Fetch, an early response\n * does not cancel the still-open upload. The returned Web Response keeps parsing isomorphic.\n */\n protected override sendStreamingTransport(\n request: ClientRequest,\n signal: AbortSignal,\n body: ByteReadableStream,\n ): Promise<Response> {\n return new Promise<Response>(\n (resolve: (response: Response) => void, reject: (error: Error) => void) => {\n const url = new URL(request.url);\n const send = url.protocol === 'https:' ? httpsRequest : httpRequest;\n const outgoing = send(\n url,\n {\n method: 'POST',\n headers: request.headersAsRecord(),\n signal,\n },\n (incoming: IncomingMessage): void => {\n const headers = new Headers();\n for (const [name, value] of Object.entries(incoming.headers)) {\n if (Array.isArray(value)) {\n for (const item of value) headers.append(name, item);\n } else if (value !== undefined) {\n headers.set(name, value);\n }\n }\n const responseBody = Readable.toWeb(incoming) as ReadableStream<Uint8Array>;\n resolve(\n new Response(responseBody, {\n status: incoming.statusCode ?? 500,\n statusText: incoming.statusMessage,\n headers,\n }),\n );\n },\n );\n outgoing.once('error', reject);\n // webpieces-disable no-any-unknown -- a native socket/write rejection is normalized by toError\n void this.pumpStreamingRequest(body, outgoing).catch((err: unknown) => {\n const error = toError(err);\n outgoing.destroy(error);\n });\n },\n );\n }\n\n private async pumpStreamingRequest(\n body: ByteReadableStream,\n outgoing: import('node:http').ClientRequest,\n ): Promise<void> {\n const reader = body.getReader();\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- socket errors reject writer acknowledgements\n try {\n for (;;) {\n const part = await reader.read();\n if (part.done) break;\n if (!outgoing.write(part.value)) await once(outgoing, 'drain');\n }\n outgoing.end();\n } finally {\n reader.releaseLock();\n }\n }\n\n /**\n * The two framework built-ins, installed on EVERY client this package builds and ordered\n * beneath every app filter by {@link ProxyClient.initRoutes}.\n *\n * They are unconditional rather than opt-in because neither costs anything on the path that\n * does not need it: the SSRF guard steps aside when nothing re-pointed the request, and the\n * auth filter does nothing for a `@WpAuthPublic` endpoint. An app therefore cannot forget to install\n * the guard on the one client that takes runtime URLs — the ACT of re-pointing is what arms it.\n */\n protected override clientFilters(): ClientFilterDefinition[] {\n return [\n new ClientFilterDefinition(\n SSRF_GUARD_PRIORITY,\n new SsrfGuardFilter(this.ssrfPolicy(), this.addressResolver),\n ),\n new ClientFilterDefinition(\n OUTBOUND_AUTH_PRIORITY,\n new OutboundAuthFilter(this.gcpOidc, this.secrets, this.vendorAuthHook),\n ),\n ];\n }\n\n /**\n * WHICH policy the guard applies when something does re-point this client.\n *\n * Read off an installed {@link ContextBaseUrlFilter} or {@link ContextFullUrlFilter}, because\n * that filter is where an app says\n * \"this client may be re-pointed\", and the single legitimate relaxation\n * ({@link SsrfTestingPolicy}) belongs at the same construction site as that decision rather\n * than in a second place a reader has to correlate. No such filter — or one built with the\n * default — means {@link SsrfPolicy} (the strict one), so the safe answer is what an app gets by saying\n * nothing.\n */\n private ssrfPolicy(): SsrfPolicy {\n for (const definition of this.appFilters) {\n const filter = definition.filter;\n if (filter instanceof ContextBaseUrlFilter || filter instanceof ContextFullUrlFilter) {\n return filter.ssrfPolicy;\n }\n }\n return new SsrfPolicy();\n }\n\n /**\n * Straight from the RequestContext. Throws when there is no active request scope.\n *\n * `destination` rides through unchanged: this is the ONE client that can legitimately propagate a\n * verified identity, and it does so exactly when the callee will authenticate us (oidcSameProject() /\n * oidcSvcs(...) / sharedSecret(...)). Calling a peer's @WpAuthPublic or jwt() endpoint now omits `x-user-id` and\n * friends instead of shipping headers that endpoint's AuthFilter is obliged to reject.\n */\n protected override outboundContextHeaders(destination: DestinationTrust): Map<string, string> {\n return this.headers.buildOutboundHeaders(destination);\n }\n\n /**\n * Straight into the ambient RequestContext — the reason a value a callee set climbs the call\n * tree: after this returns, the CALLER's context holds it, and the caller's own response (and its\n * own outbound calls) carry it onward.\n *\n * `destination` is the trust gate, and it is the mirror of the inbound problem rather than a\n * restatement of it: a response is another process's ASSERTION. Untrusted response keys are\n * admitted; a TRUSTED one is admitted only from a destination this client authenticated to, and\n * is otherwise dropped — see `RequestContextHeaders.acceptResponseHeaders`.\n */\n protected override acceptResponseContext(\n headers: Headers,\n destination: DestinationTrust,\n ): void {\n this.headers.acceptResponseHeaders(headers, destination);\n }\n\n /**\n * Test-case recording hook (mirror of Java HttpsJsonClientInvokeHandler): if a recorder is\n * travelling in the magic context, capture this outbound call + its result so it becomes a mock\n * in the generated test. Absent a recorder this is exactly the base behavior.\n */\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n protected override async execute(\n route: RouteMetadata,\n requestDto: unknown,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n method: () => Promise<unknown>,\n http?: HttpCallFactsHolder,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n ): Promise<unknown> {\n // Preserve the context precondition before logging, which also requires an active scope.\n if (!RequestContext.isActive()) {\n throw new Error(\n 'No active RequestContext. Run the client call inside RequestContext.run(...).',\n );\n }\n const recorder = this.headers.findRecorder();\n if (!recorder) {\n return super.execute(route, requestDto, method, http);\n }\n return this.recordCall(recorder, route, requestDto, method, http);\n }\n\n /**\n * Execute the call while recording it (args + masked ctx snapshot + result).\n *\n * The snapshot is a FIXTURE field, not a log line, so it is built here rather than handed down\n * from the call path — a logging backend stamps its own fields and never sees this.\n */\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n private async recordCall(\n recorder: TestCaseRecorder,\n route: RouteMetadata,\n requestDto: unknown,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n method: () => Promise<unknown>,\n http: HttpCallFactsHolder | undefined,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n ): Promise<unknown> {\n const ctxSnapshot: Record<string, string> = {};\n for (const entry of RequestContext.buildLogFields().entries()) {\n ctxSnapshot[entry[0]] = entry[1];\n }\n const recorded = new RecordedEndpoint(\n this.contractName(),\n route.methodName,\n [requestDto],\n ctxSnapshot,\n );\n recorder.addEndpointInfo(recorded);\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- capture failure into the recording, then rethrow unchanged\n try {\n const response = await super.execute(route, requestDto, method, http);\n recorded.successResponse = response;\n return response;\n } catch (err: unknown) {\n const error = toError(err);\n recorded.failureResponse = new RecordedError(error.name, error.message);\n throw err;\n }\n }\n\n}\n\n/**\n * DI token for the `Provider<NodeProxyClient>` that hands out RPC clients — one per API contract.\n * `Provider<T>` is erased at runtime, so it cannot be its own token; this Symbol names T.\n *\n * Because NodeProxyClient is bound TRANSIENT, every `get()` constructs a new one. (Were it bound\n * `@provideFrameworkSingleton`, the very same Provider would instead hand back one lazily-created\n * instance — the provider caches nothing, so the target's scope decides.)\n */\n// webpieces-disable no-symbol-di-tokens -- Provider<T> is erased at runtime; the Symbol names T\nexport const NODE_PROXY_CLIENT_PROVIDER = Symbol.for('Provider<NodeProxyClient>');\n"]}
|
|
1
|
+
{"version":3,"file":"NodeProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/NodeProxyClient.ts"],"names":[],"mappings":";;;;AAAA,yCAA6C;AAC7C,6CAAmC;AACnC,yCAAoE;AACpE,2CAAqD;AACrD,6CAAuC;AACvC,oDAc8B;AAC9B,0DAOiC;AACjC,0DAAkD;AAClD,kEAMqC;AACrC,uDAAoD;AAEpD,iEAA8D;AAC9D,iEAA8D;AAC9D,6DAA0D;AAC1D,uD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AAO,QAAQ,CAAC;QACpB,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,mBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,QAAQ,CAAC,eAAe,GAAG,IAAI,yBAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YACxE,MAAM,GAAG,CAAC;QACd,CAAC;IACL,CAAC;CAEJ,CAAA;AAvRY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,wCAAyB,GAAE;IAiBnB,mBAAA,IAAA,kBAAM,EAAC,oCAAqB,CAAC,CAAA;IAE7B,mBAAA,IAAA,kBAAM,EAAC,sBAAO,CAAC,CAAA;IAEf,mBAAA,IAAA,kBAAM,EAAC,iCAAe,CAAC,CAAA;IAGvB,mBAAA,IAAA,oBAAQ,GAAE,CAAA;IAAE,mBAAA,IAAA,kBAAM,EAAC,mBAAO,CAAC,CAAA;IAM3B,mBAAA,IAAA,oBAAQ,GAAE,CAAA;IACV,mBAAA,IAAA,kBAAM,EAAC,iCAAkB,CAAC,CAAA;6CAd8B,oCAAqB;QAEnC,sBAAO;QAES,iCAAe;QAGlB,mBAAO;QAQ3B,+BAAgB;GA/B/C,eAAe,CAuR3B;AAED;;;;;;;GAOG;AACH,gGAAgG;AACnF,QAAA,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC","sourcesContent":["import { inject, optional } from 'inversify';\nimport { once } from 'node:events';\nimport { request as httpRequest, IncomingMessage } from 'node:http';\nimport { request as httpsRequest } from 'node:https';\nimport { Readable } from 'node:stream';\nimport {\n ClientRegistry,\n DestinationTrust,\n ApiImplementationError,\n RecordedEndpoint,\n RecordedError,\n LogApiCallImpl,\n RouteMetadata,\n Secrets,\n SECRETS,\n TestCaseRecorder,\n toError,\n ClientRole,\n HttpCallFactsHolder,\n} from '@webpieces/core-util';\nimport {\n RequestContext,\n RequestContextApiCallContext,\n RequestContextHeaders,\n provideFrameworkTransient,\n VendorAuthMinter,\n VENDOR_AUTH_MINTER,\n} from '@webpieces/core-context';\nimport { GcpOidc } from '@webpieces/gcp-identity';\nimport {\n ApiPrototype,\n ByteReadableStream,\n ClientRequest,\n ClientFilterDefinition,\n ProxyClient,\n} from '@webpieces/http-client-core';\nimport { AddressResolver } from './AddressResolver';\nimport { ClientConfig } from './ClientConfig';\nimport { ContextBaseUrlFilter } from './ContextBaseUrlFilter';\nimport { ContextFullUrlFilter } from './ContextFullUrlFilter';\nimport { OutboundAuthFilter } from './OutboundAuthFilter';\nimport { SsrfGuardFilter } from './SsrfGuardFilter';\nimport { SsrfPolicy } from './SsrfPolicy';\n\n/**\n * The two framework built-ins' priorities, RELATIVE TO EACH OTHER and to nothing else — they are\n * ordered beneath every app filter structurally, not by number (see `ProxyClient.initRoutes`).\n *\n * The guard is OUTSIDE the minter deliberately: a destination that is going to be refused must be\n * refused BEFORE a credential is minted for it, so a hostile URL never causes a token to exist.\n */\nconst SSRF_GUARD_PRIORITY = 900;\nconst OUTBOUND_AUTH_PRIORITY = 800;\n\n/**\n * The server-side {@link ProxyClient}. Everything a browser cannot do lives here: reading the\n * ambient RequestContext, minting OIDC tokens, holding shared secrets, and recording test cases.\n *\n * TRANSIENT on purpose. Every `createRpcClient(api, config)` needs its own instance, because `init()`\n * binds one instance to exactly one API contract and one target. {@link ProxyClientProvider} hands\n * them out — see its doc.\n */\n@provideFrameworkTransient()\nexport class NodeProxyClient extends ProxyClient {\n protected override selectAuthMethod(route: import('@webpieces/core-util').RouteMetadata): import('@webpieces/core-util').AuthMode {\n const methods = route.authMeta?.methods;\n if (!methods) throw new Error('Endpoint requires @WpAuth or @WpAuthPublic.');\n const selected = methods.find((method: import('@webpieces/core-util').AuthMode) =>\n method.kind === 'oidc' || method.kind === 'public' ||\n (method.kind === 'shared-secret' && !!this.secrets?.get(method.secretKey)) ||\n (method.kind === 'vendorAuth' && !!this.vendorAuthMinter));\n if (selected) return selected;\n if (methods.length === 1) return methods[0];\n throw new Error('No configured Node client credential can satisfy this endpoint; bind a declared service credential.');\n }\n private config!: ClientConfig;\n\n constructor(\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @inject(RequestContextHeaders) private readonly headers: RequestContextHeaders,\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @inject(GcpOidc) private readonly gcpOidc: GcpOidc,\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @inject(AddressResolver) private readonly addressResolver: AddressResolver,\n // @optional: only sharedSecret(...) endpoints need it; the client sends its bound value.\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @optional() @inject(SECRETS) private readonly secrets?: Secrets,\n // @optional: only OUTBOUND vendorAuth(...) calls need it, and an unbound one makes them THROW\n // rather than send unauthenticated — see VendorAuthMinter. The OUTBOUND role ONLY: this\n // client must never depend on the server's inbound VendorAuthVerifier, because a verifier\n // that itself uses an RPC client would then close a construction cycle (#1358).\n // webpieces-disable inject-annotation-not-needed-for-concrete-class -- DI-resolved param; the esbuild/vitest path elides type-only imports (no design:paramtypes), so the explicit token is required\n @optional()\n @inject(VENDOR_AUTH_MINTER)\n private readonly vendorAuthMinter?: VendorAuthMinter,\n ) {\n // This package is node-only and already depends on core-context, so it builds the\n // RequestContext-backed ApiCallContext itself. No startup install, and therefore nothing a\n // non-webpieces host (plain NestJS/Express) can forget.\n super(new LogApiCallImpl(new RequestContextApiCallContext()));\n }\n\n /**\n * Bind this client to one API contract + target, with the app's outbound filters (url\n * rewriting, header editing, logging, per-call re-pointing).\n */\n init(\n apiPrototype: ApiPrototype<object>,\n config: ClientConfig,\n appFilters: ClientFilterDefinition[],\n ): void {\n this.config = config;\n this.initRoutes(apiPrototype, appFilters);\n }\n\n /**\n * The same chain every client runs — a ClientRegistry mapping, else the installed deriver — but\n * with NODE's fallback: THROW. A server has no \"own origin\" to fall back to the way a browser\n * does, so an unresolvable peer is a setup bug and must fail loudly (the error names the fixes).\n *\n * Resolved per call, never at construction, so building a client stays synchronous. Any metadata\n * read beneath a deriver is memoized process-wide, so only the first call pays.\n */\n protected override clientRole(): ClientRole {\n return this.config.role;\n }\n\n protected override resolveBaseUrl(): Promise<string> {\n return ClientRegistry.resolve(this.config.svcName);\n }\n\n /** Node/undici supports a live ReadableStream body when fetch is given `duplex: 'half'`. */\n protected override supportsConcurrentDuplexFetch(): boolean {\n return true;\n }\n\n /**\n * Node's native HTTP stream is genuinely concurrent: unlike browser Fetch, an early response\n * does not cancel the still-open upload. The returned Web Response keeps parsing isomorphic.\n */\n protected override sendStreamingTransport(\n request: ClientRequest,\n signal: AbortSignal,\n body: ByteReadableStream,\n ): Promise<Response> {\n return new Promise<Response>(\n (resolve: (response: Response) => void, reject: (error: Error) => void) => {\n const url = new URL(request.url);\n const send = url.protocol === 'https:' ? httpsRequest : httpRequest;\n const outgoing = send(\n url,\n {\n method: 'POST',\n headers: request.headersAsRecord(),\n signal,\n },\n (incoming: IncomingMessage): void => {\n const headers = new Headers();\n for (const [name, value] of Object.entries(incoming.headers)) {\n if (Array.isArray(value)) {\n for (const item of value) headers.append(name, item);\n } else if (value !== undefined) {\n headers.set(name, value);\n }\n }\n const responseBody = Readable.toWeb(incoming) as ReadableStream<Uint8Array>;\n resolve(\n new Response(responseBody, {\n status: incoming.statusCode ?? 500,\n statusText: incoming.statusMessage,\n headers,\n }),\n );\n },\n );\n outgoing.once('error', reject);\n // webpieces-disable no-any-unknown -- a native socket/write rejection is normalized by toError\n void this.pumpStreamingRequest(body, outgoing).catch((err: unknown) => {\n const error = toError(err);\n outgoing.destroy(error);\n });\n },\n );\n }\n\n private async pumpStreamingRequest(\n body: ByteReadableStream,\n outgoing: import('node:http').ClientRequest,\n ): Promise<void> {\n const reader = body.getReader();\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- socket errors reject writer acknowledgements\n try {\n for (;;) {\n const part = await reader.read();\n if (part.done) break;\n if (!outgoing.write(part.value)) await once(outgoing, 'drain');\n }\n outgoing.end();\n } finally {\n reader.releaseLock();\n }\n }\n\n /**\n * The two framework built-ins, installed on EVERY client this package builds and ordered\n * beneath every app filter by {@link ProxyClient.initRoutes}.\n *\n * They are unconditional rather than opt-in because neither costs anything on the path that\n * does not need it: the SSRF guard steps aside when nothing re-pointed the request, and the\n * auth filter does nothing for a `@WpAuthPublic` endpoint. An app therefore cannot forget to install\n * the guard on the one client that takes runtime URLs — the ACT of re-pointing is what arms it.\n */\n protected override clientFilters(): ClientFilterDefinition[] {\n return [\n new ClientFilterDefinition(\n SSRF_GUARD_PRIORITY,\n new SsrfGuardFilter(this.ssrfPolicy(), this.addressResolver),\n ),\n new ClientFilterDefinition(\n OUTBOUND_AUTH_PRIORITY,\n new OutboundAuthFilter(this.gcpOidc, this.secrets, this.vendorAuthMinter),\n ),\n ];\n }\n\n /**\n * WHICH policy the guard applies when something does re-point this client.\n *\n * Read off an installed {@link ContextBaseUrlFilter} or {@link ContextFullUrlFilter}, because\n * that filter is where an app says\n * \"this client may be re-pointed\", and the single legitimate relaxation\n * ({@link SsrfTestingPolicy}) belongs at the same construction site as that decision rather\n * than in a second place a reader has to correlate. No such filter — or one built with the\n * default — means {@link SsrfPolicy} (the strict one), so the safe answer is what an app gets by saying\n * nothing.\n */\n private ssrfPolicy(): SsrfPolicy {\n for (const definition of this.appFilters) {\n const filter = definition.filter;\n if (filter instanceof ContextBaseUrlFilter || filter instanceof ContextFullUrlFilter) {\n return filter.ssrfPolicy;\n }\n }\n return new SsrfPolicy();\n }\n\n /**\n * Straight from the RequestContext. Throws when there is no active request scope.\n *\n * `destination` rides through unchanged: this is the ONE client that can legitimately propagate a\n * verified identity, and it does so exactly when the callee will authenticate us (oidcSameProject() /\n * oidcSvcs(...) / sharedSecret(...)). Calling a peer's @WpAuthPublic or jwt() endpoint now omits `x-user-id` and\n * friends instead of shipping headers that endpoint's AuthFilter is obliged to reject.\n */\n protected override outboundContextHeaders(destination: DestinationTrust): Map<string, string> {\n return this.headers.buildOutboundHeaders(destination);\n }\n\n /**\n * Straight into the ambient RequestContext — the reason a value a callee set climbs the call\n * tree: after this returns, the CALLER's context holds it, and the caller's own response (and its\n * own outbound calls) carry it onward.\n *\n * `destination` is the trust gate, and it is the mirror of the inbound problem rather than a\n * restatement of it: a response is another process's ASSERTION. Untrusted response keys are\n * admitted; a TRUSTED one is admitted only from a destination this client authenticated to, and\n * is otherwise dropped — see `RequestContextHeaders.acceptResponseHeaders`.\n */\n protected override acceptResponseContext(\n headers: Headers,\n destination: DestinationTrust,\n ): void {\n this.headers.acceptResponseHeaders(headers, destination);\n }\n\n /**\n * Test-case recording hook (mirror of Java HttpsJsonClientInvokeHandler): if a recorder is\n * travelling in the magic context, capture this outbound call + its result so it becomes a mock\n * in the generated test. Absent a recorder this is exactly the base behavior.\n */\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n protected override async execute(\n route: RouteMetadata,\n requestDto: unknown,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n method: () => Promise<unknown>,\n http?: HttpCallFactsHolder,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n ): Promise<unknown> {\n // Preserve the context precondition before logging, which also requires an active scope.\n if (!RequestContext.isActive()) {\n throw new Error(\n 'No active RequestContext. Run the client call inside RequestContext.run(...).',\n );\n }\n const recorder = this.headers.findRecorder();\n if (!recorder) {\n return super.execute(route, requestDto, method, http);\n }\n return this.recordCall(recorder, route, requestDto, method, http);\n }\n\n /**\n * Execute the call while recording it (args + masked ctx snapshot + result).\n *\n * The snapshot is a FIXTURE field, not a log line, so it is built here rather than handed down\n * from the call path — a logging backend stamps its own fields and never sees this.\n */\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n private async recordCall(\n recorder: TestCaseRecorder,\n route: RouteMetadata,\n requestDto: unknown,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n method: () => Promise<unknown>,\n http: HttpCallFactsHolder | undefined,\n // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n ): Promise<unknown> {\n const ctxSnapshot: Record<string, string> = {};\n for (const entry of RequestContext.buildLogFields().entries()) {\n ctxSnapshot[entry[0]] = entry[1];\n }\n const recorded = new RecordedEndpoint(\n this.contractName(),\n route.methodName,\n [requestDto],\n ctxSnapshot,\n );\n recorder.addEndpointInfo(recorded);\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- capture failure into the recording, then rethrow unchanged\n try {\n const response = await super.execute(route, requestDto, method, http);\n recorded.successResponse = response;\n return response;\n } catch (err: unknown) {\n const error = toError(err);\n recorded.failureResponse = new RecordedError(error.name, error.message);\n throw err;\n }\n }\n\n}\n\n/**\n * DI token for the `Provider<NodeProxyClient>` that hands out RPC clients — one per API contract.\n * `Provider<T>` is erased at runtime, so it cannot be its own token; this Symbol names T.\n *\n * Because NodeProxyClient is bound TRANSIENT, every `get()` constructs a new one. (Were it bound\n * `@provideFrameworkSingleton`, the very same Provider would instead hand back one lazily-created\n * instance — the provider caches nothing, so the target's scope decides.)\n */\n// webpieces-disable no-symbol-di-tokens -- Provider<T> is erased at runtime; the Symbol names T\nexport const NODE_PROXY_CLIENT_PROVIDER = Symbol.for('Provider<NodeProxyClient>');\n"]}
|
|
@@ -24,12 +24,12 @@ export declare class MissingSharedSecretError extends Error {
|
|
|
24
24
|
secretKey: string);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* A `vendorAuth(name)` endpoint was called outbound with no `
|
|
28
|
-
* mint the credential the vendor checks. Thrown at CALL time, from
|
|
29
|
-
*
|
|
30
|
-
* `vendorAuth(...)` endpoint instead of admitting it.
|
|
27
|
+
* A `vendorAuth(name)` endpoint was called outbound with no `VendorAuthMinter` (VENDOR_AUTH_MINTER)
|
|
28
|
+
* bound, so nothing can mint the credential the vendor checks. Thrown at CALL time, from
|
|
29
|
+
* `OutboundAuthFilter`, BEFORE anything is sent — the mirror of the inbound side, where an unbound
|
|
30
|
+
* `VendorAuthVerifier` 401s every served `vendorAuth(...)` endpoint instead of admitting it.
|
|
31
31
|
*/
|
|
32
|
-
export declare class
|
|
32
|
+
export declare class MissingVendorAuthMinterError extends Error {
|
|
33
33
|
/** `Contract.method`, so the log line names the call without a stack read. */
|
|
34
34
|
readonly endpoint: string;
|
|
35
35
|
/** The vendor on the contract's `vendorAuth(name)`, which selects the scheme. */
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* auth mode requires is simply absent.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
13
|
+
exports.MissingVendorAuthMinterError = exports.MissingSharedSecretError = void 0;
|
|
14
14
|
/**
|
|
15
15
|
* An `sharedSecret(key)` endpoint was called by a client whose bound `Secrets` holds no value
|
|
16
16
|
* for that key. Thrown at CALL time, from `OutboundAuthFilter`.
|
|
@@ -31,12 +31,12 @@ class MissingSharedSecretError extends Error {
|
|
|
31
31
|
}
|
|
32
32
|
exports.MissingSharedSecretError = MissingSharedSecretError;
|
|
33
33
|
/**
|
|
34
|
-
* A `vendorAuth(name)` endpoint was called outbound with no `
|
|
35
|
-
* mint the credential the vendor checks. Thrown at CALL time, from
|
|
36
|
-
*
|
|
37
|
-
* `vendorAuth(...)` endpoint instead of admitting it.
|
|
34
|
+
* A `vendorAuth(name)` endpoint was called outbound with no `VendorAuthMinter` (VENDOR_AUTH_MINTER)
|
|
35
|
+
* bound, so nothing can mint the credential the vendor checks. Thrown at CALL time, from
|
|
36
|
+
* `OutboundAuthFilter`, BEFORE anything is sent — the mirror of the inbound side, where an unbound
|
|
37
|
+
* `VendorAuthVerifier` 401s every served `vendorAuth(...)` endpoint instead of admitting it.
|
|
38
38
|
*/
|
|
39
|
-
class
|
|
39
|
+
class MissingVendorAuthMinterError extends Error {
|
|
40
40
|
endpoint;
|
|
41
41
|
vendorName;
|
|
42
42
|
constructor(message,
|
|
@@ -47,8 +47,8 @@ class MissingVendorAuthHookError extends Error {
|
|
|
47
47
|
super(message);
|
|
48
48
|
this.endpoint = endpoint;
|
|
49
49
|
this.vendorName = vendorName;
|
|
50
|
-
this.name = '
|
|
50
|
+
this.name = 'MissingVendorAuthMinterError';
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
exports.
|
|
53
|
+
exports.MissingVendorAuthMinterError = MissingVendorAuthMinterError;
|
|
54
54
|
//# sourceMappingURL=OutboundAuthErrors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutboundAuthErrors.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/OutboundAuthErrors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,KAAK;IAI3B;IAEA;IALpB,YACI,OAAe;IACf,8EAA8E;IAC9D,QAAgB;IAChC,8EAA8E;IAC9D,SAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,cAAS,GAAT,SAAS,CAAQ;QAGjC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IAC3C,CAAC;CACJ;AAXD,4DAWC;AAED;;;;;GAKG;AACH,MAAa,
|
|
1
|
+
{"version":3,"file":"OutboundAuthErrors.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/OutboundAuthErrors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,KAAK;IAI3B;IAEA;IALpB,YACI,OAAe;IACf,8EAA8E;IAC9D,QAAgB;IAChC,8EAA8E;IAC9D,SAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,cAAS,GAAT,SAAS,CAAQ;QAGjC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IAC3C,CAAC;CACJ;AAXD,4DAWC;AAED;;;;;GAKG;AACH,MAAa,4BAA6B,SAAQ,KAAK;IAI/B;IAEA;IALpB,YACI,OAAe;IACf,8EAA8E;IAC9D,QAAgB;IAChC,iFAAiF;IACjE,UAAkB;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,eAAU,GAAV,UAAU,CAAQ;QAGlC,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC/C,CAAC;CACJ;AAXD,oEAWC","sourcesContent":["/**\n * The two ways outbound auth refuses to send, each its own type for the reason\n * {@link MissingRuntimeBaseUrlError} is one: a delivery worker has to tell these apart from\n * {@link SsrfRefusedError}. Both mean THIS SERVICE is misconfigured — page somebody, retrying is\n * pointless — where an SSRF refusal means a partner registered something hostile and the delivery\n * should be dead-lettered. A bare `Error` forces that decision to be made by matching message text.\n *\n * Neither is thrown for anything a caller can influence: they fire when the binding a contract's\n * auth mode requires is simply absent.\n */\n\n/**\n * An `sharedSecret(key)` endpoint was called by a client whose bound `Secrets` holds no value\n * for that key. Thrown at CALL time, from `OutboundAuthFilter`.\n */\nexport class MissingSharedSecretError extends Error {\n constructor(\n message: string,\n /** `Contract.method`, so the log line names the call without a stack read. */\n public readonly endpoint: string,\n /** The `sharedSecret(...)` key that had no value, so the fix names itself. */\n public readonly secretKey: string,\n ) {\n super(message);\n this.name = 'MissingSharedSecretError';\n }\n}\n\n/**\n * A `vendorAuth(name)` endpoint was called outbound with no `VendorAuthMinter` (VENDOR_AUTH_MINTER)\n * bound, so nothing can mint the credential the vendor checks. Thrown at CALL time, from\n * `OutboundAuthFilter`, BEFORE anything is sent — the mirror of the inbound side, where an unbound\n * `VendorAuthVerifier` 401s every served `vendorAuth(...)` endpoint instead of admitting it.\n */\nexport class MissingVendorAuthMinterError extends Error {\n constructor(\n message: string,\n /** `Contract.method`, so the log line names the call without a stack read. */\n public readonly endpoint: string,\n /** The vendor on the contract's `vendorAuth(name)`, which selects the scheme. */\n public readonly vendorName: string,\n ) {\n super(message);\n this.name = 'MissingVendorAuthMinterError';\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Filter, Secrets, Service } from '@webpieces/core-util';
|
|
2
|
-
import {
|
|
2
|
+
import { VendorAuthMinter } from '@webpieces/core-context';
|
|
3
3
|
import { GcpOidc } from '@webpieces/gcp-identity';
|
|
4
4
|
import { ClientRequest } from '@webpieces/http-client-core';
|
|
5
5
|
/**
|
|
@@ -26,7 +26,7 @@ import { ClientRequest } from '@webpieces/http-client-core';
|
|
|
26
26
|
* - `sharedSecret(...)` → the value this client holds for that key, as `Authorization: Webpieces …`.
|
|
27
27
|
* Legitimate against a re-pointed URL: N services implementing ONE contract behind ONE agreed
|
|
28
28
|
* secret is a real and common topology, and often stands in for OIDC where OIDC is not available.
|
|
29
|
-
* - `vendorAuth(name)` → the app's bound {@link
|
|
29
|
+
* - `vendorAuth(name)` → the app's bound {@link VendorAuthMinter} `mint`s the headers (a vendor's
|
|
30
30
|
* OAuth bearer, a partner's HMAC signature — the scheme is the app's). On a raw `401` it is the ONE
|
|
31
31
|
* mode that retries: cancel the 401's body, `refresh(name)` once, `mint` again and re-send ONCE.
|
|
32
32
|
* Never for a streaming upload (its body cannot be replayed), and once per logical call — the SSRF
|
|
@@ -42,13 +42,19 @@ export declare class OutboundAuthFilter extends Filter<ClientRequest, Response>
|
|
|
42
42
|
private readonly gcpOidc;
|
|
43
43
|
/** Only sharedSecret(...) endpoints need it; a server that has none binds nothing. */
|
|
44
44
|
private readonly secrets;
|
|
45
|
-
/**
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The OUTBOUND role only. Only vendorAuth(...) calls need it, and an unbound one makes them
|
|
47
|
+
* THROW. Never the inbound VendorAuthVerifier: sending a request verifies nothing (#1358).
|
|
48
|
+
*/
|
|
49
|
+
private readonly vendorAuthMinter;
|
|
47
50
|
constructor(gcpOidc: GcpOidc,
|
|
48
51
|
/** Only sharedSecret(...) endpoints need it; a server that has none binds nothing. */
|
|
49
52
|
secrets: Secrets | undefined,
|
|
50
|
-
/**
|
|
51
|
-
|
|
53
|
+
/**
|
|
54
|
+
* The OUTBOUND role only. Only vendorAuth(...) calls need it, and an unbound one makes them
|
|
55
|
+
* THROW. Never the inbound VendorAuthVerifier: sending a request verifies nothing (#1358).
|
|
56
|
+
*/
|
|
57
|
+
vendorAuthMinter: VendorAuthMinter | undefined);
|
|
52
58
|
/** Requests that already spent their one refresh — keyed by the request, so redirect hops share it. */
|
|
53
59
|
private readonly refreshed;
|
|
54
60
|
filter(request: ClientRequest, nextFilter: Service<ClientRequest, Response>): Promise<Response>;
|
|
@@ -56,10 +62,10 @@ export declare class OutboundAuthFilter extends Filter<ClientRequest, Response>
|
|
|
56
62
|
private uploadsAStream;
|
|
57
63
|
private attach;
|
|
58
64
|
/**
|
|
59
|
-
* @throws
|
|
60
|
-
* matching the inbound side exactly: an unbound
|
|
61
|
-
* endpoint rather than admitting it unverified, so
|
|
62
|
-
* deliver something the vendor is obliged to reject.
|
|
65
|
+
* @throws MissingVendorAuthMinterError when no {@link VendorAuthMinter} is bound. FAIL CLOSED,
|
|
66
|
+
* matching the inbound side exactly: an unbound verifier 401s every served
|
|
67
|
+
* `vendorAuth(...)` endpoint rather than admitting it unverified, so an unbound minter
|
|
68
|
+
* must also refuse to SEND rather than deliver something the vendor is obliged to reject.
|
|
63
69
|
*/
|
|
64
70
|
private mintVendorAuth;
|
|
65
71
|
}
|
|
@@ -28,7 +28,7 @@ const OutboundAuthErrors_1 = require("./OutboundAuthErrors");
|
|
|
28
28
|
* - `sharedSecret(...)` → the value this client holds for that key, as `Authorization: Webpieces …`.
|
|
29
29
|
* Legitimate against a re-pointed URL: N services implementing ONE contract behind ONE agreed
|
|
30
30
|
* secret is a real and common topology, and often stands in for OIDC where OIDC is not available.
|
|
31
|
-
* - `vendorAuth(name)` → the app's bound {@link
|
|
31
|
+
* - `vendorAuth(name)` → the app's bound {@link VendorAuthMinter} `mint`s the headers (a vendor's
|
|
32
32
|
* OAuth bearer, a partner's HMAC signature — the scheme is the app's). On a raw `401` it is the ONE
|
|
33
33
|
* mode that retries: cancel the 401's body, `refresh(name)` once, `mint` again and re-send ONCE.
|
|
34
34
|
* Never for a streaming upload (its body cannot be replayed), and once per logical call — the SSRF
|
|
@@ -43,16 +43,19 @@ const OutboundAuthErrors_1 = require("./OutboundAuthErrors");
|
|
|
43
43
|
class OutboundAuthFilter extends core_util_1.Filter {
|
|
44
44
|
gcpOidc;
|
|
45
45
|
secrets;
|
|
46
|
-
|
|
46
|
+
vendorAuthMinter;
|
|
47
47
|
constructor(gcpOidc,
|
|
48
48
|
/** Only sharedSecret(...) endpoints need it; a server that has none binds nothing. */
|
|
49
49
|
secrets,
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* The OUTBOUND role only. Only vendorAuth(...) calls need it, and an unbound one makes them
|
|
52
|
+
* THROW. Never the inbound VendorAuthVerifier: sending a request verifies nothing (#1358).
|
|
53
|
+
*/
|
|
54
|
+
vendorAuthMinter) {
|
|
52
55
|
super();
|
|
53
56
|
this.gcpOidc = gcpOidc;
|
|
54
57
|
this.secrets = secrets;
|
|
55
|
-
this.
|
|
58
|
+
this.vendorAuthMinter = vendorAuthMinter;
|
|
56
59
|
}
|
|
57
60
|
/** Requests that already spent their one refresh — keyed by the request, so redirect hops share it. */
|
|
58
61
|
refreshed = new WeakSet();
|
|
@@ -69,7 +72,7 @@ class OutboundAuthFilter extends core_util_1.Filter {
|
|
|
69
72
|
this.refreshed.add(request);
|
|
70
73
|
// The 401's body is never read: release the connection before the second attempt.
|
|
71
74
|
await response.body?.cancel();
|
|
72
|
-
await this.
|
|
75
|
+
await this.vendorAuthMinter.refresh(mode.name);
|
|
73
76
|
await this.mintVendorAuth(request, mode.name);
|
|
74
77
|
return nextFilter.invoke(request);
|
|
75
78
|
}
|
|
@@ -103,22 +106,23 @@ class OutboundAuthFilter extends core_util_1.Filter {
|
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
106
|
-
* @throws
|
|
107
|
-
* matching the inbound side exactly: an unbound
|
|
108
|
-
* endpoint rather than admitting it unverified, so
|
|
109
|
-
* deliver something the vendor is obliged to reject.
|
|
109
|
+
* @throws MissingVendorAuthMinterError when no {@link VendorAuthMinter} is bound. FAIL CLOSED,
|
|
110
|
+
* matching the inbound side exactly: an unbound verifier 401s every served
|
|
111
|
+
* `vendorAuth(...)` endpoint rather than admitting it unverified, so an unbound minter
|
|
112
|
+
* must also refuse to SEND rather than deliver something the vendor is obliged to reject.
|
|
110
113
|
*/
|
|
111
114
|
async mintVendorAuth(request, name) {
|
|
112
|
-
if (this.
|
|
113
|
-
throw new OutboundAuthErrors_1.
|
|
114
|
-
`client must present ${name}'s credential — but no
|
|
115
|
-
`nothing to mint it. Bind
|
|
116
|
-
`
|
|
115
|
+
if (this.vendorAuthMinter === undefined) {
|
|
116
|
+
throw new OutboundAuthErrors_1.MissingVendorAuthMinterError(`${request.contractName}.${request.route.methodName} is vendorAuth('${name}'), so this ` +
|
|
117
|
+
`client must present ${name}'s credential — but no VendorAuthMinter is bound, so there ` +
|
|
118
|
+
`is nothing to mint it. Bind the OUTBOUND role in this process:\n` +
|
|
119
|
+
` binder.bind(VENDOR_AUTH_MINTER).to(MyVendorAuthMinter).inSingletonScope();\n` +
|
|
120
|
+
`(A VENDOR_AUTH_VERIFIER binding does not count: it verifies inbound calls and never sends.)\n` +
|
|
117
121
|
`Refusing to send is deliberate: an unauthenticated call is one the vendor will reject, ` +
|
|
118
122
|
`and sending it anyway would hide the missing binding until they complained.`, `${request.contractName}.${request.route.methodName}`, name);
|
|
119
123
|
}
|
|
120
124
|
const signable = new core_context_1.SignableRequest(request.url, request.route.httpMethod, request.body, request.headers, request.contractName, request.route.methodName);
|
|
121
|
-
const minted = await this.
|
|
125
|
+
const minted = await this.vendorAuthMinter.mint(name, signable);
|
|
122
126
|
for (const entry of minted.entries()) {
|
|
123
127
|
request.headers.set(entry[0], entry[1]);
|
|
124
128
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutboundAuthFilter.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/OutboundAuthFilter.ts"],"names":[],"mappings":";;;AAAA,oDAAiF;AACjF,0DAA0E;AAG1E,6DAA4F;AAE5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAa,kBAAmB,SAAQ,kBAA+B;IAE9C;IAEA;IAEA;IALrB,YACqB,OAAgB;IACjC,sFAAsF;IACrE,OAA4B;IAC7C,mFAAmF;IAClE,cAA0C;QAE3D,KAAK,EAAE,CAAC;QANS,YAAO,GAAP,OAAO,CAAS;QAEhB,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAA4B;IAG/D,CAAC;IAED,uGAAuG;IACtF,SAAS,GAAG,IAAI,OAAO,EAAiB,CAAC;IAEjD,KAAK,CAAC,MAAM,CACjB,OAAsB,EACtB,UAA4C;QAE5C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAChD,IACI,QAAQ,CAAC,MAAM,KAAK,GAAG;YACvB,IAAI,EAAE,IAAI,KAAK,YAAY;YAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC;YAC3B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAC9B,CAAC;YACC,OAAO,QAAQ,CAAC;QACpB,CAAC;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,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YACnC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ;AA3GD,gDA2GC","sourcesContent":["import { Filter, Secrets, Service, StreamDirection } from '@webpieces/core-util';\nimport { SignableRequest, VendorAuthHook } from '@webpieces/core-context';\nimport { GcpOidc } from '@webpieces/gcp-identity';\nimport { ClientRequest } from '@webpieces/http-client-core';\nimport { MissingSharedSecretError, MissingVendorAuthHookError } from './OutboundAuthErrors';\n\n/**\n * Attaches the endpoint's outbound credential, against the destination the call is ACTUALLY going\n * to.\n *\n * ## Why this is a filter, and why it is the LAST one\n *\n * It used to be a method on the client, called before the request object even existed — so it\n * minted against the URL the client resolved at bind time, which is the URL BEFORE any filter had\n * run. That is wrong the moment a filter can re-point the request: an OIDC token's audience is the\n * callee's base URL, and a token minted for our own service name and then sent to a partner's\n * server is a credential handed to the wrong party.\n *\n * As the innermost filter (`ProxyClient.initRoutes` puts the framework's built-ins beneath every app\n * filter, and no app priority can get under them) it reads `request.baseUrl` / `request.url` after\n * everything has settled, which makes the audience correct by construction rather than by\n * convention. The SSRF guard sits immediately ABOVE it, so a destination that is going to be refused\n * is refused BEFORE any credential is minted for it.\n *\n * ## The three modes, and why none of them is restricted to a fixed host\n *\n * - `oidcSameProject()` / `oidcSvcs(...)` → a bearer token minted as this caller's runtime SA, audience = the final base URL.\n * - `sharedSecret(...)` → the value this client holds for that key, as `Authorization: Webpieces …`.\n * Legitimate against a re-pointed URL: N services implementing ONE contract behind ONE agreed\n * secret is a real and common topology, and often stands in for OIDC where OIDC is not available.\n * - `vendorAuth(name)` → the app's bound {@link VendorAuthHook} `mint`s the headers (a vendor's\n * OAuth bearer, a partner's HMAC signature — the scheme is the app's). On a raw `401` it is the ONE\n * mode that retries: cancel the 401's body, `refresh(name)` once, `mint` again and re-send ONCE.\n * Never for a streaming upload (its body cannot be replayed), and once per logical call — the SSRF\n * guard's redirect loop re-enters this filter for each hop, and a second 401 goes up the chain to\n * `ClientErrorTranslator` exactly as before, because a service that cannot log in to its vendor\n * twice running is a bug in THAT service.\n *\n * Both credential-minting modes ride in the ONE `Authorization` header under their own scheme —\n * `Bearer <oidc>` / `Webpieces <secret>` — which is never a context key, so neither can leak onto\n * the next hop.\n */\nexport class OutboundAuthFilter extends Filter<ClientRequest, Response> {\n constructor(\n private readonly gcpOidc: GcpOidc,\n /** Only sharedSecret(...) endpoints need it; a server that has none binds nothing. */\n private readonly secrets: Secrets | undefined,\n /** Only vendorAuth(...) endpoints need it, and an unbound one makes them THROW. */\n private readonly vendorAuthHook: VendorAuthHook | undefined,\n ) {\n super();\n }\n\n /** Requests that already spent their one refresh — keyed by the request, so redirect hops share it. */\n private readonly refreshed = new WeakSet<ClientRequest>();\n\n override async filter(\n request: ClientRequest,\n nextFilter: Service<ClientRequest, Response>,\n ): Promise<Response> {\n await this.attach(request);\n const response = await nextFilter.invoke(request);\n const mode = request.route.authMeta?.methods[0];\n if (\n response.status !== 401 ||\n mode?.kind !== 'vendorAuth' ||\n this.refreshed.has(request) ||\n this.uploadsAStream(request)\n ) {\n return response;\n }\n this.refreshed.add(request);\n // The 401's body is never read: release the connection before the second attempt.\n await response.body?.cancel();\n await this.vendorAuthHook!.refresh(mode.name);\n await this.mintVendorAuth(request, mode.name);\n return nextFilter.invoke(request);\n }\n\n /** A request-streaming call's body is a one-shot stream, so it can never be re-sent. */\n private uploadsAStream(request: ClientRequest): boolean {\n const streaming = request.route.streaming;\n return streaming !== undefined && streaming.direction !== StreamDirection.RESPONSE;\n }\n\n private async attach(request: ClientRequest): Promise<void> {\n const mode = request.route.authMeta?.methods[0];\n if (mode?.kind === 'oidc') {\n request.headers.set(\n 'Authorization',\n `Bearer ${await this.gcpOidc.mintIdToken(request.baseUrl)}`,\n );\n return;\n }\n if (mode?.kind === 'shared-secret') {\n const secret = this.secrets?.get(mode.secretKey);\n if (!secret) {\n throw new MissingSharedSecretError(\n `${request.contractName}.${request.route.methodName} is ` +\n `sharedSecret('${mode.secretKey}'), but this client's bound Secrets holds no ` +\n `value for that key, so there is no credential to send. Bind a Secrets carrying ` +\n `'${mode.secretKey}'. Refusing to send is deliberate: the callee is obliged to 401 an ` +\n `unauthenticated request, so sending it would report as the peer's failure.`,\n `${request.contractName}.${request.route.methodName}`,\n mode.secretKey,\n );\n }\n // Same header as a JWT/OIDC token, but its OWN scheme, so a secret can never be\n // mistaken for a token nor accepted where one was expected.\n request.headers.set('Authorization', `Webpieces ${secret}`);\n return;\n }\n if (mode?.kind === 'vendorAuth') {\n await this.mintVendorAuth(request, mode.name);\n }\n }\n\n /**\n * @throws MissingVendorAuthHookError when no {@link VendorAuthHook} is bound. FAIL CLOSED,\n * matching the inbound side exactly: an unbound hook 401s every served `vendorAuth(...)`\n * endpoint rather than admitting it unverified, so it must also refuse to SEND rather than\n * deliver something the vendor is obliged to reject.\n */\n private async mintVendorAuth(request: ClientRequest, name: string): Promise<void> {\n if (this.vendorAuthHook === undefined) {\n throw new MissingVendorAuthHookError(\n `${request.contractName}.${request.route.methodName} is vendorAuth('${name}'), so this ` +\n `client must present ${name}'s credential — but no VendorAuthHook is bound, so there is ` +\n `nothing to mint it. Bind one:\\n` +\n ` options.bind(VENDOR_AUTH_HOOK).to(MyVendorAuthHook);\\n` +\n `Refusing to send is deliberate: an unauthenticated call is one the vendor will reject, ` +\n `and sending it anyway would hide the missing binding until they complained.`,\n `${request.contractName}.${request.route.methodName}`,\n name,\n );\n }\n const signable = new SignableRequest(\n request.url,\n request.route.httpMethod,\n request.body,\n request.headers,\n request.contractName,\n request.route.methodName,\n );\n const minted = await this.vendorAuthHook.mint(name, signable);\n for (const entry of minted.entries()) {\n request.headers.set(entry[0], entry[1]);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OutboundAuthFilter.js","sourceRoot":"","sources":["../../../../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reamDirection } from '@webpieces/core-util';\nimport { SignableRequest, VendorAuthMinter } from '@webpieces/core-context';\nimport { GcpOidc } from '@webpieces/gcp-identity';\nimport { ClientRequest } from '@webpieces/http-client-core';\nimport { MissingSharedSecretError, MissingVendorAuthMinterError } from './OutboundAuthErrors';\n\n/**\n * Attaches the endpoint's outbound credential, against the destination the call is ACTUALLY going\n * to.\n *\n * ## Why this is a filter, and why it is the LAST one\n *\n * It used to be a method on the client, called before the request object even existed — so it\n * minted against the URL the client resolved at bind time, which is the URL BEFORE any filter had\n * run. That is wrong the moment a filter can re-point the request: an OIDC token's audience is the\n * callee's base URL, and a token minted for our own service name and then sent to a partner's\n * server is a credential handed to the wrong party.\n *\n * As the innermost filter (`ProxyClient.initRoutes` puts the framework's built-ins beneath every app\n * filter, and no app priority can get under them) it reads `request.baseUrl` / `request.url` after\n * everything has settled, which makes the audience correct by construction rather than by\n * convention. The SSRF guard sits immediately ABOVE it, so a destination that is going to be refused\n * is refused BEFORE any credential is minted for it.\n *\n * ## The three modes, and why none of them is restricted to a fixed host\n *\n * - `oidcSameProject()` / `oidcSvcs(...)` → a bearer token minted as this caller's runtime SA, audience = the final base URL.\n * - `sharedSecret(...)` → the value this client holds for that key, as `Authorization: Webpieces …`.\n * Legitimate against a re-pointed URL: N services implementing ONE contract behind ONE agreed\n * secret is a real and common topology, and often stands in for OIDC where OIDC is not available.\n * - `vendorAuth(name)` → the app's bound {@link VendorAuthMinter} `mint`s the headers (a vendor's\n * OAuth bearer, a partner's HMAC signature — the scheme is the app's). On a raw `401` it is the ONE\n * mode that retries: cancel the 401's body, `refresh(name)` once, `mint` again and re-send ONCE.\n * Never for a streaming upload (its body cannot be replayed), and once per logical call — the SSRF\n * guard's redirect loop re-enters this filter for each hop, and a second 401 goes up the chain to\n * `ClientErrorTranslator` exactly as before, because a service that cannot log in to its vendor\n * twice running is a bug in THAT service.\n *\n * Both credential-minting modes ride in the ONE `Authorization` header under their own scheme —\n * `Bearer <oidc>` / `Webpieces <secret>` — which is never a context key, so neither can leak onto\n * the next hop.\n */\nexport class OutboundAuthFilter extends Filter<ClientRequest, Response> {\n constructor(\n private readonly gcpOidc: GcpOidc,\n /** Only sharedSecret(...) endpoints need it; a server that has none binds nothing. */\n private readonly secrets: Secrets | undefined,\n /**\n * The OUTBOUND role only. Only vendorAuth(...) calls need it, and an unbound one makes them\n * THROW. Never the inbound VendorAuthVerifier: sending a request verifies nothing (#1358).\n */\n private readonly vendorAuthMinter: VendorAuthMinter | undefined,\n ) {\n super();\n }\n\n /** Requests that already spent their one refresh — keyed by the request, so redirect hops share it. */\n private readonly refreshed = new WeakSet<ClientRequest>();\n\n override async filter(\n request: ClientRequest,\n nextFilter: Service<ClientRequest, Response>,\n ): Promise<Response> {\n await this.attach(request);\n const response = await nextFilter.invoke(request);\n const mode = request.route.authMeta?.methods[0];\n if (\n response.status !== 401 ||\n mode?.kind !== 'vendorAuth' ||\n this.refreshed.has(request) ||\n this.uploadsAStream(request)\n ) {\n return response;\n }\n this.refreshed.add(request);\n // The 401's body is never read: release the connection before the second attempt.\n await response.body?.cancel();\n await this.vendorAuthMinter!.refresh(mode.name);\n await this.mintVendorAuth(request, mode.name);\n return nextFilter.invoke(request);\n }\n\n /** A request-streaming call's body is a one-shot stream, so it can never be re-sent. */\n private uploadsAStream(request: ClientRequest): boolean {\n const streaming = request.route.streaming;\n return streaming !== undefined && streaming.direction !== StreamDirection.RESPONSE;\n }\n\n private async attach(request: ClientRequest): Promise<void> {\n const mode = request.route.authMeta?.methods[0];\n if (mode?.kind === 'oidc') {\n request.headers.set(\n 'Authorization',\n `Bearer ${await this.gcpOidc.mintIdToken(request.baseUrl)}`,\n );\n return;\n }\n if (mode?.kind === 'shared-secret') {\n const secret = this.secrets?.get(mode.secretKey);\n if (!secret) {\n throw new MissingSharedSecretError(\n `${request.contractName}.${request.route.methodName} is ` +\n `sharedSecret('${mode.secretKey}'), but this client's bound Secrets holds no ` +\n `value for that key, so there is no credential to send. Bind a Secrets carrying ` +\n `'${mode.secretKey}'. Refusing to send is deliberate: the callee is obliged to 401 an ` +\n `unauthenticated request, so sending it would report as the peer's failure.`,\n `${request.contractName}.${request.route.methodName}`,\n mode.secretKey,\n );\n }\n // Same header as a JWT/OIDC token, but its OWN scheme, so a secret can never be\n // mistaken for a token nor accepted where one was expected.\n request.headers.set('Authorization', `Webpieces ${secret}`);\n return;\n }\n if (mode?.kind === 'vendorAuth') {\n await this.mintVendorAuth(request, mode.name);\n }\n }\n\n /**\n * @throws MissingVendorAuthMinterError when no {@link VendorAuthMinter} is bound. FAIL CLOSED,\n * matching the inbound side exactly: an unbound verifier 401s every served\n * `vendorAuth(...)` endpoint rather than admitting it unverified, so an unbound minter\n * must also refuse to SEND rather than deliver something the vendor is obliged to reject.\n */\n private async mintVendorAuth(request: ClientRequest, name: string): Promise<void> {\n if (this.vendorAuthMinter === undefined) {\n throw new MissingVendorAuthMinterError(\n `${request.contractName}.${request.route.methodName} is vendorAuth('${name}'), so this ` +\n `client must present ${name}'s credential — but no VendorAuthMinter is bound, so there ` +\n `is nothing to mint it. Bind the OUTBOUND role in this process:\\n` +\n ` binder.bind(VENDOR_AUTH_MINTER).to(MyVendorAuthMinter).inSingletonScope();\\n` +\n `(A VENDOR_AUTH_VERIFIER binding does not count: it verifies inbound calls and never sends.)\\n` +\n `Refusing to send is deliberate: an unauthenticated call is one the vendor will reject, ` +\n `and sending it anyway would hide the missing binding until they complained.`,\n `${request.contractName}.${request.route.methodName}`,\n name,\n );\n }\n const signable = new SignableRequest(\n request.url,\n request.route.httpMethod,\n request.body,\n request.headers,\n request.contractName,\n request.route.methodName,\n );\n const minted = await this.vendorAuthMinter.mint(name, signable);\n for (const entry of minted.entries()) {\n request.headers.set(entry[0], entry[1]);\n }\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -30,8 +30,8 @@ export { ClientRole } from '@webpieces/core-util';
|
|
|
30
30
|
export { ContextBaseUrlFilter } from './ContextBaseUrlFilter';
|
|
31
31
|
export { ContextFullUrlFilter } from './ContextFullUrlFilter';
|
|
32
32
|
export { MissingRuntimeBaseUrlError } from './MissingRuntimeBaseUrlError';
|
|
33
|
-
export { MissingSharedSecretError,
|
|
34
|
-
export {
|
|
33
|
+
export { MissingSharedSecretError, MissingVendorAuthMinterError } from './OutboundAuthErrors';
|
|
34
|
+
export { VendorAuthMinter, VENDOR_AUTH_MINTER, SignableRequest } from '@webpieces/core-context';
|
|
35
35
|
export { SsrfPolicy, SsrfTestingPolicy } from './SsrfPolicy';
|
|
36
36
|
export { SsrfGuardFilter } from './SsrfGuardFilter';
|
|
37
37
|
export { SsrfRefusedError } from './SsrfRefusedError';
|
package/src/index.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.WiringPolicy = exports.StreamingCapabilityError = exports.ClientFilterDefinition = exports.ClientRequest = exports.ClientErrorTranslator = exports.ProxyClient = exports.DnsAddressResolver = exports.AddressResolver = exports.InternalAddressRules = exports.OutboundAuthFilter = exports.SsrfRefusedError = exports.SsrfGuardFilter = exports.SsrfTestingPolicy = exports.SsrfPolicy = exports.SignableRequest = exports.
|
|
28
|
+
exports.WiringPolicy = exports.StreamingCapabilityError = exports.ClientFilterDefinition = exports.ClientRequest = exports.ClientErrorTranslator = exports.ProxyClient = exports.DnsAddressResolver = exports.AddressResolver = exports.InternalAddressRules = exports.OutboundAuthFilter = exports.SsrfRefusedError = exports.SsrfGuardFilter = exports.SsrfTestingPolicy = exports.SsrfPolicy = exports.SignableRequest = exports.VENDOR_AUTH_MINTER = exports.VendorAuthMinter = exports.MissingVendorAuthMinterError = exports.MissingSharedSecretError = exports.MissingRuntimeBaseUrlError = exports.ContextFullUrlFilter = exports.ContextBaseUrlFilter = exports.ClientRole = exports.ClientConfig = exports.NODE_PROXY_CLIENT_PROVIDER = exports.NodeProxyClient = exports.ClientHttpFactory = void 0;
|
|
29
29
|
var ClientHttpFactory_1 = require("./ClientHttpFactory");
|
|
30
30
|
Object.defineProperty(exports, "ClientHttpFactory", { enumerable: true, get: function () { return ClientHttpFactory_1.ClientHttpFactory; } });
|
|
31
31
|
var NodeProxyClient_1 = require("./NodeProxyClient");
|
|
@@ -51,13 +51,14 @@ Object.defineProperty(exports, "MissingRuntimeBaseUrlError", { enumerable: true,
|
|
|
51
51
|
// hostile' (SsrfRefusedError) without matching message text.
|
|
52
52
|
var OutboundAuthErrors_1 = require("./OutboundAuthErrors");
|
|
53
53
|
Object.defineProperty(exports, "MissingSharedSecretError", { enumerable: true, get: function () { return OutboundAuthErrors_1.MissingSharedSecretError; } });
|
|
54
|
-
Object.defineProperty(exports, "
|
|
55
|
-
// vendorAuth(name):
|
|
56
|
-
// Defined in @webpieces/core-context; bind
|
|
57
|
-
// than sending unauthenticated.
|
|
54
|
+
Object.defineProperty(exports, "MissingVendorAuthMinterError", { enumerable: true, get: function () { return OutboundAuthErrors_1.MissingVendorAuthMinterError; } });
|
|
55
|
+
// vendorAuth(name), OUTBOUND role: the minter mints (and refreshes once on a 401) what this client
|
|
56
|
+
// sends. Defined in @webpieces/core-context; bind VENDOR_AUTH_MINTER, or every outbound
|
|
57
|
+
// vendorAuth(...) call throws rather than sending unauthenticated. The INBOUND VendorAuthVerifier is
|
|
58
|
+
// http-routing's, and no client ever depends on it (#1358).
|
|
58
59
|
var core_context_1 = require("@webpieces/core-context");
|
|
59
|
-
Object.defineProperty(exports, "
|
|
60
|
-
Object.defineProperty(exports, "
|
|
60
|
+
Object.defineProperty(exports, "VendorAuthMinter", { enumerable: true, get: function () { return core_context_1.VendorAuthMinter; } });
|
|
61
|
+
Object.defineProperty(exports, "VENDOR_AUTH_MINTER", { enumerable: true, get: function () { return core_context_1.VENDOR_AUTH_MINTER; } });
|
|
61
62
|
Object.defineProperty(exports, "SignableRequest", { enumerable: true, get: function () { return core_context_1.SignableRequest; } });
|
|
62
63
|
// The SSRF policy a re-pointed URL is judged under, and the refusal it produces. Automatic, armed by
|
|
63
64
|
// the ACT of re-pointing; the ONLY way to relax it is naming SsrfTestingPolicy at a call site.
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAEH,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAC1B,qDAAgF;AAAvE,kHAAA,eAAe,OAAA;AAAE,6HAAA,0BAA0B,OAAA;AACpD,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,8FAA8F;AAC9F,kDAAkD;AAAzC,uGAAA,UAAU,OAAA;AAEnB,kGAAkG;AAClG,4DAA4D;AAC5D,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,kGAAkG;AAClG,4EAA4E;AAC5E,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,2EAA0E;AAAjE,wIAAA,0BAA0B,OAAA;AAEnC,mGAAmG;AACnG,kGAAkG;AAClG,6DAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAEH,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAC1B,qDAAgF;AAAvE,kHAAA,eAAe,OAAA;AAAE,6HAAA,0BAA0B,OAAA;AACpD,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,8FAA8F;AAC9F,kDAAkD;AAAzC,uGAAA,UAAU,OAAA;AAEnB,kGAAkG;AAClG,4DAA4D;AAC5D,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,kGAAkG;AAClG,4EAA4E;AAC5E,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,2EAA0E;AAAjE,wIAAA,0BAA0B,OAAA;AAEnC,mGAAmG;AACnG,kGAAkG;AAClG,6DAA6D;AAC7D,2DAA8F;AAArF,8HAAA,wBAAwB,OAAA;AAAE,kIAAA,4BAA4B,OAAA;AAE/D,mGAAmG;AACnG,wFAAwF;AACxF,qGAAqG;AACrG,4DAA4D;AAC5D,wDAAgG;AAAvF,gHAAA,gBAAgB,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AAAE,+GAAA,eAAe,OAAA;AAE9D,qGAAqG;AACrG,+FAA+F;AAC/F,2CAA6D;AAApD,wGAAA,UAAU,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AACtC,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,qDAAwE;AAA/D,kHAAA,eAAe,OAAA;AAAE,qHAAA,kBAAkB,OAAA;AAE5C,uEAAuE;AACvE,gEAAiF;AAAxE,+GAAA,WAAW,OAAA;AAAE,yHAAA,qBAAqB,OAAA;AAC3C,gEAAoF;AAA3E,iHAAA,aAAa,OAAA;AAAE,0HAAA,sBAAsB,OAAA;AAG9C,gEAAuE;AAA9D,4HAAA,wBAAwB,OAAA;AAEjC,gEAA2D;AAAlD,gHAAA,YAAY,OAAA","sourcesContent":["/**\n * @webpieces/http-client-node\n *\n * The SERVER-side HTTP client. Reads an API contract's decorators and generates type-safe HTTP\n * clients from it — the same contract the callee's controller implements.\n *\n * Node-only, so unlike @webpieces/http-client-browser it is fully inversify-wired and reads the\n * magic context straight out of the AsyncLocalStorage-backed RequestContext. There is no\n * ContextReader indirection, because a server has exactly one right answer, and a call made\n * OUTSIDE `RequestContext.run(...)` throws instead of silently dropping the trace.\n *\n * Usage:\n * ```typescript\n * import { ClientHttpFactory, ClientConfig } from '@webpieces/http-client-node';\n *\n * // inject the factory, then one client per contract\n * const server2 = factory.createRpcClient(Server2Api, new ClientConfig('server2', ClientRole.SERVER));\n * const response = await server2.fetchValue(req);\n *\n * // a client whose destination arrives per call: ONE filter, and nothing else changes\n * const partner = factory.createRpcClient(PartnerWebhookApi, new ClientConfig('partner-webhooks', ClientRole.SERVER), [\n * new ClientFilterDefinition(1000, new ContextFullUrlFilter()),\n * ]);\n * ```\n */\n\nexport { ClientHttpFactory } from './ClientHttpFactory';\nexport { NodeProxyClient, NODE_PROXY_CLIENT_PROVIDER } from './NodeProxyClient';\nexport { ClientConfig } from './ClientConfig';\n// ClientConfig's required `role` argument, re-exported so a client is set up from one import.\nexport { ClientRole } from '@webpieces/core-util';\n\n// Install this on the ONE client whose destination is data. Installing it IS the opt-in; a client\n// without it ignores an ambient OVERRIDE_BASE_URL entirely.\nexport { ContextBaseUrlFilter } from './ContextBaseUrlFilter';\n// The same opt-in for a COMPLETE stored url (host + path + query), sent verbatim with no contract\n// path appended — the usual partner-webhook shape. Reads OVERRIDE_FULL_URL.\nexport { ContextFullUrlFilter } from './ContextFullUrlFilter';\nexport { MissingRuntimeBaseUrlError } from './MissingRuntimeBaseUrlError';\n\n// The two ways outbound auth refuses to send: a binding a contract's auth mode requires is absent.\n// Typed, so a delivery worker tells 'we are misconfigured' from 'the partner registered something\n// hostile' (SsrfRefusedError) without matching message text.\nexport { MissingSharedSecretError, MissingVendorAuthMinterError } from './OutboundAuthErrors';\n\n// vendorAuth(name), OUTBOUND role: the minter mints (and refreshes once on a 401) what this client\n// sends. Defined in @webpieces/core-context; bind VENDOR_AUTH_MINTER, or every outbound\n// vendorAuth(...) call throws rather than sending unauthenticated. The INBOUND VendorAuthVerifier is\n// http-routing's, and no client ever depends on it (#1358).\nexport { VendorAuthMinter, VENDOR_AUTH_MINTER, SignableRequest } from '@webpieces/core-context';\n\n// The SSRF policy a re-pointed URL is judged under, and the refusal it produces. Automatic, armed by\n// the ACT of re-pointing; the ONLY way to relax it is naming SsrfTestingPolicy at a call site.\nexport { SsrfPolicy, SsrfTestingPolicy } from './SsrfPolicy';\nexport { SsrfGuardFilter } from './SsrfGuardFilter';\nexport { SsrfRefusedError } from './SsrfRefusedError';\nexport { OutboundAuthFilter } from './OutboundAuthFilter';\nexport { InternalAddressRules } from './InternalAddressRules';\nexport { AddressResolver, DnsAddressResolver } from './AddressResolver';\n\n// The isomorphic engine, re-exported so a server app needs one import.\nexport { ProxyClient, ClientErrorTranslator } from '@webpieces/http-client-core';\nexport { ClientRequest, ClientFilterDefinition } from '@webpieces/http-client-core';\nexport type { ClientFilter } from '@webpieces/http-client-core';\nexport type { ApiPrototype } from '@webpieces/http-client-core';\nexport { StreamingCapabilityError } from '@webpieces/http-client-core';\n\nexport { WiringPolicy } from '@webpieces/http-client-core';\n"]}
|