@nathapp/nestjs-common 4.5.0 → 4.5.1
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 +57 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/outbound-http/address.d.ts +1 -0
- package/dist/outbound-http/address.js +26 -0
- package/dist/outbound-http/address.js.map +1 -0
- package/dist/outbound-http/assert-outbound-url.d.ts +6 -0
- package/dist/outbound-http/assert-outbound-url.js +58 -0
- package/dist/outbound-http/assert-outbound-url.js.map +1 -0
- package/dist/outbound-http/errors.d.ts +7 -0
- package/dist/outbound-http/errors.js +26 -0
- package/dist/outbound-http/errors.js.map +1 -0
- package/dist/outbound-http/guarded-http-client.d.ts +24 -0
- package/dist/outbound-http/guarded-http-client.js +106 -0
- package/dist/outbound-http/guarded-http-client.js.map +1 -0
- package/dist/outbound-http/index.d.ts +5 -0
- package/dist/outbound-http/index.js +22 -0
- package/dist/outbound-http/index.js.map +1 -0
- package/dist/outbound-http/policy.d.ts +16 -0
- package/dist/outbound-http/policy.js +40 -0
- package/dist/outbound-http/policy.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -186,3 +186,60 @@ export class AppService {
|
|
|
186
186
|
this.globalFilter.registerHandler(new RateLimitExceptionHandler());
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
# Outbound HTTP guard
|
|
192
|
+
|
|
193
|
+
`GuardedHttpClient` and `assertOutboundUrl` protect server-side requests to URLs that a tenant or client can influence (OIDC discovery, token and JWKS URLs, dynamic-registration `jwks_uri`). Plain `fetch` accepts any scheme, follows redirects, has no timeout or size cap and reaches private networks.
|
|
194
|
+
|
|
195
|
+
## What is blocked by default
|
|
196
|
+
|
|
197
|
+
- Schemes other than `https:` (`http:` only with `allowHttp` or an allow-listed host).
|
|
198
|
+
- URLs with userinfo (`https://user:pw@host/`).
|
|
199
|
+
- Any host whose address is not public unicast: private, loopback, link-local (including `169.254.169.254`), carrier-grade NAT, unique-local, unspecified, multicast, broadcast, reserved and transition ranges. IPv4-mapped IPv6 (`::ffff:127.0.0.1`) is classified by its IPv4 part. Also blocked: IPv4-compatible IPv6 (`::/96`), local-use NAT64 (`64:ff9b:1::/48`), site-local (`fec0::/10`), IPv6 documentation (`3fff::/20`) and SRv6 SIDs (`5f00::/16`). `localhost` and `*.localhost` are blocked without DNS.
|
|
200
|
+
- Hostnames are resolved with all answers checked; if any answer is blocked, the request is refused. DNS failure is refused.
|
|
201
|
+
- Redirects (any 3xx) are never followed.
|
|
202
|
+
- Exchanges slower than `timeoutMs` (covers the body read) and bodies larger than `maxBytes`.
|
|
203
|
+
|
|
204
|
+
Failures reject with `OutboundUrlBlockedError`, whose `reason` is one of `invalid-url`, `scheme`, `credentials`, `private-address`, `dns-failure`, `redirect`, `timeout`, `too-large`, `network`. Its `url` field (origin and pathname only) is safe to log.
|
|
205
|
+
|
|
206
|
+
## Policy
|
|
207
|
+
|
|
208
|
+
| Field | Default | Meaning |
|
|
209
|
+
|-------|---------|---------|
|
|
210
|
+
| `allowedHosts` | `[]` | Hostnames that skip the IP-range check. Exact match, case-insensitive, trailing dot ignored, no wildcards. |
|
|
211
|
+
| `allowHttp` | `false` | Permit `http:` for any host. An allow-listed host may always use `http:`. |
|
|
212
|
+
| `timeoutMs` | `5000` | Positive integer. Whole-exchange timeout. |
|
|
213
|
+
| `maxBytes` | `1048576` | Positive integer. Maximum response body size. |
|
|
214
|
+
|
|
215
|
+
Invalid numeric values throw a `TypeError` naming the field when the policy is resolved (`resolveOutboundHttpPolicy`) or the client is constructed.
|
|
216
|
+
|
|
217
|
+
## Escape hatch
|
|
218
|
+
|
|
219
|
+
To reach an in-cluster service such as a Keycloak on a private address, list its hostname in `allowedHosts`. That host skips the address check only; credentials in the URL, redirects, timeout and size limits still apply.
|
|
220
|
+
|
|
221
|
+
## Usage
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { GuardedHttpClient, OutboundUrlBlockedError } from '@nathapp/nestjs-common';
|
|
225
|
+
|
|
226
|
+
const http = new GuardedHttpClient({ allowedHosts: ['keycloak.auth.svc.cluster.local'], allowHttp: false });
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
const res = await http.get(`${issuer}/.well-known/openid-configuration`);
|
|
230
|
+
if (!res.ok) throw new Error(`discovery failed: ${res.status}`);
|
|
231
|
+
const config = await res.json();
|
|
232
|
+
const token = await http.postForm(tokenUrl, { grant_type: 'authorization_code', code }, { accept: 'application/json' });
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (error instanceof OutboundUrlBlockedError) {
|
|
235
|
+
logger.warn(`blocked ${error.reason} ${error.url}`);
|
|
236
|
+
}
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Non-2xx responses are returned, not thrown. `json()` rejects with the native `SyntaxError` on invalid JSON.
|
|
242
|
+
|
|
243
|
+
## Known limitation: DNS rebinding
|
|
244
|
+
|
|
245
|
+
The address check and the request are separate steps: the hostname is resolved once by the guard and resolved again by `fetch`. A hostile DNS server can answer differently the second time, so a narrow rebinding window remains. The guard does not pin the resolved IP or install a custom dispatcher. Treat it as strong defence against misconfiguration and direct internal URLs, and combine it with network egress policy where rebinding matters.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./i18n"), exports);
|
|
|
26
26
|
__exportStar(require("./interceptor"), exports);
|
|
27
27
|
__exportStar(require("./ip"), exports);
|
|
28
28
|
__exportStar(require("./logging"), exports);
|
|
29
|
+
__exportStar(require("./outbound-http"), exports);
|
|
29
30
|
__exportStar(require("./module"), exports);
|
|
30
31
|
__exportStar(require("./pagination"), exports);
|
|
31
32
|
__exportStar(require("./serialize"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,6CAA2B;AAC3B,8CAA4B;AAC5B,6CAA2B;AAC3B,8CAA4B;AAC5B,yCAAuB;AACvB,iDAA+B;AAC/B,yCAAuB;AACvB,gDAA8B;AAC9B,uCAAqB;AACrB,4CAA0B;AAC1B,2CAAyB;AACzB,+CAA6B;AAC7B,8CAA4B;AAC5B,0CAAwB;AACxB,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,6CAA2B;AAC3B,8CAA4B;AAC5B,6CAA2B;AAC3B,8CAA4B;AAC5B,yCAAuB;AACvB,iDAA+B;AAC/B,yCAAuB;AACvB,gDAA8B;AAC9B,uCAAqB;AACrB,4CAA0B;AAC1B,kDAAgC;AAChC,2CAAyB;AACzB,+CAA6B;AAC7B,8CAA4B;AAC5B,0CAAwB;AACxB,+CAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBlockedAddress(address: string): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBlockedAddress = isBlockedAddress;
|
|
4
|
+
const ipaddr = require("ipaddr.js");
|
|
5
|
+
const EXTRA_BLOCKED_IPV6 = Object.freeze([
|
|
6
|
+
'::/96',
|
|
7
|
+
'64:ff9b:1::/48',
|
|
8
|
+
'fec0::/10',
|
|
9
|
+
'3fff::/20',
|
|
10
|
+
'5f00::/16',
|
|
11
|
+
].map((cidr) => ipaddr.IPv6.parseCIDR(cidr)));
|
|
12
|
+
function isBlockedAddress(address) {
|
|
13
|
+
if (!ipaddr.isValid(address))
|
|
14
|
+
return true;
|
|
15
|
+
let parsed = ipaddr.parse(address);
|
|
16
|
+
if (parsed.kind() === 'ipv6' && parsed.isIPv4MappedAddress()) {
|
|
17
|
+
parsed = parsed.toIPv4Address();
|
|
18
|
+
}
|
|
19
|
+
if (parsed.range() !== 'unicast')
|
|
20
|
+
return true;
|
|
21
|
+
if (parsed.kind() !== 'ipv6')
|
|
22
|
+
return false;
|
|
23
|
+
const v6 = parsed;
|
|
24
|
+
return EXTRA_BLOCKED_IPV6.some((range) => v6.match(range));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../lib/outbound-http/address.ts"],"names":[],"mappings":";;AAoBA,4CAUC;AA9BD,oCAAoC;AAMpC,MAAM,kBAAkB,GAAyC,MAAM,CAAC,MAAM,CAC5E;IACE,OAAO;IACP,gBAAgB;IAChB,WAAW;IACX,WAAW;IACX,WAAW;CACZ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAC7C,CAAC;AAMF,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,MAAM,IAAK,MAAsB,CAAC,mBAAmB,EAAE,EAAE,CAAC;QAC9E,MAAM,GAAI,MAAsB,CAAC,aAAa,EAAE,CAAC;IACnD,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,EAAE,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC9C,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IAC3C,MAAM,EAAE,GAAG,MAAqB,CAAC;IACjC,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type OutboundHttpPolicy } from './policy';
|
|
2
|
+
export type OutboundLookup = (hostname: string) => Promise<string[]>;
|
|
3
|
+
export interface OutboundUrlDeps {
|
|
4
|
+
lookup?: OutboundLookup;
|
|
5
|
+
}
|
|
6
|
+
export declare function assertOutboundUrl(url: string, policy?: OutboundHttpPolicy, deps?: OutboundUrlDeps): Promise<URL>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertOutboundUrl = assertOutboundUrl;
|
|
4
|
+
const promises_1 = require("node:dns/promises");
|
|
5
|
+
const node_net_1 = require("node:net");
|
|
6
|
+
const address_1 = require("./address");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
const policy_1 = require("./policy");
|
|
9
|
+
const defaultLookup = async (hostname) => {
|
|
10
|
+
const records = await (0, promises_1.lookup)(hostname, { all: true, verbatim: true });
|
|
11
|
+
return records.map((r) => r.address);
|
|
12
|
+
};
|
|
13
|
+
function isLocalhost(host) {
|
|
14
|
+
return host === 'localhost' || host.endsWith('.localhost');
|
|
15
|
+
}
|
|
16
|
+
function parse(raw) {
|
|
17
|
+
try {
|
|
18
|
+
return new URL(raw);
|
|
19
|
+
}
|
|
20
|
+
catch (_a) {
|
|
21
|
+
throw new errors_1.OutboundUrlBlockedError('invalid-url', '');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function resolveAddresses(url, host, lookup) {
|
|
25
|
+
let addresses;
|
|
26
|
+
try {
|
|
27
|
+
addresses = await lookup(host);
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
throw new errors_1.OutboundUrlBlockedError('dns-failure', url);
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(addresses) || addresses.length === 0) {
|
|
33
|
+
throw new errors_1.OutboundUrlBlockedError('dns-failure', url);
|
|
34
|
+
}
|
|
35
|
+
return addresses;
|
|
36
|
+
}
|
|
37
|
+
async function assertOutboundUrl(url, policy, deps = {}) {
|
|
38
|
+
var _a;
|
|
39
|
+
const resolved = (0, policy_1.resolveOutboundHttpPolicy)(policy);
|
|
40
|
+
const parsed = parse(url);
|
|
41
|
+
if (parsed.username !== '' || parsed.password !== '') {
|
|
42
|
+
throw new errors_1.OutboundUrlBlockedError('credentials', parsed);
|
|
43
|
+
}
|
|
44
|
+
const host = (0, policy_1.normaliseHostname)(parsed.hostname);
|
|
45
|
+
const allowed = resolved.allowedHosts.includes(host);
|
|
46
|
+
const schemeOk = parsed.protocol === 'https:' || (parsed.protocol === 'http:' && (resolved.allowHttp || allowed));
|
|
47
|
+
if (!schemeOk)
|
|
48
|
+
throw new errors_1.OutboundUrlBlockedError('scheme', parsed);
|
|
49
|
+
if (allowed)
|
|
50
|
+
return parsed;
|
|
51
|
+
if (isLocalhost(host))
|
|
52
|
+
throw new errors_1.OutboundUrlBlockedError('private-address', parsed);
|
|
53
|
+
const addresses = (0, node_net_1.isIP)(host) !== 0 ? [host] : await resolveAddresses(parsed, host, (_a = deps.lookup) !== null && _a !== void 0 ? _a : defaultLookup);
|
|
54
|
+
if (addresses.some(address_1.isBlockedAddress))
|
|
55
|
+
throw new errors_1.OutboundUrlBlockedError('private-address', parsed);
|
|
56
|
+
return parsed;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=assert-outbound-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-outbound-url.js","sourceRoot":"","sources":["../../lib/outbound-http/assert-outbound-url.ts"],"names":[],"mappings":";;AA+CA,8CAqBC;AApED,gDAAwD;AACxD,uCAAgC;AAChC,uCAA6C;AAC7C,qCAAmD;AACnD,qCAAiG;AAQjG,MAAM,aAAa,GAAmB,KAAK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ect' | 'timeout' | 'too-large' | 'network';
|
|
2
|
+
export declare function toLoggableUrl(raw: string | URL): string;
|
|
3
|
+
export declare class OutboundUrlBlockedError extends Error {
|
|
4
|
+
readonly reason: OutboundBlockReason;
|
|
5
|
+
readonly url: string;
|
|
6
|
+
constructor(reason: OutboundBlockReason, url: string | URL);
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutboundUrlBlockedError = void 0;
|
|
4
|
+
exports.toLoggableUrl = toLoggableUrl;
|
|
5
|
+
const UNPARSEABLE_URL = '[invalid-url]';
|
|
6
|
+
function toLoggableUrl(raw) {
|
|
7
|
+
try {
|
|
8
|
+
const parsed = typeof raw === 'string' ? new URL(raw) : raw;
|
|
9
|
+
return `${parsed.origin === 'null' ? parsed.protocol : parsed.origin}${parsed.pathname}`;
|
|
10
|
+
}
|
|
11
|
+
catch (_a) {
|
|
12
|
+
return UNPARSEABLE_URL;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class OutboundUrlBlockedError extends Error {
|
|
16
|
+
constructor(reason, url) {
|
|
17
|
+
const safe = toLoggableUrl(url);
|
|
18
|
+
super(`Outbound request blocked (${reason}): ${safe}`);
|
|
19
|
+
this.name = 'OutboundUrlBlockedError';
|
|
20
|
+
this.reason = reason;
|
|
21
|
+
this.url = safe;
|
|
22
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.OutboundUrlBlockedError = OutboundUrlBlockedError;
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../lib/outbound-http/errors.ts"],"names":[],"mappings":";;;AAcA,sCAOC;AAVD,MAAM,eAAe,GAAG,eAAe,CAAC;AAGxC,SAAgB,aAAa,CAAC,GAAiB;IAC7C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAC5D,OAAO,GAAG,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC3F,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,eAAe,CAAC;IACzB,CAAC;AACH,CAAC;AAGD,MAAa,uBAAwB,SAAQ,KAAK;IAKhD,YAAY,MAA2B,EAAE,GAAiB;QACxD,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAChC,KAAK,CAAC,6BAA6B,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAChB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAbD,0DAaC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type OutboundLookup } from './assert-outbound-url';
|
|
2
|
+
import { type OutboundHttpPolicy } from './policy';
|
|
3
|
+
export interface OutboundHttpResponse {
|
|
4
|
+
status: number;
|
|
5
|
+
ok: boolean;
|
|
6
|
+
headers: Headers;
|
|
7
|
+
text(): Promise<string>;
|
|
8
|
+
json(): Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface GuardedHttpClientDeps {
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
lookup?: OutboundLookup;
|
|
13
|
+
}
|
|
14
|
+
export declare class GuardedHttpClient {
|
|
15
|
+
private readonly policy;
|
|
16
|
+
private readonly fetchFn;
|
|
17
|
+
private readonly lookup?;
|
|
18
|
+
constructor(policy?: OutboundHttpPolicy, deps?: GuardedHttpClientDeps);
|
|
19
|
+
get(url: string, headers?: Record<string, string>): Promise<OutboundHttpResponse>;
|
|
20
|
+
postForm(url: string, form: Record<string, string>, headers?: Record<string, string>): Promise<OutboundHttpResponse>;
|
|
21
|
+
private execute;
|
|
22
|
+
private exchange;
|
|
23
|
+
private readBody;
|
|
24
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuardedHttpClient = void 0;
|
|
4
|
+
const assert_outbound_url_1 = require("./assert-outbound-url");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const policy_1 = require("./policy");
|
|
7
|
+
const FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded';
|
|
8
|
+
function mergeHeaders(base, extra) {
|
|
9
|
+
const headers = new Headers(base);
|
|
10
|
+
for (const [name, value] of Object.entries(extra !== null && extra !== void 0 ? extra : {}))
|
|
11
|
+
headers.set(name, value);
|
|
12
|
+
return headers;
|
|
13
|
+
}
|
|
14
|
+
class GuardedHttpClient {
|
|
15
|
+
constructor(policy, deps = {}) {
|
|
16
|
+
var _a;
|
|
17
|
+
this.policy = (0, policy_1.resolveOutboundHttpPolicy)(policy);
|
|
18
|
+
this.fetchFn = (_a = deps.fetch) !== null && _a !== void 0 ? _a : ((input, init) => fetch(input, init));
|
|
19
|
+
this.lookup = deps.lookup;
|
|
20
|
+
}
|
|
21
|
+
get(url, headers) {
|
|
22
|
+
return this.execute(url, { method: 'GET', headers: mergeHeaders({}, headers) });
|
|
23
|
+
}
|
|
24
|
+
postForm(url, form, headers) {
|
|
25
|
+
return this.execute(url, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: mergeHeaders({ 'content-type': FORM_CONTENT_TYPE }, headers),
|
|
28
|
+
body: new URLSearchParams(form),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async execute(rawUrl, init) {
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
let timer;
|
|
34
|
+
const timedOut = new Promise((_resolve, reject) => {
|
|
35
|
+
timer = setTimeout(() => {
|
|
36
|
+
controller.abort();
|
|
37
|
+
reject(new errors_1.OutboundUrlBlockedError('timeout', rawUrl));
|
|
38
|
+
}, this.policy.timeoutMs);
|
|
39
|
+
});
|
|
40
|
+
timedOut.catch(() => undefined);
|
|
41
|
+
const work = (async () => {
|
|
42
|
+
const url = await (0, assert_outbound_url_1.assertOutboundUrl)(rawUrl, this.policy, { lookup: this.lookup });
|
|
43
|
+
if (controller.signal.aborted)
|
|
44
|
+
throw new errors_1.OutboundUrlBlockedError('timeout', url);
|
|
45
|
+
return this.exchange(url, init, controller);
|
|
46
|
+
})();
|
|
47
|
+
work.catch(() => undefined);
|
|
48
|
+
try {
|
|
49
|
+
return await Promise.race([work, timedOut]);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof errors_1.OutboundUrlBlockedError)
|
|
53
|
+
throw error;
|
|
54
|
+
throw new errors_1.OutboundUrlBlockedError(controller.signal.aborted ? 'timeout' : 'network', rawUrl);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async exchange(url, init, controller) {
|
|
61
|
+
var _a;
|
|
62
|
+
const response = await this.fetchFn(url.href, { ...init, redirect: 'manual', signal: controller.signal });
|
|
63
|
+
if (response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400)) {
|
|
64
|
+
await ((_a = response.body) === null || _a === void 0 ? void 0 : _a.cancel().catch(() => undefined));
|
|
65
|
+
throw new errors_1.OutboundUrlBlockedError('redirect', url);
|
|
66
|
+
}
|
|
67
|
+
const body = await this.readBody(response, url);
|
|
68
|
+
return buildResponse(response, body);
|
|
69
|
+
}
|
|
70
|
+
async readBody(response, url) {
|
|
71
|
+
var _a;
|
|
72
|
+
const declared = Number(response.headers.get('content-length'));
|
|
73
|
+
if (Number.isFinite(declared) && declared > this.policy.maxBytes) {
|
|
74
|
+
await ((_a = response.body) === null || _a === void 0 ? void 0 : _a.cancel().catch(() => undefined));
|
|
75
|
+
throw new errors_1.OutboundUrlBlockedError('too-large', url);
|
|
76
|
+
}
|
|
77
|
+
if (!response.body)
|
|
78
|
+
return '';
|
|
79
|
+
const reader = response.body.getReader();
|
|
80
|
+
const chunks = [];
|
|
81
|
+
let total = 0;
|
|
82
|
+
for (;;) {
|
|
83
|
+
const { done, value } = await reader.read();
|
|
84
|
+
if (done)
|
|
85
|
+
break;
|
|
86
|
+
total += value.byteLength;
|
|
87
|
+
if (total > this.policy.maxBytes) {
|
|
88
|
+
await reader.cancel().catch(() => undefined);
|
|
89
|
+
throw new errors_1.OutboundUrlBlockedError('too-large', url);
|
|
90
|
+
}
|
|
91
|
+
chunks.push(value);
|
|
92
|
+
}
|
|
93
|
+
return new TextDecoder().decode(Buffer.concat(chunks));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.GuardedHttpClient = GuardedHttpClient;
|
|
97
|
+
function buildResponse(response, body) {
|
|
98
|
+
return {
|
|
99
|
+
status: response.status,
|
|
100
|
+
ok: response.status >= 200 && response.status < 300,
|
|
101
|
+
headers: new Headers(response.headers),
|
|
102
|
+
text: async () => body,
|
|
103
|
+
json: async () => JSON.parse(body),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=guarded-http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guarded-http-client.js","sourceRoot":"","sources":["../../lib/outbound-http/guarded-http-client.ts"],"names":[],"mappings":";;;AAAA,+DAA+E;AAC/E,qCAAmD;AACnD,qCAA+G;AAe/G,MAAM,iBAAiB,GAAG,mCAAmC,CAAC;AAE9D,SAAS,YAAY,CAAC,IAA4B,EAAE,KAA8B;I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
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./address"), exports);
|
|
18
|
+
__exportStar(require("./assert-outbound-url"), exports);
|
|
19
|
+
__exportStar(require("./errors"), exports);
|
|
20
|
+
__exportStar(require("./guarded-http-client"), exports);
|
|
21
|
+
__exportStar(require("./policy"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/outbound-http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,wDAAsC;AACtC,2CAAyB;AACzB,wDAAsC;AACtC,2CAAyB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface OutboundHttpPolicy {
|
|
2
|
+
allowedHosts?: readonly string[];
|
|
3
|
+
allowHttp?: boolean;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
maxBytes?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ResolvedOutboundHttpPolicy {
|
|
8
|
+
readonly allowedHosts: readonly string[];
|
|
9
|
+
readonly allowHttp: boolean;
|
|
10
|
+
readonly timeoutMs: number;
|
|
11
|
+
readonly maxBytes: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_OUTBOUND_TIMEOUT_MS = 5000;
|
|
14
|
+
export declare const DEFAULT_OUTBOUND_MAX_BYTES = 1048576;
|
|
15
|
+
export declare function normaliseHostname(host: string): string;
|
|
16
|
+
export declare function resolveOutboundHttpPolicy(policy?: OutboundHttpPolicy): ResolvedOutboundHttpPolicy;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_OUTBOUND_MAX_BYTES = exports.DEFAULT_OUTBOUND_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.normaliseHostname = normaliseHostname;
|
|
5
|
+
exports.resolveOutboundHttpPolicy = resolveOutboundHttpPolicy;
|
|
6
|
+
exports.DEFAULT_OUTBOUND_TIMEOUT_MS = 5000;
|
|
7
|
+
exports.DEFAULT_OUTBOUND_MAX_BYTES = 1048576;
|
|
8
|
+
function normaliseHostname(host) {
|
|
9
|
+
let h = host.toLowerCase();
|
|
10
|
+
if (h.startsWith('[') && h.endsWith(']'))
|
|
11
|
+
h = h.slice(1, -1);
|
|
12
|
+
if (h.endsWith('.'))
|
|
13
|
+
h = h.slice(0, -1);
|
|
14
|
+
return h;
|
|
15
|
+
}
|
|
16
|
+
function positiveInt(field, value, fallback) {
|
|
17
|
+
if (value === undefined)
|
|
18
|
+
return fallback;
|
|
19
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value <= 0) {
|
|
20
|
+
throw new TypeError(`OutboundHttpPolicy.${field} must be a positive integer`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function normaliseAllowedHosts(hosts) {
|
|
25
|
+
if (hosts === undefined)
|
|
26
|
+
return Object.freeze([]);
|
|
27
|
+
if (!Array.isArray(hosts) || hosts.some((h) => typeof h !== 'string')) {
|
|
28
|
+
throw new TypeError('OutboundHttpPolicy.allowedHosts must be an array of strings');
|
|
29
|
+
}
|
|
30
|
+
return Object.freeze([...new Set(hosts.map(normaliseHostname))]);
|
|
31
|
+
}
|
|
32
|
+
function resolveOutboundHttpPolicy(policy = {}) {
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
allowedHosts: normaliseAllowedHosts(policy.allowedHosts),
|
|
35
|
+
allowHttp: policy.allowHttp === true,
|
|
36
|
+
timeoutMs: positiveInt('timeoutMs', policy.timeoutMs, exports.DEFAULT_OUTBOUND_TIMEOUT_MS),
|
|
37
|
+
maxBytes: positiveInt('maxBytes', policy.maxBytes, exports.DEFAULT_OUTBOUND_MAX_BYTES),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../lib/outbound-http/policy.ts"],"names":[],"mappings":";;;AAsBA,8CAKC;AAmBD,8DAOC;AAnCY,QAAA,2BAA2B,GAAG,IAAI,CAAC;AACnC,QAAA,0BAA0B,GAAG,OAAS,CAAC;AAGpD,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC3B,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,WAAW,CAAC,KAAa,EAAE,KAAyB,EAAE,QAAgB;IAC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