@webpieces/http-client-node 0.4.698 → 0.4.700
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 +75 -1
- package/package.json +5 -5
- package/src/AddressResolver.d.ts +23 -0
- package/src/AddressResolver.js +29 -0
- package/src/AddressResolver.js.map +1 -0
- package/src/ClientConfig.d.ts +41 -11
- package/src/ClientConfig.js +24 -7
- package/src/ClientConfig.js.map +1 -1
- package/src/ClientHttpFactory.d.ts +21 -4
- package/src/ClientHttpFactory.js +21 -5
- package/src/ClientHttpFactory.js.map +1 -1
- package/src/ContextBaseUrlOverrideFilter.d.ts +38 -0
- package/src/ContextBaseUrlOverrideFilter.js +57 -0
- package/src/ContextBaseUrlOverrideFilter.js.map +1 -0
- package/src/HostPolicy.d.ts +118 -0
- package/src/HostPolicy.js +169 -0
- package/src/HostPolicy.js.map +1 -0
- package/src/InternalAddressRules.d.ts +37 -0
- package/src/InternalAddressRules.js +132 -0
- package/src/InternalAddressRules.js.map +1 -0
- package/src/NodeProxyClient.d.ts +24 -6
- package/src/NodeProxyClient.js +30 -8
- package/src/NodeProxyClient.js.map +1 -1
- package/src/RuntimeHostErrors.d.ts +42 -0
- package/src/RuntimeHostErrors.js +54 -0
- package/src/RuntimeHostErrors.js.map +1 -0
- package/src/SsrfGuardFilter.d.ts +50 -0
- package/src/SsrfGuardFilter.js +146 -0
- package/src/SsrfGuardFilter.js.map +1 -0
- package/src/SsrfPolicy.d.ts +64 -0
- package/src/SsrfPolicy.js +52 -0
- package/src/SsrfPolicy.js.map +1 -0
- package/src/SsrfRefusedError.d.ts +20 -0
- package/src/SsrfRefusedError.js +28 -0
- package/src/SsrfRefusedError.js.map +1 -0
- package/src/index.d.ts +15 -1
- package/src/index.js +38 -2
- package/src/index.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/NodeProxyClient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,CAAA;IAGf,mBAAA,IAAA,oBAAQ,GAAE,CAAA;IAAE,mBAAA,IAAA,kBAAM,EAAC,mBAAO,CAAC,CAAA;6CAL6B,oCAAqB;QAEnC,sBAAO;QAGM,mBAAO;GAV1D,eAAe,CAiM3B;AAED;;;;;;;GAOG;AACH,gGAAgG;AACnF,QAAA,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC","sourcesContent":["import { inject, optional } from 'inversify';\nimport {\n AuthMeta,\n ClientRegistry,\n DestinationTrust,\n HttpInternalServerError,\n RecordedEndpoint,\n RecordedError,\n RouteMetadata,\n Secrets,\n SECRETS,\n TestCaseRecorder,\n toError,\n} from '@webpieces/core-util';\nimport { RequestContext, RequestContextHeaders, provideFrameworkTransient } from '@webpieces/core-context';\nimport { GcpOidc } from '@webpieces/gcp-identity';\nimport { ApiPrototype, ProxyClient, TranslatedFailure } from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\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 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 // @optional: only @AuthSharedSecret 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 ) {\n super();\n }\n\n /** Bind this client to one API contract + target. */\n init(apiPrototype: ApiPrototype<object>, config: ClientConfig): void {\n this.config = config;\n this.initRoutes(apiPrototype);\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 resolveBaseUrl(): Promise<string> {\n return ClientRegistry.resolve(this.config.svcName);\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 (@AuthOidc /\n * @AuthSharedSecret). Calling a peer's @Public or @AuthJwt 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 * Attach the outbound credential for the endpoint's AuthMode: an @AuthOidc bearer minted as\n * this caller's runtime SA (audience = the callee base URL — the server verifies the signature\n * + caller allow-list), or the @AuthSharedSecret(key) value THIS client sends from its bound\n * {@link Secrets}. Both ride in the ONE `Authorization` header under their own scheme —\n * `Bearer <oidc>` / `Webpieces <secret>` — which is never a context key, so it cannot leak onto\n * the next hop. Never reads process.env.\n */\n protected override async attachOutboundAuth(\n route: RouteMetadata,\n baseUrl: string,\n httpHeaders: Record<string, string>,\n ): Promise<void> {\n const mode = route.authMeta?.mode;\n if (mode?.kind === 'oidc') {\n httpHeaders['Authorization'] = `Bearer ${await this.gcpOidc.mintIdToken(baseUrl)}`;\n } else if (mode?.kind === 'shared-secret') {\n const secret = this.secrets?.get(mode.secretKey);\n if (!secret) {\n throw new Error(\n `No shared secret configured for @AuthSharedSecret('${mode.secretKey}') endpoint ${route.methodName}`,\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 httpHeaders['Authorization'] = `Webpieces ${secret}`;\n }\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 // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n ): Promise<unknown> {\n const recorder = this.headers.findRecorder();\n if (!recorder) {\n return super.execute(route, requestDto, method);\n }\n return this.recordCall(recorder, route, requestDto, method);\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 // 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(this.contractName(), route.methodName, [requestDto], ctxSnapshot);\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);\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 /** A server can satisfy every auth mode, so nothing is rejected at bind time. */\n protected override assertEndpointSupported(_authMeta: AuthMeta | undefined, _methodName: string): void {}\n\n /**\n * SERVER-TO-SERVER: a 4xx received from a dependency becomes THIS server's own 500.\n *\n * THE INVARIANT:\n *\n * A status received from a downstream dependency describes OUR request to it. It is never the\n * status we return to OUR caller. The server that answered 404 is correct; the server that\n * asked for a route that does not exist is broken, and must say so as a 500.\n *\n * Every 4xx is a CALLER-side defect on this hop: 404 = wrong path / wrong base URL / a dependency\n * that is not deployed yet, 400 = we sent a malformed request, 401/403 = our service credentials\n * or the callee's caller allow-list are wrong. None of them is an answer for whoever called US, and\n * relaying one lets an internal misconfiguration impersonate a legitimate response. That is not\n * hypothetical: a partner-facing Management API reported an EMPTY store estate for an org with six\n * live storefronts, because its dependency had not been promoted and Express served an HTML 404\n * which arrived here as `HttpNotFoundError` and went straight back out. A 500 would have been\n * loud, correct, and attributable to the one server that actually had the bug — which is the whole\n * point: only ONE server should be paged for this.\n *\n * DELIBERATELY 4xx ONLY. 5xx (502/503/504) already mean \"the dependency is unavailable\", which is\n * honest and useful outward, and 500 is already a 500. `HttpUserError` (266, a 2xx code carrying\n * user validation) and `HttpVendorError` (598) are not statuses about our request at all. All of\n * them pass through untouched.\n *\n * THE OPT-OUT IS `appRegistered`, not a config key. A thin proxy or gateway that genuinely wants to\n * relay a downstream status as its own registers a `ClientRegistry` error translation for it at\n * startup — one greppable line saying so out loud — and that translation wins here. Only the\n * framework's built-in default mapping gets wrapped. There is no flag, because a flag would make\n * the dangerous choice invisible in the code that suffers from it.\n *\n * The downstream diagnostic is NOT lost: the original error (which for the incident above names the\n * method, the status, the `text/html` content-type and a snippet of the body) is both quoted in the\n * message and kept as `httpCause`.\n *\n * How much \"Downstream said:\" is worth depends on WHO answered, and both halves are by design:\n * - a NON-webpieces answer (an lb's html 404, a proxy's plain-text 502) is described CLIENT-side by\n * `ResponseBodyReader.describeForeignBody`, so the full diagnostic is ours to quote — this is the\n * mealco incident's exact shape, and it is the case that mattered.\n * - a WEBPIECES peer deliberately sends only the generic reason phrase for its status (see\n * `HttpErrorWireMapper` in http-server — only `HttpUserError`'s message is caller-facing), so this\n * reads \"Downstream said: Not Found\". That is correct and not a regression: the peer's real\n * message is in the PEER's log, correlated by request id, which is the only place it was ever\n * safe to read it.\n *\n * This whole string is an operator-facing message on an `HttpInternalServerError`, so when THIS\n * server answers its own caller none of it goes on the wire — it goes to this server's log.\n */\n protected override adaptDownstreamFailure(failure: TranslatedFailure, callId: string): Error {\n if (failure.appRegistered) {\n return failure.error;\n }\n if (failure.statusCode < 400 || failure.statusCode >= 500) {\n return failure.error;\n }\n return new HttpInternalServerError(\n `${callId}: dependency answered HTTP ${failure.statusCode}. That status describes OUR ` +\n `request to it, not an answer for our caller, so this server owns it as a 500 — check the ` +\n `path, the base URL, whether the dependency is deployed, and our service credentials. ` +\n `Downstream said: ${failure.error.message}`,\n failure.error,\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,oDAY8B;AAC9B,0DAA2G;AAC3G,0DAAkD;AAClD,kEAAmH;AAGnH;;;;;;;GAOG;AAEI,IAAM,eAAe,GAArB,MAAM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;AAxNY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,wCAAyB,GAAE;IAMnB,mBAAA,IAAA,kBAAM,EAAC,oCAAqB,CAAC,CAAA;IAE7B,mBAAA,IAAA,kBAAM,EAAC,sBAAO,CAAC,CAAA;IAGf,mBAAA,IAAA,oBAAQ,GAAE,CAAA;IAAE,mBAAA,IAAA,kBAAM,EAAC,mBAAO,CAAC,CAAA;6CAL6B,oCAAqB;QAEnC,sBAAO;QAGM,mBAAO;GAV1D,eAAe,CAwN3B;AAED;;;;;;;GAOG;AACH,gGAAgG;AACnF,QAAA,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC","sourcesContent":["import { inject, optional } from 'inversify';\nimport {\n AuthMeta,\n ClientRegistry,\n DestinationTrust,\n HttpInternalServerError,\n RecordedEndpoint,\n RecordedError,\n RouteMetadata,\n Secrets,\n SECRETS,\n TestCaseRecorder,\n toError,\n} from '@webpieces/core-util';\nimport { RequestContext, RequestContextHeaders, provideFrameworkTransient } from '@webpieces/core-context';\nimport { GcpOidc } from '@webpieces/gcp-identity';\nimport { ApiPrototype, ClientFilterDefinition, ProxyClient, TranslatedFailure } from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\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 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 // @optional: only @AuthSharedSecret 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 ) {\n super();\n }\n\n /**\n * Bind this client to one API contract + target, with the app's outbound filters.\n *\n * `appFilters` is REQUIRED, not defaulted: an empty array is a statement that this client signs\n * nothing and rewrites nothing, and it should be written down rather than inferred from an\n * omitted argument.\n */\n init(apiPrototype: ApiPrototype<object>, config: ClientConfig, appFilters: ClientFilterDefinition[]): 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 resolveBaseUrl(): Promise<string> {\n return this.config.hostPolicy.resolveBaseUrl(this.config.svcName);\n }\n\n /**\n * The framework filters this client's {@link HostPolicy} demands — none for a deployed service,\n * the context override plus the SSRF guard for a runtime host. Delegated rather than decided\n * here so the two halves of \"where does this go\" (resolution and enforcement) cannot drift\n * apart into different policies.\n */\n protected override clientFilters(): ClientFilterDefinition[] {\n return this.config.hostPolicy.builtInFilters();\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 (@AuthOidc /\n * @AuthSharedSecret). Calling a peer's @Public or @AuthJwt 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 * Attach the outbound credential for the endpoint's AuthMode: an @AuthOidc bearer minted as\n * this caller's runtime SA (audience = the callee base URL — the server verifies the signature\n * + caller allow-list), or the @AuthSharedSecret(key) value THIS client sends from its bound\n * {@link Secrets}. Both ride in the ONE `Authorization` header under their own scheme —\n * `Bearer <oidc>` / `Webpieces <secret>` — which is never a context key, so it cannot leak onto\n * the next hop. Never reads process.env.\n */\n protected override async attachOutboundAuth(\n route: RouteMetadata,\n baseUrl: string,\n httpHeaders: Map<string, string>,\n ): Promise<void> {\n const mode = route.authMeta?.mode;\n if (mode?.kind === 'oidc') {\n httpHeaders.set('Authorization', `Bearer ${await this.gcpOidc.mintIdToken(baseUrl)}`);\n } else if (mode?.kind === 'shared-secret') {\n const secret = this.secrets?.get(mode.secretKey);\n if (!secret) {\n throw new Error(\n `No shared secret configured for @AuthSharedSecret('${mode.secretKey}') endpoint ${route.methodName}`,\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 httpHeaders.set('Authorization', `Webpieces ${secret}`);\n }\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 // webpieces-disable no-any-unknown -- DTO types are erased at the proxy boundary\n ): Promise<unknown> {\n const recorder = this.headers.findRecorder();\n if (!recorder) {\n return super.execute(route, requestDto, method);\n }\n return this.recordCall(recorder, route, requestDto, method);\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 // 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(this.contractName(), route.methodName, [requestDto], ctxSnapshot);\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);\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 * A server can satisfy every auth mode when it is talking to a peer it CHOSE, so the deployed\n * policy rejects nothing. A runtime-host policy does reject: an OIDC token's audience and a\n * shared secret both name a peer, and a destination that arrives per call has no honest one —\n * see {@link HostPolicy.assertEndpointSupported}.\n */\n protected override assertEndpointSupported(authMeta: AuthMeta | undefined, methodName: string): void {\n this.config.hostPolicy.assertEndpointSupported(authMeta, methodName, this.contractName());\n }\n\n /**\n * SERVER-TO-SERVER: a 4xx received from a dependency becomes THIS server's own 500.\n *\n * THE INVARIANT:\n *\n * A status received from a downstream dependency describes OUR request to it. It is never the\n * status we return to OUR caller. The server that answered 404 is correct; the server that\n * asked for a route that does not exist is broken, and must say so as a 500.\n *\n * Every 4xx is a CALLER-side defect on this hop: 404 = wrong path / wrong base URL / a dependency\n * that is not deployed yet, 400 = we sent a malformed request, 401/403 = our service credentials\n * or the callee's caller allow-list are wrong. None of them is an answer for whoever called US, and\n * relaying one lets an internal misconfiguration impersonate a legitimate response. That is not\n * hypothetical: a partner-facing Management API reported an EMPTY store estate for an org with six\n * live storefronts, because its dependency had not been promoted and Express served an HTML 404\n * which arrived here as `HttpNotFoundError` and went straight back out. A 500 would have been\n * loud, correct, and attributable to the one server that actually had the bug — which is the whole\n * point: only ONE server should be paged for this.\n *\n * DELIBERATELY 4xx ONLY. 5xx (502/503/504) already mean \"the dependency is unavailable\", which is\n * honest and useful outward, and 500 is already a 500. `HttpUserError` (266, a 2xx code carrying\n * user validation) and `HttpVendorError` (598) are not statuses about our request at all. All of\n * them pass through untouched.\n *\n * THE OPT-OUT IS `appRegistered`, not a config key. A thin proxy or gateway that genuinely wants to\n * relay a downstream status as its own registers a `ClientRegistry` error translation for it at\n * startup — one greppable line saying so out loud — and that translation wins here. Only the\n * framework's built-in default mapping gets wrapped. There is no flag, because a flag would make\n * the dangerous choice invisible in the code that suffers from it.\n *\n * The downstream diagnostic is NOT lost: the original error (which for the incident above names the\n * method, the status, the `text/html` content-type and a snippet of the body) is both quoted in the\n * message and kept as `httpCause`.\n *\n * How much \"Downstream said:\" is worth depends on WHO answered, and both halves are by design:\n * - a NON-webpieces answer (an lb's html 404, a proxy's plain-text 502) is described CLIENT-side by\n * `ResponseBodyReader.describeForeignBody`, so the full diagnostic is ours to quote — this is the\n * mealco incident's exact shape, and it is the case that mattered.\n * - a WEBPIECES peer deliberately sends only the generic reason phrase for its status (see\n * `HttpErrorWireMapper` in http-server — only `HttpUserError`'s message is caller-facing), so this\n * reads \"Downstream said: Not Found\". That is correct and not a regression: the peer's real\n * message is in the PEER's log, correlated by request id, which is the only place it was ever\n * safe to read it.\n *\n * This whole string is an operator-facing message on an `HttpInternalServerError`, so when THIS\n * server answers its own caller none of it goes on the wire — it goes to this server's log.\n */\n protected override adaptDownstreamFailure(failure: TranslatedFailure, callId: string): Error {\n if (failure.appRegistered) {\n return failure.error;\n }\n if (failure.statusCode < 400 || failure.statusCode >= 500) {\n return failure.error;\n }\n return new HttpInternalServerError(\n `${callId}: dependency answered HTTP ${failure.statusCode}. That status describes OUR ` +\n `request to it, not an answer for our caller, so this server owns it as a 500 — check the ` +\n `path, the base URL, whether the dependency is deployed, and our service credentials. ` +\n `Downstream said: ${failure.error.message}`,\n failure.error,\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"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ways a RUNTIME-HOST client refuses before any bytes leave, each its own type for the same
|
|
3
|
+
* reason {@link SsrfRefusedError} is: a delivery worker has to tell these apart, and they have
|
|
4
|
+
* different owners and different cures.
|
|
5
|
+
*
|
|
6
|
+
* - {@link RuntimeHostEndpointUnsupportedError} — BIND time, OUR bug. The contract declares an auth
|
|
7
|
+
* mode no runtime-host client can honestly satisfy. It fires when the client is built, so it takes
|
|
8
|
+
* the process down at startup rather than at the first delivery, which is the point.
|
|
9
|
+
* - {@link MissingRuntimeBaseUrlError} — CALL time, the CALLER's bug. This call was made with no
|
|
10
|
+
* destination in scope. Retrying is pointless; the fix is at the call site.
|
|
11
|
+
*
|
|
12
|
+
* Neither is an {@link SsrfRefusedError}: nothing about the destination was judged and found hostile.
|
|
13
|
+
* A worker that dead-letters on SSRF should usually PAGE on these instead — they mean the sender is
|
|
14
|
+
* misconfigured, not that a partner registered something dangerous.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* A runtime-host client was pointed at an endpoint whose auth mode mints a credential for an
|
|
18
|
+
* audience WE choose (`@AuthOidc`, `@AuthSharedSecret`). Thrown at BIND time, from
|
|
19
|
+
* `HostPolicy.assertEndpointSupported`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class RuntimeHostEndpointUnsupportedError extends Error {
|
|
22
|
+
/** `Contract.method`, so a startup failure names the endpoint without reading a stack. */
|
|
23
|
+
readonly endpoint: string;
|
|
24
|
+
constructor(message: string,
|
|
25
|
+
/** `Contract.method`, so a startup failure names the endpoint without reading a stack. */
|
|
26
|
+
endpoint: string);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A runtime-host client was called with no `WebpiecesCoreHeaders.OVERRIDE_BASE_URL` in the ambient
|
|
30
|
+
* RequestContext, so there is no destination for this call.
|
|
31
|
+
*
|
|
32
|
+
* It is a THROW rather than a fallback to a derived service URL, deliberately: a silent fallback
|
|
33
|
+
* would send a partner's payload to one of our own services, which is a worse outcome than a loud
|
|
34
|
+
* failure by every measure.
|
|
35
|
+
*/
|
|
36
|
+
export declare class MissingRuntimeBaseUrlError extends Error {
|
|
37
|
+
/** `Contract.method`, so the log line names the call that had nowhere to go. */
|
|
38
|
+
readonly endpoint: string;
|
|
39
|
+
constructor(message: string,
|
|
40
|
+
/** `Contract.method`, so the log line names the call that had nowhere to go. */
|
|
41
|
+
endpoint: string);
|
|
42
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The two ways a RUNTIME-HOST client refuses before any bytes leave, each its own type for the same
|
|
4
|
+
* reason {@link SsrfRefusedError} is: a delivery worker has to tell these apart, and they have
|
|
5
|
+
* different owners and different cures.
|
|
6
|
+
*
|
|
7
|
+
* - {@link RuntimeHostEndpointUnsupportedError} — BIND time, OUR bug. The contract declares an auth
|
|
8
|
+
* mode no runtime-host client can honestly satisfy. It fires when the client is built, so it takes
|
|
9
|
+
* the process down at startup rather than at the first delivery, which is the point.
|
|
10
|
+
* - {@link MissingRuntimeBaseUrlError} — CALL time, the CALLER's bug. This call was made with no
|
|
11
|
+
* destination in scope. Retrying is pointless; the fix is at the call site.
|
|
12
|
+
*
|
|
13
|
+
* Neither is an {@link SsrfRefusedError}: nothing about the destination was judged and found hostile.
|
|
14
|
+
* A worker that dead-letters on SSRF should usually PAGE on these instead — they mean the sender is
|
|
15
|
+
* misconfigured, not that a partner registered something dangerous.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.MissingRuntimeBaseUrlError = exports.RuntimeHostEndpointUnsupportedError = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* A runtime-host client was pointed at an endpoint whose auth mode mints a credential for an
|
|
21
|
+
* audience WE choose (`@AuthOidc`, `@AuthSharedSecret`). Thrown at BIND time, from
|
|
22
|
+
* `HostPolicy.assertEndpointSupported`.
|
|
23
|
+
*/
|
|
24
|
+
class RuntimeHostEndpointUnsupportedError extends Error {
|
|
25
|
+
endpoint;
|
|
26
|
+
constructor(message,
|
|
27
|
+
/** `Contract.method`, so a startup failure names the endpoint without reading a stack. */
|
|
28
|
+
endpoint) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.endpoint = endpoint;
|
|
31
|
+
this.name = 'RuntimeHostEndpointUnsupportedError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.RuntimeHostEndpointUnsupportedError = RuntimeHostEndpointUnsupportedError;
|
|
35
|
+
/**
|
|
36
|
+
* A runtime-host client was called with no `WebpiecesCoreHeaders.OVERRIDE_BASE_URL` in the ambient
|
|
37
|
+
* RequestContext, so there is no destination for this call.
|
|
38
|
+
*
|
|
39
|
+
* It is a THROW rather than a fallback to a derived service URL, deliberately: a silent fallback
|
|
40
|
+
* would send a partner's payload to one of our own services, which is a worse outcome than a loud
|
|
41
|
+
* failure by every measure.
|
|
42
|
+
*/
|
|
43
|
+
class MissingRuntimeBaseUrlError extends Error {
|
|
44
|
+
endpoint;
|
|
45
|
+
constructor(message,
|
|
46
|
+
/** `Contract.method`, so the log line names the call that had nowhere to go. */
|
|
47
|
+
endpoint) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.endpoint = endpoint;
|
|
50
|
+
this.name = 'MissingRuntimeBaseUrlError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.MissingRuntimeBaseUrlError = MissingRuntimeBaseUrlError;
|
|
54
|
+
//# sourceMappingURL=RuntimeHostErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeHostErrors.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/RuntimeHostErrors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AACH,MAAa,mCAAoC,SAAQ,KAAK;IAItC;IAHpB,YACI,OAAe;IACf,0FAA0F;IAC1E,QAAgB;QAEhC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,aAAQ,GAAR,QAAQ,CAAQ;QAGhC,IAAI,CAAC,IAAI,GAAG,qCAAqC,CAAC;IACtD,CAAC;CACJ;AATD,kFASC;AAED;;;;;;;GAOG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IAI7B;IAHpB,YACI,OAAe;IACf,gFAAgF;IAChE,QAAgB;QAEhC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,aAAQ,GAAR,QAAQ,CAAQ;QAGhC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC7C,CAAC;CACJ;AATD,gEASC","sourcesContent":["/**\n * The two ways a RUNTIME-HOST client refuses before any bytes leave, each its own type for the same\n * reason {@link SsrfRefusedError} is: a delivery worker has to tell these apart, and they have\n * different owners and different cures.\n *\n * - {@link RuntimeHostEndpointUnsupportedError} — BIND time, OUR bug. The contract declares an auth\n * mode no runtime-host client can honestly satisfy. It fires when the client is built, so it takes\n * the process down at startup rather than at the first delivery, which is the point.\n * - {@link MissingRuntimeBaseUrlError} — CALL time, the CALLER's bug. This call was made with no\n * destination in scope. Retrying is pointless; the fix is at the call site.\n *\n * Neither is an {@link SsrfRefusedError}: nothing about the destination was judged and found hostile.\n * A worker that dead-letters on SSRF should usually PAGE on these instead — they mean the sender is\n * misconfigured, not that a partner registered something dangerous.\n */\n\n/**\n * A runtime-host client was pointed at an endpoint whose auth mode mints a credential for an\n * audience WE choose (`@AuthOidc`, `@AuthSharedSecret`). Thrown at BIND time, from\n * `HostPolicy.assertEndpointSupported`.\n */\nexport class RuntimeHostEndpointUnsupportedError extends Error {\n constructor(\n message: string,\n /** `Contract.method`, so a startup failure names the endpoint without reading a stack. */\n public readonly endpoint: string,\n ) {\n super(message);\n this.name = 'RuntimeHostEndpointUnsupportedError';\n }\n}\n\n/**\n * A runtime-host client was called with no `WebpiecesCoreHeaders.OVERRIDE_BASE_URL` in the ambient\n * RequestContext, so there is no destination for this call.\n *\n * It is a THROW rather than a fallback to a derived service URL, deliberately: a silent fallback\n * would send a partner's payload to one of our own services, which is a worse outcome than a loud\n * failure by every measure.\n */\nexport class MissingRuntimeBaseUrlError extends Error {\n constructor(\n message: string,\n /** `Contract.method`, so the log line names the call that had nowhere to go. */\n public readonly endpoint: string,\n ) {\n super(message);\n this.name = 'MissingRuntimeBaseUrlError';\n }\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Filter, Service } from '@webpieces/core-util';
|
|
2
|
+
import { ClientRequest } from '@webpieces/http-client-core';
|
|
3
|
+
import { AddressResolver } from './AddressResolver';
|
|
4
|
+
import { SsrfPolicy } from './SsrfPolicy';
|
|
5
|
+
/**
|
|
6
|
+
* Enforces {@link SsrfPolicy} on a call whose destination came from RUNTIME data.
|
|
7
|
+
*
|
|
8
|
+
* The moment the base URL is a database column a partner edited, "do not let our process be used as
|
|
9
|
+
* a proxy into our own network" stops being the caller's job and becomes the framework's. Every
|
|
10
|
+
* consumer was reinventing this, badly or not at all, and the one that did it best still only
|
|
11
|
+
* managed `maxRedirects: 0` by hand.
|
|
12
|
+
*
|
|
13
|
+
* ## What it enforces, per hop
|
|
14
|
+
*
|
|
15
|
+
* 1. the URL parses and its scheme is allowed (https only, by default);
|
|
16
|
+
* 2. the hostname is not internal BY NAME (`localhost`, `metadata.google.internal`, `*.internal`);
|
|
17
|
+
* 3. EVERY address the hostname resolves to is public — one private answer among several condemns
|
|
18
|
+
* the request, which is what makes DNS rebinding a refusal rather than a coin toss;
|
|
19
|
+
* 4. redirects are not followed by the transport. The guard reads the `Location` itself, re-runs
|
|
20
|
+
* (1)–(3) on it, and only then re-invokes the chain. A partner URL that 302s to
|
|
21
|
+
* `http://169.254.169.254/…` is refused at the redirect, not obeyed — and because the whole
|
|
22
|
+
* chain below re-runs, whatever signs the request signs it for the host it is actually going to.
|
|
23
|
+
*
|
|
24
|
+
* ## What it deliberately does NOT claim
|
|
25
|
+
*
|
|
26
|
+
* There is a TOCTOU window between resolving a name and the transport connecting: a hostile DNS
|
|
27
|
+
* server can answer differently for the two lookups. Closing it properly means pinning the resolved
|
|
28
|
+
* address into the socket, which node's transport gives no seam for. This guard raises the cost of
|
|
29
|
+
* the attack a great deal and is honest about not eliminating it; egress firewalling remains the
|
|
30
|
+
* control that actually cannot be tricked.
|
|
31
|
+
*/
|
|
32
|
+
export declare class SsrfGuardFilter extends Filter<ClientRequest, Response> {
|
|
33
|
+
private readonly policy;
|
|
34
|
+
private readonly addressResolver;
|
|
35
|
+
private readonly rules;
|
|
36
|
+
constructor(policy: SsrfPolicy, addressResolver: AddressResolver);
|
|
37
|
+
filter(request: ClientRequest, nextFilter: Service<ClientRequest, Response>): Promise<Response>;
|
|
38
|
+
/**
|
|
39
|
+
* @throws SsrfRefusedError naming what condemned the url and the ONE opt-out that would allow
|
|
40
|
+
* it. Returns normally when the destination is acceptable.
|
|
41
|
+
*/
|
|
42
|
+
private assertAllowed;
|
|
43
|
+
private refuseInternal;
|
|
44
|
+
/** Every address for `hostname`, or a refusal — a name that will not resolve is not a destination. */
|
|
45
|
+
private resolveOrRefuse;
|
|
46
|
+
private parse;
|
|
47
|
+
private isRedirect;
|
|
48
|
+
/** The redirect's absolute target, resolving a relative Location against the URL we just called. */
|
|
49
|
+
private redirectTargetOf;
|
|
50
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SsrfGuardFilter = void 0;
|
|
4
|
+
const core_util_1 = require("@webpieces/core-util");
|
|
5
|
+
const InternalAddressRules_1 = require("./InternalAddressRules");
|
|
6
|
+
const SsrfRefusedError_1 = require("./SsrfRefusedError");
|
|
7
|
+
/**
|
|
8
|
+
* Enforces {@link SsrfPolicy} on a call whose destination came from RUNTIME data.
|
|
9
|
+
*
|
|
10
|
+
* The moment the base URL is a database column a partner edited, "do not let our process be used as
|
|
11
|
+
* a proxy into our own network" stops being the caller's job and becomes the framework's. Every
|
|
12
|
+
* consumer was reinventing this, badly or not at all, and the one that did it best still only
|
|
13
|
+
* managed `maxRedirects: 0` by hand.
|
|
14
|
+
*
|
|
15
|
+
* ## What it enforces, per hop
|
|
16
|
+
*
|
|
17
|
+
* 1. the URL parses and its scheme is allowed (https only, by default);
|
|
18
|
+
* 2. the hostname is not internal BY NAME (`localhost`, `metadata.google.internal`, `*.internal`);
|
|
19
|
+
* 3. EVERY address the hostname resolves to is public — one private answer among several condemns
|
|
20
|
+
* the request, which is what makes DNS rebinding a refusal rather than a coin toss;
|
|
21
|
+
* 4. redirects are not followed by the transport. The guard reads the `Location` itself, re-runs
|
|
22
|
+
* (1)–(3) on it, and only then re-invokes the chain. A partner URL that 302s to
|
|
23
|
+
* `http://169.254.169.254/…` is refused at the redirect, not obeyed — and because the whole
|
|
24
|
+
* chain below re-runs, whatever signs the request signs it for the host it is actually going to.
|
|
25
|
+
*
|
|
26
|
+
* ## What it deliberately does NOT claim
|
|
27
|
+
*
|
|
28
|
+
* There is a TOCTOU window between resolving a name and the transport connecting: a hostile DNS
|
|
29
|
+
* server can answer differently for the two lookups. Closing it properly means pinning the resolved
|
|
30
|
+
* address into the socket, which node's transport gives no seam for. This guard raises the cost of
|
|
31
|
+
* the attack a great deal and is honest about not eliminating it; egress firewalling remains the
|
|
32
|
+
* control that actually cannot be tricked.
|
|
33
|
+
*/
|
|
34
|
+
class SsrfGuardFilter extends core_util_1.Filter {
|
|
35
|
+
policy;
|
|
36
|
+
addressResolver;
|
|
37
|
+
rules = new InternalAddressRules_1.InternalAddressRules();
|
|
38
|
+
constructor(policy, addressResolver) {
|
|
39
|
+
super();
|
|
40
|
+
this.policy = policy;
|
|
41
|
+
this.addressResolver = addressResolver;
|
|
42
|
+
}
|
|
43
|
+
async filter(request, nextFilter) {
|
|
44
|
+
await this.assertAllowed(request.url);
|
|
45
|
+
// The transport must not follow a redirect on its own — that would be a hop this policy
|
|
46
|
+
// never saw. We read the Location and judge it ourselves, below.
|
|
47
|
+
request.followRedirects = false;
|
|
48
|
+
let response = await nextFilter.invoke(request);
|
|
49
|
+
for (let hop = 0; this.isRedirect(response); hop++) {
|
|
50
|
+
if (hop >= this.policy.maxRedirects) {
|
|
51
|
+
throw new SsrfRefusedError_1.SsrfRefusedError(`${request.contractName}.${request.route.methodName}: refused to follow more than ` +
|
|
52
|
+
`${this.policy.maxRedirects} redirect(s) from a runtime-supplied destination. ` +
|
|
53
|
+
`The last one was ${request.url}. A webhook endpoint that needs a longer redirect ` +
|
|
54
|
+
`chain should be registered at its final URL instead.`, request.url);
|
|
55
|
+
}
|
|
56
|
+
const target = this.redirectTargetOf(response, request);
|
|
57
|
+
await this.assertAllowed(target);
|
|
58
|
+
request.followRedirectTo(target);
|
|
59
|
+
response = await nextFilter.invoke(request);
|
|
60
|
+
}
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @throws SsrfRefusedError naming what condemned the url and the ONE opt-out that would allow
|
|
65
|
+
* it. Returns normally when the destination is acceptable.
|
|
66
|
+
*/
|
|
67
|
+
async assertAllowed(url) {
|
|
68
|
+
const parsed = this.parse(url);
|
|
69
|
+
if (!this.policy.allowedSchemes.has(parsed.protocol)) {
|
|
70
|
+
const allowed = [...this.policy.allowedSchemes].join(', ');
|
|
71
|
+
throw new SsrfRefusedError_1.SsrfRefusedError(`Refusing to send to ${url}: scheme '${parsed.protocol}' is not allowed (allowed: ${allowed}). ` +
|
|
72
|
+
`A destination supplied at runtime must be reached over TLS — a plaintext hop leaks the ` +
|
|
73
|
+
`payload and its signature to anything on the path.`, url);
|
|
74
|
+
}
|
|
75
|
+
if (this.policy.allowInternalAddresses) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const hostname = parsed.hostname.replace(/^\[|\]$/g, '');
|
|
79
|
+
if (this.rules.isInternalHostname(hostname)) {
|
|
80
|
+
throw this.refuseInternal(url, `'${hostname}' names infrastructure inside our own network`);
|
|
81
|
+
}
|
|
82
|
+
for (const address of await this.resolveOrRefuse(url, hostname)) {
|
|
83
|
+
if (this.rules.isInternalAddress(address)) {
|
|
84
|
+
throw this.refuseInternal(url, `it resolves to the internal address ${address}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
refuseInternal(url, because) {
|
|
89
|
+
return new SsrfRefusedError_1.SsrfRefusedError(`Refusing to send to ${url}: ${because}. A destination supplied at runtime is attacker-influenced ` +
|
|
90
|
+
`data, so loopback, RFC1918, link-local and cloud-metadata addresses are refused — reaching ` +
|
|
91
|
+
`169.254.169.254 would hand this process's own service-account tokens to whoever registered ` +
|
|
92
|
+
`the URL. If this client genuinely must reach an internal host (a local emulator, an ` +
|
|
93
|
+
`on-cluster service), say so at the construction site with ` +
|
|
94
|
+
`new RuntimeHostFromContextAllowingInternalAddresses('<why>', new DnsAddressResolver()) ` +
|
|
95
|
+
`instead of new RuntimeHostFromContext(new DnsAddressResolver()).`, url);
|
|
96
|
+
}
|
|
97
|
+
/** Every address for `hostname`, or a refusal — a name that will not resolve is not a destination. */
|
|
98
|
+
async resolveOrRefuse(url, hostname) {
|
|
99
|
+
// An IP LITERAL never went to DNS, so judge it directly; hostnames go to the resolver.
|
|
100
|
+
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(hostname) || hostname.includes(':')) {
|
|
101
|
+
return [hostname];
|
|
102
|
+
}
|
|
103
|
+
// webpieces-disable no-unmanaged-exceptions -- turn an unresolvable name into the SAME refusal a bad address gets
|
|
104
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
105
|
+
try {
|
|
106
|
+
return await this.addressResolver.resolve(hostname);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
const error = (0, core_util_1.toError)(err);
|
|
110
|
+
throw new SsrfRefusedError_1.SsrfRefusedError(`Refusing to send to ${url}: '${hostname}' did not resolve (${error.message}). ` +
|
|
111
|
+
`An unresolvable destination is refused rather than attempted, so a partner row that has ` +
|
|
112
|
+
`gone stale fails as a delivery error instead of as a network timeout.`, url);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
parse(url) {
|
|
116
|
+
// webpieces-disable no-unmanaged-exceptions -- an unparseable url is a refusal, in this filter's own vocabulary
|
|
117
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
118
|
+
try {
|
|
119
|
+
return new URL(url);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
const error = (0, core_util_1.toError)(err);
|
|
123
|
+
throw new SsrfRefusedError_1.SsrfRefusedError(`Refusing to send to '${url}': it is not a parseable absolute URL (${error.message}). ` +
|
|
124
|
+
`A runtime-supplied base URL must be absolute, e.g. 'https://api.partner.example'.`, url);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
isRedirect(response) {
|
|
128
|
+
return response.status >= 300 && response.status < 400 && response.headers.get('location') !== null;
|
|
129
|
+
}
|
|
130
|
+
/** The redirect's absolute target, resolving a relative Location against the URL we just called. */
|
|
131
|
+
redirectTargetOf(response, request) {
|
|
132
|
+
const location = response.headers.get('location') ?? '';
|
|
133
|
+
// webpieces-disable no-unmanaged-exceptions -- a malformed Location is a refusal, in this filter's own vocabulary
|
|
134
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
135
|
+
try {
|
|
136
|
+
return new URL(location, request.url).toString();
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
const error = (0, core_util_1.toError)(err);
|
|
140
|
+
throw new SsrfRefusedError_1.SsrfRefusedError(`Refusing to follow the redirect from ${request.url}: its Location header ` +
|
|
141
|
+
`'${location}' is not a usable URL (${error.message}).`, request.url);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.SsrfGuardFilter = SsrfGuardFilter;
|
|
146
|
+
//# sourceMappingURL=SsrfGuardFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SsrfGuardFilter.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/SsrfGuardFilter.ts"],"names":[],"mappings":";;;AAAA,oDAAgE;AAGhE,iEAA8D;AAE9D,yDAAsD;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,eAAgB,SAAQ,kBAA+B;IAI3C;IACA;IAJJ,KAAK,GAAG,IAAI,2CAAoB,EAAE,CAAC;IAEpD,YACqB,MAAkB,EAClB,eAAgC;QAEjD,KAAK,EAAE,CAAC;QAHS,WAAM,GAAN,MAAM,CAAY;QAClB,oBAAe,GAAf,eAAe,CAAiB;IAGrD,CAAC;IAEQ,KAAK,CAAC,MAAM,CAAC,OAAsB,EAAE,UAA4C;QACtF,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAEtC,wFAAwF;QACxF,iEAAiE;QACjE,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC;QAEhC,IAAI,QAAQ,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChD,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;YACjD,IAAI,GAA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N,CAAC;IACL,CAAC;CACJ;AAtID,0CAsIC","sourcesContent":["import { Filter, Service, toError } from '@webpieces/core-util';\nimport { ClientRequest } from '@webpieces/http-client-core';\nimport { AddressResolver } from './AddressResolver';\nimport { InternalAddressRules } from './InternalAddressRules';\nimport { SsrfPolicy } from './SsrfPolicy';\nimport { SsrfRefusedError } from './SsrfRefusedError';\n\n/**\n * Enforces {@link SsrfPolicy} on a call whose destination came from RUNTIME data.\n *\n * The moment the base URL is a database column a partner edited, \"do not let our process be used as\n * a proxy into our own network\" stops being the caller's job and becomes the framework's. Every\n * consumer was reinventing this, badly or not at all, and the one that did it best still only\n * managed `maxRedirects: 0` by hand.\n *\n * ## What it enforces, per hop\n *\n * 1. the URL parses and its scheme is allowed (https only, by default);\n * 2. the hostname is not internal BY NAME (`localhost`, `metadata.google.internal`, `*.internal`);\n * 3. EVERY address the hostname resolves to is public — one private answer among several condemns\n * the request, which is what makes DNS rebinding a refusal rather than a coin toss;\n * 4. redirects are not followed by the transport. The guard reads the `Location` itself, re-runs\n * (1)–(3) on it, and only then re-invokes the chain. A partner URL that 302s to\n * `http://169.254.169.254/…` is refused at the redirect, not obeyed — and because the whole\n * chain below re-runs, whatever signs the request signs it for the host it is actually going to.\n *\n * ## What it deliberately does NOT claim\n *\n * There is a TOCTOU window between resolving a name and the transport connecting: a hostile DNS\n * server can answer differently for the two lookups. Closing it properly means pinning the resolved\n * address into the socket, which node's transport gives no seam for. This guard raises the cost of\n * the attack a great deal and is honest about not eliminating it; egress firewalling remains the\n * control that actually cannot be tricked.\n */\nexport class SsrfGuardFilter extends Filter<ClientRequest, Response> {\n private readonly rules = new InternalAddressRules();\n\n constructor(\n private readonly policy: SsrfPolicy,\n private readonly addressResolver: AddressResolver,\n ) {\n super();\n }\n\n override async filter(request: ClientRequest, nextFilter: Service<ClientRequest, Response>): Promise<Response> {\n await this.assertAllowed(request.url);\n\n // The transport must not follow a redirect on its own — that would be a hop this policy\n // never saw. We read the Location and judge it ourselves, below.\n request.followRedirects = false;\n\n let response = await nextFilter.invoke(request);\n for (let hop = 0; this.isRedirect(response); hop++) {\n if (hop >= this.policy.maxRedirects) {\n throw new SsrfRefusedError(\n `${request.contractName}.${request.route.methodName}: refused to follow more than ` +\n `${this.policy.maxRedirects} redirect(s) from a runtime-supplied destination. ` +\n `The last one was ${request.url}. A webhook endpoint that needs a longer redirect ` +\n `chain should be registered at its final URL instead.`,\n request.url,\n );\n }\n const target = this.redirectTargetOf(response, request);\n await this.assertAllowed(target);\n request.followRedirectTo(target);\n response = await nextFilter.invoke(request);\n }\n return response;\n }\n\n /**\n * @throws SsrfRefusedError naming what condemned the url and the ONE opt-out that would allow\n * it. Returns normally when the destination is acceptable.\n */\n private async assertAllowed(url: string): Promise<void> {\n const parsed = this.parse(url);\n if (!this.policy.allowedSchemes.has(parsed.protocol)) {\n const allowed = [...this.policy.allowedSchemes].join(', ');\n throw new SsrfRefusedError(\n `Refusing to send to ${url}: scheme '${parsed.protocol}' is not allowed (allowed: ${allowed}). ` +\n `A destination supplied at runtime must be reached over TLS — a plaintext hop leaks the ` +\n `payload and its signature to anything on the path.`,\n url,\n );\n }\n if (this.policy.allowInternalAddresses) {\n return;\n }\n const hostname = parsed.hostname.replace(/^\\[|\\]$/g, '');\n if (this.rules.isInternalHostname(hostname)) {\n throw this.refuseInternal(url, `'${hostname}' names infrastructure inside our own network`);\n }\n for (const address of await this.resolveOrRefuse(url, hostname)) {\n if (this.rules.isInternalAddress(address)) {\n throw this.refuseInternal(url, `it resolves to the internal address ${address}`);\n }\n }\n }\n\n private refuseInternal(url: string, because: string): SsrfRefusedError {\n return new SsrfRefusedError(\n `Refusing to send to ${url}: ${because}. A destination supplied at runtime is attacker-influenced ` +\n `data, so loopback, RFC1918, link-local and cloud-metadata addresses are refused — reaching ` +\n `169.254.169.254 would hand this process's own service-account tokens to whoever registered ` +\n `the URL. If this client genuinely must reach an internal host (a local emulator, an ` +\n `on-cluster service), say so at the construction site with ` +\n `new RuntimeHostFromContextAllowingInternalAddresses('<why>', new DnsAddressResolver()) ` +\n `instead of new RuntimeHostFromContext(new DnsAddressResolver()).`,\n url,\n );\n }\n\n /** Every address for `hostname`, or a refusal — a name that will not resolve is not a destination. */\n private async resolveOrRefuse(url: string, hostname: string): Promise<string[]> {\n // An IP LITERAL never went to DNS, so judge it directly; hostnames go to the resolver.\n if (/^\\d{1,3}(\\.\\d{1,3}){3}$/.test(hostname) || hostname.includes(':')) {\n return [hostname];\n }\n // webpieces-disable no-unmanaged-exceptions -- turn an unresolvable name into the SAME refusal a bad address gets\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return await this.addressResolver.resolve(hostname);\n } catch (err: unknown) {\n const error = toError(err);\n throw new SsrfRefusedError(\n `Refusing to send to ${url}: '${hostname}' did not resolve (${error.message}). ` +\n `An unresolvable destination is refused rather than attempted, so a partner row that has ` +\n `gone stale fails as a delivery error instead of as a network timeout.`,\n url,\n );\n }\n }\n\n private parse(url: string): URL {\n // webpieces-disable no-unmanaged-exceptions -- an unparseable url is a refusal, in this filter's own vocabulary\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return new URL(url);\n } catch (err: unknown) {\n const error = toError(err);\n throw new SsrfRefusedError(\n `Refusing to send to '${url}': it is not a parseable absolute URL (${error.message}). ` +\n `A runtime-supplied base URL must be absolute, e.g. 'https://api.partner.example'.`,\n url,\n );\n }\n }\n\n private isRedirect(response: Response): boolean {\n return response.status >= 300 && response.status < 400 && response.headers.get('location') !== null;\n }\n\n /** The redirect's absolute target, resolving a relative Location against the URL we just called. */\n private redirectTargetOf(response: Response, request: ClientRequest): string {\n const location = response.headers.get('location') ?? '';\n // webpieces-disable no-unmanaged-exceptions -- a malformed Location is a refusal, in this filter's own vocabulary\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return new URL(location, request.url).toString();\n } catch (err: unknown) {\n const error = toError(err);\n throw new SsrfRefusedError(\n `Refusing to follow the redirect from ${request.url}: its Location header ` +\n `'${location}' is not a usable URL (${error.message}).`,\n request.url,\n );\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a runtime-supplied destination has to satisfy before this client will send to it.
|
|
3
|
+
*
|
|
4
|
+
* DATA ONLY — the enforcement is {@link SsrfGuardFilter}. It is constructed by a
|
|
5
|
+
* {@link HostPolicy}, never by app code directly, because the CHOICE between the strict policy and
|
|
6
|
+
* the internal-addresses one is made by naming a host-policy class at the `new ClientConfig(...)`
|
|
7
|
+
* call site. That keeps the permissive answer a greppable noun rather than a boolean somebody
|
|
8
|
+
* flipped.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SsrfPolicy {
|
|
11
|
+
/**
|
|
12
|
+
* URL schemes that may be sent to, with their colons ('https:'). HTTPS-only by default: a
|
|
13
|
+
* partner-registered destination reached over plaintext http leaks the payload and its
|
|
14
|
+
* signature to anything on the path, and "the partner has not got TLS yet" is their bug to
|
|
15
|
+
* fix, not ours to accommodate silently.
|
|
16
|
+
*/
|
|
17
|
+
readonly allowedSchemes: ReadonlySet<string>;
|
|
18
|
+
/**
|
|
19
|
+
* TRUE only under {@link RuntimeHostFromContextAllowingInternalAddresses}. When true, the
|
|
20
|
+
* loopback / RFC1918 / link-local / metadata refusals are skipped — scheme checking and the
|
|
21
|
+
* redirect cap still apply.
|
|
22
|
+
*/
|
|
23
|
+
readonly allowInternalAddresses: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* How many redirects may be followed, each one re-judged under this same policy. Small on
|
|
26
|
+
* purpose: a legitimate webhook endpoint does not need a redirect chain, and every hop is
|
|
27
|
+
* another chance for the destination to move somewhere we did not agree to.
|
|
28
|
+
*/
|
|
29
|
+
readonly maxRedirects: number;
|
|
30
|
+
/**
|
|
31
|
+
* WHY internal addresses are allowed, in prose, when they are. Required by
|
|
32
|
+
* {@link RuntimeHostFromContextAllowingInternalAddresses} and quoted in the log line the
|
|
33
|
+
* guard writes, so the reason travels with the decision instead of living in a commit
|
|
34
|
+
* message nobody will find.
|
|
35
|
+
*/
|
|
36
|
+
readonly allowInternalReason: string | undefined;
|
|
37
|
+
constructor(
|
|
38
|
+
/**
|
|
39
|
+
* URL schemes that may be sent to, with their colons ('https:'). HTTPS-only by default: a
|
|
40
|
+
* partner-registered destination reached over plaintext http leaks the payload and its
|
|
41
|
+
* signature to anything on the path, and "the partner has not got TLS yet" is their bug to
|
|
42
|
+
* fix, not ours to accommodate silently.
|
|
43
|
+
*/
|
|
44
|
+
allowedSchemes: ReadonlySet<string>,
|
|
45
|
+
/**
|
|
46
|
+
* TRUE only under {@link RuntimeHostFromContextAllowingInternalAddresses}. When true, the
|
|
47
|
+
* loopback / RFC1918 / link-local / metadata refusals are skipped — scheme checking and the
|
|
48
|
+
* redirect cap still apply.
|
|
49
|
+
*/
|
|
50
|
+
allowInternalAddresses: boolean,
|
|
51
|
+
/**
|
|
52
|
+
* How many redirects may be followed, each one re-judged under this same policy. Small on
|
|
53
|
+
* purpose: a legitimate webhook endpoint does not need a redirect chain, and every hop is
|
|
54
|
+
* another chance for the destination to move somewhere we did not agree to.
|
|
55
|
+
*/
|
|
56
|
+
maxRedirects: number,
|
|
57
|
+
/**
|
|
58
|
+
* WHY internal addresses are allowed, in prose, when they are. Required by
|
|
59
|
+
* {@link RuntimeHostFromContextAllowingInternalAddresses} and quoted in the log line the
|
|
60
|
+
* guard writes, so the reason travels with the decision instead of living in a commit
|
|
61
|
+
* message nobody will find.
|
|
62
|
+
*/
|
|
63
|
+
allowInternalReason: string | undefined);
|
|
64
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SsrfPolicy = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* What a runtime-supplied destination has to satisfy before this client will send to it.
|
|
6
|
+
*
|
|
7
|
+
* DATA ONLY — the enforcement is {@link SsrfGuardFilter}. It is constructed by a
|
|
8
|
+
* {@link HostPolicy}, never by app code directly, because the CHOICE between the strict policy and
|
|
9
|
+
* the internal-addresses one is made by naming a host-policy class at the `new ClientConfig(...)`
|
|
10
|
+
* call site. That keeps the permissive answer a greppable noun rather than a boolean somebody
|
|
11
|
+
* flipped.
|
|
12
|
+
*/
|
|
13
|
+
class SsrfPolicy {
|
|
14
|
+
allowedSchemes;
|
|
15
|
+
allowInternalAddresses;
|
|
16
|
+
maxRedirects;
|
|
17
|
+
allowInternalReason;
|
|
18
|
+
constructor(
|
|
19
|
+
/**
|
|
20
|
+
* URL schemes that may be sent to, with their colons ('https:'). HTTPS-only by default: a
|
|
21
|
+
* partner-registered destination reached over plaintext http leaks the payload and its
|
|
22
|
+
* signature to anything on the path, and "the partner has not got TLS yet" is their bug to
|
|
23
|
+
* fix, not ours to accommodate silently.
|
|
24
|
+
*/
|
|
25
|
+
allowedSchemes,
|
|
26
|
+
/**
|
|
27
|
+
* TRUE only under {@link RuntimeHostFromContextAllowingInternalAddresses}. When true, the
|
|
28
|
+
* loopback / RFC1918 / link-local / metadata refusals are skipped — scheme checking and the
|
|
29
|
+
* redirect cap still apply.
|
|
30
|
+
*/
|
|
31
|
+
allowInternalAddresses,
|
|
32
|
+
/**
|
|
33
|
+
* How many redirects may be followed, each one re-judged under this same policy. Small on
|
|
34
|
+
* purpose: a legitimate webhook endpoint does not need a redirect chain, and every hop is
|
|
35
|
+
* another chance for the destination to move somewhere we did not agree to.
|
|
36
|
+
*/
|
|
37
|
+
maxRedirects,
|
|
38
|
+
/**
|
|
39
|
+
* WHY internal addresses are allowed, in prose, when they are. Required by
|
|
40
|
+
* {@link RuntimeHostFromContextAllowingInternalAddresses} and quoted in the log line the
|
|
41
|
+
* guard writes, so the reason travels with the decision instead of living in a commit
|
|
42
|
+
* message nobody will find.
|
|
43
|
+
*/
|
|
44
|
+
allowInternalReason) {
|
|
45
|
+
this.allowedSchemes = allowedSchemes;
|
|
46
|
+
this.allowInternalAddresses = allowInternalAddresses;
|
|
47
|
+
this.maxRedirects = maxRedirects;
|
|
48
|
+
this.allowInternalReason = allowInternalReason;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.SsrfPolicy = SsrfPolicy;
|
|
52
|
+
//# sourceMappingURL=SsrfPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SsrfPolicy.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/SsrfPolicy.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,MAAa,UAAU;IAQC;IAMA;IAMA;IAOA;IA1BpB;IACI;;;;;OAKG;IACa,cAAmC;IACnD;;;;OAIG;IACa,sBAA+B;IAC/C;;;;OAIG;IACa,YAAoB;IACpC;;;;;OAKG;IACa,mBAAuC;QAnBvC,mBAAc,GAAd,cAAc,CAAqB;QAMnC,2BAAsB,GAAtB,sBAAsB,CAAS;QAM/B,iBAAY,GAAZ,YAAY,CAAQ;QAOpB,wBAAmB,GAAnB,mBAAmB,CAAoB;IACxD,CAAC;CACP;AA7BD,gCA6BC","sourcesContent":["/**\n * What a runtime-supplied destination has to satisfy before this client will send to it.\n *\n * DATA ONLY — the enforcement is {@link SsrfGuardFilter}. It is constructed by a\n * {@link HostPolicy}, never by app code directly, because the CHOICE between the strict policy and\n * the internal-addresses one is made by naming a host-policy class at the `new ClientConfig(...)`\n * call site. That keeps the permissive answer a greppable noun rather than a boolean somebody\n * flipped.\n */\nexport class SsrfPolicy {\n constructor(\n /**\n * URL schemes that may be sent to, with their colons ('https:'). HTTPS-only by default: a\n * partner-registered destination reached over plaintext http leaks the payload and its\n * signature to anything on the path, and \"the partner has not got TLS yet\" is their bug to\n * fix, not ours to accommodate silently.\n */\n public readonly allowedSchemes: ReadonlySet<string>,\n /**\n * TRUE only under {@link RuntimeHostFromContextAllowingInternalAddresses}. When true, the\n * loopback / RFC1918 / link-local / metadata refusals are skipped — scheme checking and the\n * redirect cap still apply.\n */\n public readonly allowInternalAddresses: boolean,\n /**\n * How many redirects may be followed, each one re-judged under this same policy. Small on\n * purpose: a legitimate webhook endpoint does not need a redirect chain, and every hop is\n * another chance for the destination to move somewhere we did not agree to.\n */\n public readonly maxRedirects: number,\n /**\n * WHY internal addresses are allowed, in prose, when they are. Required by\n * {@link RuntimeHostFromContextAllowingInternalAddresses} and quoted in the log line the\n * guard writes, so the reason travels with the decision instead of living in a commit\n * message nobody will find.\n */\n public readonly allowInternalReason: string | undefined,\n ) {}\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We refused to SEND a request, because the destination failed this client's SSRF policy.
|
|
3
|
+
*
|
|
4
|
+
* Its own type rather than a bare Error so an app can tell "the partner's endpoint rejected us"
|
|
5
|
+
* (an HttpError carrying their status) from "we never contacted the partner at all" — those are
|
|
6
|
+
* different incidents with different owners, and only the second one means the URL in our database
|
|
7
|
+
* is hostile or wrong. A delivery worker typically dead-letters this instead of retrying: no number
|
|
8
|
+
* of retries makes 127.0.0.1 an acceptable destination.
|
|
9
|
+
*
|
|
10
|
+
* The message names the URL, the address it resolved to when that is what condemned it, and the
|
|
11
|
+
* ONE named opt-out that would allow it — so the reader does not have to go looking for whether an
|
|
12
|
+
* escape exists.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SsrfRefusedError extends Error {
|
|
15
|
+
/** The URL that was refused, verbatim, so a log line identifies the offending row. */
|
|
16
|
+
readonly refusedUrl: string;
|
|
17
|
+
constructor(message: string,
|
|
18
|
+
/** The URL that was refused, verbatim, so a log line identifies the offending row. */
|
|
19
|
+
refusedUrl: string);
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SsrfRefusedError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* We refused to SEND a request, because the destination failed this client's SSRF policy.
|
|
6
|
+
*
|
|
7
|
+
* Its own type rather than a bare Error so an app can tell "the partner's endpoint rejected us"
|
|
8
|
+
* (an HttpError carrying their status) from "we never contacted the partner at all" — those are
|
|
9
|
+
* different incidents with different owners, and only the second one means the URL in our database
|
|
10
|
+
* is hostile or wrong. A delivery worker typically dead-letters this instead of retrying: no number
|
|
11
|
+
* of retries makes 127.0.0.1 an acceptable destination.
|
|
12
|
+
*
|
|
13
|
+
* The message names the URL, the address it resolved to when that is what condemned it, and the
|
|
14
|
+
* ONE named opt-out that would allow it — so the reader does not have to go looking for whether an
|
|
15
|
+
* escape exists.
|
|
16
|
+
*/
|
|
17
|
+
class SsrfRefusedError extends Error {
|
|
18
|
+
refusedUrl;
|
|
19
|
+
constructor(message,
|
|
20
|
+
/** The URL that was refused, verbatim, so a log line identifies the offending row. */
|
|
21
|
+
refusedUrl) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.refusedUrl = refusedUrl;
|
|
24
|
+
this.name = 'SsrfRefusedError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SsrfRefusedError = SsrfRefusedError;
|
|
28
|
+
//# sourceMappingURL=SsrfRefusedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SsrfRefusedError.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-node/src/SsrfRefusedError.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IAInB;IAHpB,YACI,OAAe;IACf,sFAAsF;IACtE,UAAkB;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,eAAU,GAAV,UAAU,CAAQ;QAGlC,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACnC,CAAC;CACJ;AATD,4CASC","sourcesContent":["/**\n * We refused to SEND a request, because the destination failed this client's SSRF policy.\n *\n * Its own type rather than a bare Error so an app can tell \"the partner's endpoint rejected us\"\n * (an HttpError carrying their status) from \"we never contacted the partner at all\" — those are\n * different incidents with different owners, and only the second one means the URL in our database\n * is hostile or wrong. A delivery worker typically dead-letters this instead of retrying: no number\n * of retries makes 127.0.0.1 an acceptable destination.\n *\n * The message names the URL, the address it resolved to when that is what condemned it, and the\n * ONE named opt-out that would allow it — so the reader does not have to go looking for whether an\n * escape exists.\n */\nexport class SsrfRefusedError extends Error {\n constructor(\n message: string,\n /** The URL that was refused, verbatim, so a log line identifies the offending row. */\n public readonly refusedUrl: string,\n ) {\n super(message);\n this.name = 'SsrfRefusedError';\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -14,12 +14,26 @@
|
|
|
14
14
|
* import { ClientHttpFactory, ClientConfig } from '@webpieces/http-client-node';
|
|
15
15
|
*
|
|
16
16
|
* // inject the factory, then one client per contract
|
|
17
|
-
* const server2 = factory.createRpcClient(
|
|
17
|
+
* const server2 = factory.createRpcClient(
|
|
18
|
+
* Server2Api,
|
|
19
|
+
* new ClientConfig('server2', new DeployedServiceHost()),
|
|
20
|
+
* [], // this client's outbound filters
|
|
21
|
+
* );
|
|
18
22
|
* const response = await server2.fetchValue(req);
|
|
19
23
|
* ```
|
|
20
24
|
*/
|
|
21
25
|
export { ClientHttpFactory } from './ClientHttpFactory';
|
|
22
26
|
export { NodeProxyClient, NODE_PROXY_CLIENT_PROVIDER } from './NodeProxyClient';
|
|
23
27
|
export { ClientConfig } from './ClientConfig';
|
|
28
|
+
export { HostPolicy, DeployedServiceHost, RuntimeHostFromContext, RuntimeHostFromContextAllowingInternalAddresses } from './HostPolicy';
|
|
29
|
+
export { SsrfPolicy } from './SsrfPolicy';
|
|
30
|
+
export { SsrfGuardFilter } from './SsrfGuardFilter';
|
|
31
|
+
export { SsrfRefusedError } from './SsrfRefusedError';
|
|
32
|
+
export { RuntimeHostEndpointUnsupportedError, MissingRuntimeBaseUrlError } from './RuntimeHostErrors';
|
|
33
|
+
export { InternalAddressRules } from './InternalAddressRules';
|
|
34
|
+
export { AddressResolver, DnsAddressResolver } from './AddressResolver';
|
|
35
|
+
export { ContextBaseUrlOverrideFilter, BASE_URL_OVERRIDE_PRIORITY, SSRF_GUARD_PRIORITY } from './ContextBaseUrlOverrideFilter';
|
|
24
36
|
export { ProxyClient, ClientErrorTranslator, TranslatedFailure } from '@webpieces/http-client-core';
|
|
37
|
+
export { ClientRequest, ClientFilterDefinition } from '@webpieces/http-client-core';
|
|
38
|
+
export type { ClientFilter } from '@webpieces/http-client-core';
|
|
25
39
|
export type { ApiPrototype } from '@webpieces/http-client-core';
|