@procedures/http 0.55.2 → 0.57.0
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/CHANGELOG.md +24 -0
- package/README.md +39 -0
- package/dist/exchange.d.ts +7 -1
- package/dist/exchange.d.ts.map +1 -1
- package/dist/exchange.js +5 -2
- package/dist/exchange.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/proxy.d.ts +80 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +307 -0
- package/dist/proxy.js.map +1 -0
- package/package.json +8 -5
- package/src/exchange.ts +5 -2
- package/src/index.ts +2 -0
- package/src/proxy.ts +357 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @procedures/http
|
|
2
2
|
|
|
3
|
+
## 0.57.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @procedures/client@0.57.0
|
|
8
|
+
|
|
9
|
+
## 0.56.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 7498bc1: `@procedures/http` has a local forward proxy that applies the host policy to each request of another program. `@procedures/browser` uses it for the new option `hostPolicy` of each render. The change adds names and is backward compatible, so it is a patch.
|
|
14
|
+
|
|
15
|
+
- `startPolicyProxy({ policy, onRefusal })` starts the proxy on `127.0.0.1`, on a free port. It gives `host`, `port`, `url`, `refusals`, `requests` and `close()`.
|
|
16
|
+
- The proxy takes `CONNECT` tunnels and plain requests with an absolute `http:` URL. It examines each host with `checkHost`, and connects only to the checked addresses.
|
|
17
|
+
- A refused host gets the status 403. `refusals` keeps the first `MAX_PROXY_REFUSALS` refusals, and `onRefusal` gets each refusal.
|
|
18
|
+
- The options `hostPolicy` and `onHostRefusal` of each render start the proxy for the run, and stop it at the end, also after an error.
|
|
19
|
+
- `policyProxyArgs(proxyUrl)` gives the flags of the browser: the proxy, the bypass rule `<-loopback>`, no QUIC, no UDP for WebRTC and no DNS look-up.
|
|
20
|
+
- With `hostPolicy`, a flag of `args` that can undo these flags gives an error before the browser starts.
|
|
21
|
+
- A Chrome or Edge policy of the computer (`ProxySettings` or `ProxyMode`) replaces `--proxy-server` with no error. Thus a render of an `http:` or `https:` URL fails when the proxy gets no request.
|
|
22
|
+
- `@procedures/browser` now depends on `@procedures/http`.
|
|
23
|
+
- 13996cf: An automated dependency update changes the shipped files, so this PATCH ships them.
|
|
24
|
+
- Updated dependencies [13996cf]
|
|
25
|
+
- @procedures/client@0.56.0
|
|
26
|
+
|
|
3
27
|
## 0.55.2
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -129,6 +129,44 @@ isLocalName("Router.Home.Arpa."); // true
|
|
|
129
129
|
isLocalName("myinternal.example"); // false
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
### The policy proxy for other programs
|
|
133
|
+
|
|
134
|
+
`startPolicyProxy(options)` starts a local forward proxy. The proxy applies the host policy to each request of another program, for example a headless browser.
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { createHostPolicy, startPolicyProxy } from "@procedures/http";
|
|
138
|
+
|
|
139
|
+
const proxy = await startPolicyProxy({
|
|
140
|
+
policy: createHostPolicy({ allow: ["intranet.example"] }),
|
|
141
|
+
onRefusal: (refusal) => console.warn(refusal.method, refusal.target, refusal.reason),
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
// Start the program with the flag `--proxy-server=${proxy.url}`
|
|
145
|
+
} finally {
|
|
146
|
+
await proxy.close();
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
- The proxy listens on `127.0.0.1`, on a free port. `proxy.url` is its address, for example `http://127.0.0.1:41234`.
|
|
151
|
+
- A `CONNECT` request opens a tunnel to `host:port`. A browser sends `https:`, `wss:` and `ws:` requests in a tunnel.
|
|
152
|
+
- A plain request has an absolute `http:` URL, for example `GET http://a.example/page`. The proxy sends it to the host, and gives back the response.
|
|
153
|
+
- The proxy examines the host of each request with `checkHost`. The connection uses only the checked addresses, so a second DNS answer cannot change the address.
|
|
154
|
+
- The proxy gives the status 403 to a host that the policy refuses. The page of the 403 does not tell the reason.
|
|
155
|
+
- `proxy.refusals` gives the first 1000 refusals (`MAX_PROXY_REFUSALS`). `onRefusal` gets each refusal at its time. An error of `onRefusal` does not stop the proxy.
|
|
156
|
+
- A host with no address, a connection that fails and a response with a bad status (for example 99) get the status 502. Each other request gets the status 400.
|
|
157
|
+
- The proxy does not send the headers of one connection, for example `proxy-authorization` and `connection`.
|
|
158
|
+
- `proxy.requests` gives the number of requests that the proxy got, also each refused request. The value stays after `close()`.
|
|
159
|
+
- `close()` closes each open connection and the listener. Then the port is free. A second call does nothing.
|
|
160
|
+
- The default policy is `DEFAULT_HOST_POLICY`: each public host, and no other host.
|
|
161
|
+
|
|
162
|
+
`@procedures/browser` uses the proxy for its option `hostPolicy`.
|
|
163
|
+
|
|
164
|
+
Use the proxy only for one run, and close it at the end of the run:
|
|
165
|
+
|
|
166
|
+
- The listener has no token. While the proxy runs, each program on this computer can send requests through it.
|
|
167
|
+
- Such a program can reach each host that the policy permits. With an `allow` entry for an intranet host, it can reach that intranet host.
|
|
168
|
+
- The connections to the hosts have no idle time-out. `close()` closes them.
|
|
169
|
+
|
|
132
170
|
## Limits and time
|
|
133
171
|
|
|
134
172
|
- Each input of `http.request` and `http.json` has `timeoutMs`. The default is 30 seconds.
|
|
@@ -190,6 +228,7 @@ const decision = frameRefusal(response.headers, { ancestor: "https://a.example",
|
|
|
190
228
|
## Limits of this package
|
|
191
229
|
|
|
192
230
|
- The procedures do not use a proxy.
|
|
231
|
+
- The policy proxy does not decrypt a tunnel. It examines the host and the port of a tunnel, not the requests in it.
|
|
193
232
|
- Each request gets its own connection. The procedures do not keep connections open.
|
|
194
233
|
- The check and the connection use the same addresses. A server can still send a redirect, and the check examines it before its connection.
|
|
195
234
|
|
package/dist/exchange.d.ts
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* each redirect itself and examines each new host. Each request gets its own connection.
|
|
8
8
|
*/
|
|
9
9
|
import { type IncomingHttpHeaders, type IncomingMessage } from "node:http";
|
|
10
|
+
import type { LookupFunction } from "node:net";
|
|
10
11
|
import { type Readable } from "node:stream";
|
|
11
12
|
import type { ProcedurePath } from "@procedures/client";
|
|
12
13
|
import { HttpError } from "./errors.js";
|
|
13
|
-
import { type HostPolicy } from "./policy.js";
|
|
14
|
+
import { type AllowedTarget, type HostPolicy } from "./policy.js";
|
|
14
15
|
import type { CallScope } from "./scope.js";
|
|
15
16
|
/** One mebibyte. */
|
|
16
17
|
export declare const MIB: number;
|
|
@@ -91,6 +92,11 @@ export interface StreamRequestParts extends RequestParts {
|
|
|
91
92
|
* throw.
|
|
92
93
|
*/
|
|
93
94
|
export declare function prepareStream(parts: StreamRequestParts, path: ProcedurePath, settings: HttpSettings, headers: Record<string, string>): PreparedRequest;
|
|
95
|
+
/**
|
|
96
|
+
* A `lookup` for the socket that gives only the addresses that the check allowed. The exchange and
|
|
97
|
+
* the policy proxy (`proxy.ts`) use it.
|
|
98
|
+
*/
|
|
99
|
+
export declare function pinnedLookup(target: AllowedTarget): LookupFunction;
|
|
94
100
|
/** The text of a header value: several values are joined with a comma. */
|
|
95
101
|
export declare function headerText(value: string | string[] | undefined): string | undefined;
|
|
96
102
|
/**
|
package/dist/exchange.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.d.ts","sourceRoot":"","sources":["../src/exchange.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA2B,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAuB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"exchange.d.ts","sourceRoot":"","sources":["../src/exchange.ts"],"names":[],"mappings":"AAAA;;;;;;;GA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EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyDhH;AAED,gGAAgG;AAChG,wBAAsB,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CA6B7H;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAM/F;AAED,qDAAqD;AACrD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,SAAM,GAAG,MAAM,CAGnE;AAED,uCAAuC;AACvC,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAoBxF;AAED,gFAAgF;AAChF,wBAAuB,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,GAAG,cAAc,CAAC,UAAU,GAAG,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAKtH"}
|
package/dist/exchange.js
CHANGED
|
@@ -105,8 +105,11 @@ export function prepareStream(parts, path, settings, headers) {
|
|
|
105
105
|
const extra = body === undefined ? headers : { ...headers, "content-type": body.type };
|
|
106
106
|
return prepare({ ...parts, method }, path, settings, { headers: extra, body: body?.bytes });
|
|
107
107
|
}
|
|
108
|
-
/**
|
|
109
|
-
|
|
108
|
+
/**
|
|
109
|
+
* A `lookup` for the socket that gives only the addresses that the check allowed. The exchange and
|
|
110
|
+
* the policy proxy (`proxy.ts`) use it.
|
|
111
|
+
*/
|
|
112
|
+
export function pinnedLookup(target) {
|
|
110
113
|
return (_hostname, options, callback) => {
|
|
111
114
|
const family = options.family === "IPv4" ? 4 : options.family === "IPv6" ? 6 : options.family;
|
|
112
115
|
const addresses = family === 4 || family === 6 ? target.addresses.filter((entry) => entry.family === family) : target.addresses;
|
package/dist/exchange.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../src/exchange.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,IAAI,YAAY,EAAuE,MAAM,WAAW,CAAC;AACzH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEhF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAuC,MAAM,aAAa,CAAC;AAGlG,oBAAoB;AACpB,MAAM,CAAC,MAAM,GAAG,GAAW,IAAI,GAAG,IAAI,CAAC;AAEvC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAW,EAAE,GAAG,GAAG,CAAC;AAElD,qFAAqF;AACrF,MAAM,CAAC,MAAM,kBAAkB,GAAW,GAAG,CAAC;AAE9C,sEAAsE;AACtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAWvC,sFAAsF;AACtF,MAAM,CAAC,MAAM,gBAAgB,GAAiB;IAC5C,MAAM,EAAE,mBAAmB;IAC3B,eAAe,EAAE,iBAAiB;IAClC,gBAAgB,EAAE,iBAAiB;CACpC,CAAC;AAEF,sEAAsE;AACtE,MAAM,eAAe,GAAqC;IACxD,iBAAiB,EAAE,mBAAmB;IAC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IAAI,SAAS,CAAC,aAAa,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAC3I,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAc,EAAE,KAAgB;IAC9D,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QAC/B,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,MAAM,KAA4B,CAAC;IACrC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { httpRequest, httpJson, httpNdjson, httpSse } from "./procedures/http/in
|
|
|
4
4
|
export { HOST_NOT_ALLOWED, DEFAULT_HOST_POLICY, createHostPolicy, checkHost, isHostNotAllowed, systemResolver } from "./policy.js";
|
|
5
5
|
export { createHostFetch, type HostFetch, type HostFetchInit, type HostFetchResponse } from "./host-fetch.js";
|
|
6
6
|
export type { AllowedTarget, HostPolicy, HostPolicyOptions, HostResolver, ResolvedAddress } from "./policy.js";
|
|
7
|
+
export { MAX_PROXY_REFUSALS, PROXY_HOST, startPolicyProxy, type PolicyProxy, type PolicyProxyOptions, type ProxyRefusal } from "./proxy.js";
|
|
7
8
|
export { isLocalName, isPublicAddress, parseAddress, specialClass } from "./address.js";
|
|
8
9
|
export { HttpError, type HttpErrorCode } from "./errors.js";
|
|
9
10
|
export { DEFAULT_MAX_BYTES, DEFAULT_ITEM_BYTES, DEFAULT_TIMEOUT_MS, DEFAULT_SETTINGS, type HttpSettings } from "./exchange.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA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E,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/H,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAE7F,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpF,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export { httpRequest, httpJson, httpNdjson, httpSse } from "./procedures/http/in
|
|
|
6
6
|
export { HOST_NOT_ALLOWED, DEFAULT_HOST_POLICY, createHostPolicy, checkHost, isHostNotAllowed, systemResolver } from "./policy.js";
|
|
7
7
|
// A fetch for GET requests through the host policy, for the procedures of other packages (O55)
|
|
8
8
|
export { createHostFetch } from "./host-fetch.js";
|
|
9
|
+
// A local forward proxy that applies the host policy to each request of another program, for example a headless browser
|
|
10
|
+
export { MAX_PROXY_REFUSALS, PROXY_HOST, startPolicyProxy } from "./proxy.js";
|
|
9
11
|
export { isLocalName, isPublicAddress, parseAddress, specialClass } from "./address.js";
|
|
10
12
|
export { HttpError } from "./errors.js";
|
|
11
13
|
export { DEFAULT_MAX_BYTES, DEFAULT_ITEM_BYTES, DEFAULT_TIMEOUT_MS, DEFAULT_SETTINGS } from "./exchange.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,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,cAAc,CAAC;AACxF,OAAO,EAAE,SAAS,EAAsB,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAqB,MAAM,eAAe,CAAC;AAC/H,OAAO,EAAE,WAAW,EAAE,SAAS,EAAyC,MAAM,cAAc,CAAC;AAC7F,6EAA6E;AAC7E,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A local forward proxy that applies the host policy to each request of another program, for
|
|
3
|
+
* example a headless browser. The program sends each request to the proxy. Thus a redirect, a
|
|
4
|
+
* resource of a page and a second DNS answer go through the same check as the first request.
|
|
5
|
+
*
|
|
6
|
+
* - The proxy listens on `127.0.0.1`, on a free port.
|
|
7
|
+
* - A `CONNECT` request opens a tunnel to `host:port`. A browser uses it for `https:`, `wss:` and
|
|
8
|
+
* `ws:` URLs.
|
|
9
|
+
* - A plain request has an absolute `http:` URL, for example `GET http://a.example/page`. The proxy
|
|
10
|
+
* sends the request to the host, and gives the response back.
|
|
11
|
+
* - For each request, the proxy examines the host with `checkHost`. The connection uses only the
|
|
12
|
+
* addresses that the check allowed, so a second DNS answer cannot change the address (DNS
|
|
13
|
+
* rebinding).
|
|
14
|
+
* - A host that the policy refuses gets the status 403. The proxy records each refusal and gives
|
|
15
|
+
* it to `onRefusal`.
|
|
16
|
+
* - A host with no address, a connection that fails and a response that the proxy cannot send on
|
|
17
|
+
* get the status 502.
|
|
18
|
+
* - Each other request gets the status 400.
|
|
19
|
+
*/
|
|
20
|
+
import { type HostPolicy } from "./policy.js";
|
|
21
|
+
/** The address of the listener of the proxy. */
|
|
22
|
+
export declare const PROXY_HOST = "127.0.0.1";
|
|
23
|
+
/** The largest number of refusals that `PolicyProxy.refusals` keeps. `onRefusal` gets each refusal. */
|
|
24
|
+
export declare const MAX_PROXY_REFUSALS = 1000;
|
|
25
|
+
/** One request that the proxy refused. */
|
|
26
|
+
export interface ProxyRefusal {
|
|
27
|
+
/** The method of the request: `CONNECT`, or the method of a plain request. */
|
|
28
|
+
readonly method: string;
|
|
29
|
+
/** The target of the request: `host:port` for `CONNECT`, else the URL. */
|
|
30
|
+
readonly target: string;
|
|
31
|
+
/** The reason of the refusal: the message of the host check. */
|
|
32
|
+
readonly reason: string;
|
|
33
|
+
}
|
|
34
|
+
/** The options of `startPolicyProxy()`. */
|
|
35
|
+
export interface PolicyProxyOptions {
|
|
36
|
+
/** The host policy of each request. The default is `DEFAULT_HOST_POLICY`: each public host, and no other host. */
|
|
37
|
+
readonly policy?: HostPolicy | undefined;
|
|
38
|
+
/** This function gets each refusal at the time of the refusal. An error of the function does not stop the proxy. */
|
|
39
|
+
readonly onRefusal?: ((refusal: ProxyRefusal) => void) | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** A proxy that runs. */
|
|
42
|
+
export interface PolicyProxy {
|
|
43
|
+
/** The address of the listener: `127.0.0.1`. */
|
|
44
|
+
readonly host: string;
|
|
45
|
+
/** The port of the listener. */
|
|
46
|
+
readonly port: number;
|
|
47
|
+
/** The URL of the proxy, for example `http://127.0.0.1:41234`. A browser gets it in `--proxy-server`. */
|
|
48
|
+
readonly url: string;
|
|
49
|
+
/** The refusals until now, in their order. The list keeps the first `MAX_PROXY_REFUSALS` refusals. */
|
|
50
|
+
readonly refusals: readonly ProxyRefusal[];
|
|
51
|
+
/**
|
|
52
|
+
* The number of requests that the proxy got: each `CONNECT` request and each plain request, also a refused
|
|
53
|
+
* request and a request with a bad form. The value stays after `close()`. When a program that
|
|
54
|
+
* has the URL of the proxy loads a page, and the value is 0, the program did not use the proxy.
|
|
55
|
+
*/
|
|
56
|
+
readonly requests: number;
|
|
57
|
+
/** This function stops the listener and closes each open connection. Then the port is free. A second call does nothing. */
|
|
58
|
+
close(): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* This function starts a forward proxy on `127.0.0.1`, on a free port, and gives its address. The
|
|
62
|
+
* proxy applies the host policy to each request. Give its URL to a program, for example in the
|
|
63
|
+
* flag `--proxy-server` of a browser. Call `close()` at the end.
|
|
64
|
+
*
|
|
65
|
+
* - The listener has no token. While the proxy runs, each program on this computer can send
|
|
66
|
+
* requests through it, to each host that the policy permits.
|
|
67
|
+
* - The connections to the hosts have no idle time-out. Thus keep the proxy only for one run:
|
|
68
|
+
* `close()` closes each connection.
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* const proxy = await startPolicyProxy({ policy: createHostPolicy({ allow: ["intranet.example"] }) });
|
|
72
|
+
* try {
|
|
73
|
+
* // Start the program with proxy.url
|
|
74
|
+
* } finally {
|
|
75
|
+
* await proxy.close();
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function startPolicyProxy(options?: PolicyProxyOptions): Promise<PolicyProxy>;
|
|
80
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAwE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpH,gDAAgD;AAChD,eAAO,MAAM,UAAU,cAAc,CAAC;AAEtC,uGAAuG;AACvG,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAKvC,0CAA0C;AAC1C,MAAM,WAAW,YAAY;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,kHAAkH;IAClH,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACzC,oHAAoH;IACpH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACpE;AAED,yBAAyB;AACzB,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2HAA2H;IAC3H,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AA2FD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC,CA+K7F"}
|
package/dist/proxy.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A local forward proxy that applies the host policy to each request of another program, for
|
|
3
|
+
* example a headless browser. The program sends each request to the proxy. Thus a redirect, a
|
|
4
|
+
* resource of a page and a second DNS answer go through the same check as the first request.
|
|
5
|
+
*
|
|
6
|
+
* - The proxy listens on `127.0.0.1`, on a free port.
|
|
7
|
+
* - A `CONNECT` request opens a tunnel to `host:port`. A browser uses it for `https:`, `wss:` and
|
|
8
|
+
* `ws:` URLs.
|
|
9
|
+
* - A plain request has an absolute `http:` URL, for example `GET http://a.example/page`. The proxy
|
|
10
|
+
* sends the request to the host, and gives the response back.
|
|
11
|
+
* - For each request, the proxy examines the host with `checkHost`. The connection uses only the
|
|
12
|
+
* addresses that the check allowed, so a second DNS answer cannot change the address (DNS
|
|
13
|
+
* rebinding).
|
|
14
|
+
* - A host that the policy refuses gets the status 403. The proxy records each refusal and gives
|
|
15
|
+
* it to `onRefusal`.
|
|
16
|
+
* - A host with no address, a connection that fails and a response that the proxy cannot send on
|
|
17
|
+
* get the status 502.
|
|
18
|
+
* - Each other request gets the status 400.
|
|
19
|
+
*/
|
|
20
|
+
import { createServer, request as plainRequest, STATUS_CODES } from "node:http";
|
|
21
|
+
import { connect } from "node:net";
|
|
22
|
+
import { pinnedLookup } from "./exchange.js";
|
|
23
|
+
import { checkHost, DEFAULT_HOST_POLICY, isHostNotAllowed } from "./policy.js";
|
|
24
|
+
/** The address of the listener of the proxy. */
|
|
25
|
+
export const PROXY_HOST = "127.0.0.1";
|
|
26
|
+
/** The largest number of refusals that `PolicyProxy.refusals` keeps. `onRefusal` gets each refusal. */
|
|
27
|
+
export const MAX_PROXY_REFUSALS = 1000;
|
|
28
|
+
/** The path of the proxy in the messages of the host check. */
|
|
29
|
+
const PROXY_PATH = ["http", "proxy"];
|
|
30
|
+
/** The text of a 403 answer. The refusal record has the reason, and the page does not get it. */
|
|
31
|
+
const REFUSED = "The host policy of the proxy refuses this host.";
|
|
32
|
+
/** The text of a 502 answer when the connection fails. */
|
|
33
|
+
const NO_CONNECTION = "The proxy cannot connect to this host.";
|
|
34
|
+
/** The text of a 502 answer when the response of the host has a status that the proxy cannot send on, for example 99. */
|
|
35
|
+
const BAD_RESPONSE = "The host gave a response that the proxy cannot send on.";
|
|
36
|
+
/** The headers of one connection (RFC 9110, section 7.6.1). The proxy does not send them on. */
|
|
37
|
+
const HOP_BY_HOP = new Set([
|
|
38
|
+
"connection",
|
|
39
|
+
"keep-alive",
|
|
40
|
+
"proxy-authenticate",
|
|
41
|
+
"proxy-authorization",
|
|
42
|
+
"proxy-connection",
|
|
43
|
+
"te",
|
|
44
|
+
"trailer",
|
|
45
|
+
"transfer-encoding",
|
|
46
|
+
"upgrade",
|
|
47
|
+
]);
|
|
48
|
+
/** The headers without the headers of one connection, and without each header that `connection` names. */
|
|
49
|
+
function endToEnd(headers) {
|
|
50
|
+
const named = new Set(String(headers.connection ?? "").split(",").map((token) => token.trim().toLowerCase()));
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
53
|
+
if (!HOP_BY_HOP.has(name) && !named.has(name))
|
|
54
|
+
out[name] = value;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** The target of `CONNECT`: a host name, an IPv4 address or an IPv6 address in brackets, then a port. */
|
|
59
|
+
const AUTHORITY = /^(\[[0-9a-f:.]+\]|[^\s/?#@[\]:]+):([0-9]{1,5})$/i;
|
|
60
|
+
/**
|
|
61
|
+
* This function gives the URL of the target of a `CONNECT` request (`host:port`), or undefined for
|
|
62
|
+
* another form. The URL parser gives the normal form of the host, for example `127.0.0.1` for
|
|
63
|
+
* `0x7f.1`. Thus the check and the connection use the same host.
|
|
64
|
+
*/
|
|
65
|
+
function connectUrl(authority) {
|
|
66
|
+
const match = AUTHORITY.exec(authority);
|
|
67
|
+
if (!match)
|
|
68
|
+
return undefined;
|
|
69
|
+
const port = Number(match[2]);
|
|
70
|
+
if (port < 1 || port > 65_535)
|
|
71
|
+
return undefined;
|
|
72
|
+
try {
|
|
73
|
+
return new URL(`http://${match[1]}:${port}/`);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** The URL of a plain request: an absolute `http:` URL, or undefined. */
|
|
80
|
+
function plainUrl(target) {
|
|
81
|
+
if (!/^http:\/\//i.test(target))
|
|
82
|
+
return undefined;
|
|
83
|
+
try {
|
|
84
|
+
return new URL(target);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** This function writes a failure to the socket of a `CONNECT` request, and ends the socket. */
|
|
91
|
+
function rawAnswer(socket, failure) {
|
|
92
|
+
const body = `${failure.message}\n`;
|
|
93
|
+
socket.end(`HTTP/1.1 ${failure.status} ${STATUS_CODES[failure.status]}\r\n` +
|
|
94
|
+
`content-type: text/plain; charset=utf-8\r\ncontent-length: ${Buffer.byteLength(body)}\r\nconnection: close\r\n\r\n${body}`);
|
|
95
|
+
}
|
|
96
|
+
/** This function writes a failure as the response of a plain request. */
|
|
97
|
+
function answer(response, failure) {
|
|
98
|
+
const body = `${failure.message}\n`;
|
|
99
|
+
// A failed writeHead keeps the status text of the host. Thus the answer gives its own status text
|
|
100
|
+
response.writeHead(failure.status, String(STATUS_CODES[failure.status]), {
|
|
101
|
+
"content-type": "text/plain; charset=utf-8",
|
|
102
|
+
"content-length": Buffer.byteLength(body),
|
|
103
|
+
connection: "close",
|
|
104
|
+
});
|
|
105
|
+
response.end(body);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* This function starts a forward proxy on `127.0.0.1`, on a free port, and gives its address. The
|
|
109
|
+
* proxy applies the host policy to each request. Give its URL to a program, for example in the
|
|
110
|
+
* flag `--proxy-server` of a browser. Call `close()` at the end.
|
|
111
|
+
*
|
|
112
|
+
* - The listener has no token. While the proxy runs, each program on this computer can send
|
|
113
|
+
* requests through it, to each host that the policy permits.
|
|
114
|
+
* - The connections to the hosts have no idle time-out. Thus keep the proxy only for one run:
|
|
115
|
+
* `close()` closes each connection.
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* const proxy = await startPolicyProxy({ policy: createHostPolicy({ allow: ["intranet.example"] }) });
|
|
119
|
+
* try {
|
|
120
|
+
* // Start the program with proxy.url
|
|
121
|
+
* } finally {
|
|
122
|
+
* await proxy.close();
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export async function startPolicyProxy(options = {}) {
|
|
127
|
+
const policy = options.policy ?? DEFAULT_HOST_POLICY;
|
|
128
|
+
const refusals = [];
|
|
129
|
+
const sockets = new Set();
|
|
130
|
+
let requests = 0;
|
|
131
|
+
let closed = false;
|
|
132
|
+
/**
|
|
133
|
+
* This function keeps a socket until it closes, so that `close()` can close it. No socket comes
|
|
134
|
+
* after `close()`: the server takes no connection, the check of a request stops each new
|
|
135
|
+
* connection, and the close of the client socket stops a request in progress.
|
|
136
|
+
*/
|
|
137
|
+
const track = (socket) => {
|
|
138
|
+
sockets.add(socket);
|
|
139
|
+
socket.once("close", () => sockets.delete(socket));
|
|
140
|
+
};
|
|
141
|
+
/** This function examines the host of a request. It gives the checked target, or the failure. */
|
|
142
|
+
const examine = async (url, method, target) => {
|
|
143
|
+
try {
|
|
144
|
+
return await checkHost(policy, url, PROXY_PATH, `the ${method} request`);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (!isHostNotAllowed(error))
|
|
148
|
+
return { status: 502, message: NO_CONNECTION };
|
|
149
|
+
// isHostNotAllowed gives true only for an InvocationError
|
|
150
|
+
const refusal = { method, target, reason: error.message };
|
|
151
|
+
if (refusals.length < MAX_PROXY_REFUSALS)
|
|
152
|
+
refusals.push(refusal);
|
|
153
|
+
try {
|
|
154
|
+
options.onRefusal?.(refusal);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// An error of the callback does not stop the proxy
|
|
158
|
+
}
|
|
159
|
+
return { status: 403, message: REFUSED };
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
/** A `CONNECT` request: a tunnel to the checked addresses of the target. */
|
|
163
|
+
const tunnel = async (request, client, head) => {
|
|
164
|
+
requests += 1;
|
|
165
|
+
let upstream;
|
|
166
|
+
// An error of the client socket closes it. Then the tunnel closes too
|
|
167
|
+
const drop = () => {
|
|
168
|
+
upstream?.destroy();
|
|
169
|
+
};
|
|
170
|
+
client.on("error", drop);
|
|
171
|
+
client.once("close", drop);
|
|
172
|
+
// The server sets the URL of each request
|
|
173
|
+
const authority = String(request.url);
|
|
174
|
+
const url = connectUrl(authority);
|
|
175
|
+
if (url === undefined) {
|
|
176
|
+
rawAnswer(client, { status: 400, message: "The target of CONNECT is host:port." });
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const checked = await examine(url, "CONNECT", authority);
|
|
180
|
+
if (client.destroyed || closed) {
|
|
181
|
+
client.destroy();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if ("status" in checked) {
|
|
185
|
+
rawAnswer(client, checked);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const socket = connect({ host: checked.hostname, port: checked.port, lookup: pinnedLookup(checked) });
|
|
189
|
+
upstream = socket;
|
|
190
|
+
track(socket);
|
|
191
|
+
let open = false;
|
|
192
|
+
socket.once("connect", () => {
|
|
193
|
+
open = true;
|
|
194
|
+
client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
195
|
+
if (head.length > 0)
|
|
196
|
+
socket.write(head);
|
|
197
|
+
socket.pipe(client);
|
|
198
|
+
client.pipe(socket);
|
|
199
|
+
});
|
|
200
|
+
socket.on("error", () => {
|
|
201
|
+
if (open)
|
|
202
|
+
client.destroy();
|
|
203
|
+
else
|
|
204
|
+
rawAnswer(client, { status: 502, message: NO_CONNECTION });
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
/** A plain request: the request goes to the checked addresses of its host, and the response comes back. */
|
|
208
|
+
const forward = async (request, response) => {
|
|
209
|
+
requests += 1;
|
|
210
|
+
// The server sets the method and the URL of each request
|
|
211
|
+
const method = String(request.method);
|
|
212
|
+
const url = plainUrl(String(request.url));
|
|
213
|
+
if (url === undefined) {
|
|
214
|
+
request.resume();
|
|
215
|
+
answer(response, { status: 400, message: "The proxy takes CONNECT requests, and requests for an absolute http: URL." });
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const checked = await examine(url, method, url.href);
|
|
219
|
+
if (response.destroyed || closed) {
|
|
220
|
+
response.destroy();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if ("status" in checked) {
|
|
224
|
+
request.resume();
|
|
225
|
+
answer(response, checked);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const outgoing = plainRequest({
|
|
229
|
+
host: checked.hostname,
|
|
230
|
+
port: checked.port,
|
|
231
|
+
method,
|
|
232
|
+
path: `${url.pathname}${url.search}`,
|
|
233
|
+
// A proxy sends the host of the URL, not the host header of the request (RFC 9112, section 3.2.2)
|
|
234
|
+
headers: { ...endToEnd(request.headers), host: url.host },
|
|
235
|
+
setHost: false,
|
|
236
|
+
lookup: pinnedLookup(checked),
|
|
237
|
+
// A connection of its own: a pooled socket could belong to another check
|
|
238
|
+
agent: false,
|
|
239
|
+
});
|
|
240
|
+
outgoing.on("socket", track);
|
|
241
|
+
outgoing.on("response", (upstream) => {
|
|
242
|
+
try {
|
|
243
|
+
// The client parser sets the status. writeHead refuses some of them, for example 99
|
|
244
|
+
response.writeHead(Number(upstream.statusCode), upstream.statusMessage, endToEnd(upstream.headers));
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
upstream.destroy();
|
|
248
|
+
answer(response, { status: 502, message: BAD_RESPONSE });
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
// A response that stops early stops the response to the client too
|
|
252
|
+
upstream.on("error", () => response.destroy());
|
|
253
|
+
upstream.pipe(response);
|
|
254
|
+
});
|
|
255
|
+
outgoing.on("error", () => {
|
|
256
|
+
if (response.headersSent)
|
|
257
|
+
response.destroy();
|
|
258
|
+
else
|
|
259
|
+
answer(response, { status: 502, message: NO_CONNECTION });
|
|
260
|
+
});
|
|
261
|
+
// When the client connection closes before the end of the response, the request to the host stops.
|
|
262
|
+
// A request body that stops early closes the client connection too
|
|
263
|
+
response.once("close", () => {
|
|
264
|
+
if (!response.writableFinished)
|
|
265
|
+
outgoing.destroy();
|
|
266
|
+
});
|
|
267
|
+
request.pipe(outgoing);
|
|
268
|
+
};
|
|
269
|
+
const server = createServer();
|
|
270
|
+
server.on("connection", track);
|
|
271
|
+
// The two functions do not reject. If one does, the bound destroy closes the connection with the error
|
|
272
|
+
server.on("connect", (request, client, head) => {
|
|
273
|
+
tunnel(request, client, head).catch(client.destroy.bind(client));
|
|
274
|
+
});
|
|
275
|
+
server.on("request", (request, response) => {
|
|
276
|
+
forward(request, response).catch(response.destroy.bind(response));
|
|
277
|
+
});
|
|
278
|
+
await new Promise((resolve, reject) => {
|
|
279
|
+
// reject stays the listener of "error". After the start it does nothing, and an error does not stop the process
|
|
280
|
+
server.on("error", reject);
|
|
281
|
+
server.listen(0, PROXY_HOST, resolve);
|
|
282
|
+
});
|
|
283
|
+
const { port } = server.address();
|
|
284
|
+
let closing;
|
|
285
|
+
const close = () => {
|
|
286
|
+
closing ??= new Promise((resolve) => {
|
|
287
|
+
closed = true;
|
|
288
|
+
server.close(() => resolve());
|
|
289
|
+
for (const socket of sockets)
|
|
290
|
+
socket.destroy();
|
|
291
|
+
});
|
|
292
|
+
return closing;
|
|
293
|
+
};
|
|
294
|
+
return {
|
|
295
|
+
host: PROXY_HOST,
|
|
296
|
+
port,
|
|
297
|
+
url: `http://${PROXY_HOST}:${port}`,
|
|
298
|
+
get refusals() {
|
|
299
|
+
return [...refusals];
|
|
300
|
+
},
|
|
301
|
+
get requests() {
|
|
302
|
+
return requests;
|
|
303
|
+
},
|
|
304
|
+
close,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,OAAO,IAAI,YAAY,EAAE,YAAY,EAAiG,MAAM,WAAW,CAAC;AAC/K,OAAO,EAAE,OAAO,EAAiC,MAAM,UAAU,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,mBA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C,IAAI,QAAQ;YACV,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,QAAQ;YACV,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/http",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.57.0",
|
|
5
5
|
"description": "HTTP as procedures: request, JSON, NDJSON and server-sent events, with a host allowlist that refuses private addresses, size limits and the deadline of the call.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"procedures",
|
|
@@ -30,15 +30,18 @@
|
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
|
-
"import": "./dist/index.js"
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
34
35
|
},
|
|
35
36
|
"./module": {
|
|
36
37
|
"types": "./dist/module.d.ts",
|
|
37
|
-
"import": "./dist/module.js"
|
|
38
|
+
"import": "./dist/module.js",
|
|
39
|
+
"default": "./dist/module.js"
|
|
38
40
|
},
|
|
39
41
|
"./register": {
|
|
40
42
|
"types": "./dist/register.d.ts",
|
|
41
|
-
"import": "./dist/register.js"
|
|
43
|
+
"import": "./dist/register.js",
|
|
44
|
+
"default": "./dist/register.js"
|
|
42
45
|
}
|
|
43
46
|
},
|
|
44
47
|
"files": [
|
|
@@ -71,7 +74,7 @@
|
|
|
71
74
|
"procedures": "./dist/register.js"
|
|
72
75
|
},
|
|
73
76
|
"dependencies": {
|
|
74
|
-
"@procedures/client": "0.
|
|
77
|
+
"@procedures/client": "0.57.0",
|
|
75
78
|
"zod": "^4.6.5"
|
|
76
79
|
},
|
|
77
80
|
"scripts": {
|
package/src/exchange.ts
CHANGED
|
@@ -175,8 +175,11 @@ export function prepareStream(parts: StreamRequestParts, path: ProcedurePath, se
|
|
|
175
175
|
return prepare({ ...parts, method }, path, settings, { headers: extra, body: body?.bytes });
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
/**
|
|
179
|
-
|
|
178
|
+
/**
|
|
179
|
+
* A `lookup` for the socket that gives only the addresses that the check allowed. The exchange and
|
|
180
|
+
* the policy proxy (`proxy.ts`) use it.
|
|
181
|
+
*/
|
|
182
|
+
export function pinnedLookup(target: AllowedTarget): LookupFunction {
|
|
180
183
|
return (_hostname, options, callback) => {
|
|
181
184
|
const family = options.family === "IPv4" ? 4 : options.family === "IPv6" ? 6 : options.family;
|
|
182
185
|
const addresses = family === 4 || family === 6 ? target.addresses.filter((entry) => entry.family === family) : target.addresses;
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,8 @@ export { HOST_NOT_ALLOWED, DEFAULT_HOST_POLICY, createHostPolicy, checkHost, isH
|
|
|
7
7
|
// A fetch for GET requests through the host policy, for the procedures of other packages (O55)
|
|
8
8
|
export { createHostFetch, type HostFetch, type HostFetchInit, type HostFetchResponse } from "./host-fetch.js";
|
|
9
9
|
export type { AllowedTarget, HostPolicy, HostPolicyOptions, HostResolver, ResolvedAddress } from "./policy.js";
|
|
10
|
+
// A local forward proxy that applies the host policy to each request of another program, for example a headless browser
|
|
11
|
+
export { MAX_PROXY_REFUSALS, PROXY_HOST, startPolicyProxy, type PolicyProxy, type PolicyProxyOptions, type ProxyRefusal } from "./proxy.js";
|
|
10
12
|
export { isLocalName, isPublicAddress, parseAddress, specialClass } from "./address.js";
|
|
11
13
|
export { HttpError, type HttpErrorCode } from "./errors.js";
|
|
12
14
|
export { DEFAULT_MAX_BYTES, DEFAULT_ITEM_BYTES, DEFAULT_TIMEOUT_MS, DEFAULT_SETTINGS, type HttpSettings } from "./exchange.js";
|
package/src/proxy.ts
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A local forward proxy that applies the host policy to each request of another program, for
|
|
3
|
+
* example a headless browser. The program sends each request to the proxy. Thus a redirect, a
|
|
4
|
+
* resource of a page and a second DNS answer go through the same check as the first request.
|
|
5
|
+
*
|
|
6
|
+
* - The proxy listens on `127.0.0.1`, on a free port.
|
|
7
|
+
* - A `CONNECT` request opens a tunnel to `host:port`. A browser uses it for `https:`, `wss:` and
|
|
8
|
+
* `ws:` URLs.
|
|
9
|
+
* - A plain request has an absolute `http:` URL, for example `GET http://a.example/page`. The proxy
|
|
10
|
+
* sends the request to the host, and gives the response back.
|
|
11
|
+
* - For each request, the proxy examines the host with `checkHost`. The connection uses only the
|
|
12
|
+
* addresses that the check allowed, so a second DNS answer cannot change the address (DNS
|
|
13
|
+
* rebinding).
|
|
14
|
+
* - A host that the policy refuses gets the status 403. The proxy records each refusal and gives
|
|
15
|
+
* it to `onRefusal`.
|
|
16
|
+
* - A host with no address, a connection that fails and a response that the proxy cannot send on
|
|
17
|
+
* get the status 502.
|
|
18
|
+
* - Each other request gets the status 400.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { createServer, request as plainRequest, STATUS_CODES, type IncomingHttpHeaders, type IncomingMessage, type OutgoingHttpHeaders, type ServerResponse } from "node:http";
|
|
22
|
+
import { connect, type AddressInfo, type Socket } from "node:net";
|
|
23
|
+
import type { Duplex } from "node:stream";
|
|
24
|
+
import { pinnedLookup } from "./exchange.js";
|
|
25
|
+
import { checkHost, DEFAULT_HOST_POLICY, isHostNotAllowed, type AllowedTarget, type HostPolicy } from "./policy.js";
|
|
26
|
+
|
|
27
|
+
/** The address of the listener of the proxy. */
|
|
28
|
+
export const PROXY_HOST = "127.0.0.1";
|
|
29
|
+
|
|
30
|
+
/** The largest number of refusals that `PolicyProxy.refusals` keeps. `onRefusal` gets each refusal. */
|
|
31
|
+
export const MAX_PROXY_REFUSALS = 1000;
|
|
32
|
+
|
|
33
|
+
/** The path of the proxy in the messages of the host check. */
|
|
34
|
+
const PROXY_PATH = ["http", "proxy"];
|
|
35
|
+
|
|
36
|
+
/** One request that the proxy refused. */
|
|
37
|
+
export interface ProxyRefusal {
|
|
38
|
+
/** The method of the request: `CONNECT`, or the method of a plain request. */
|
|
39
|
+
readonly method: string;
|
|
40
|
+
/** The target of the request: `host:port` for `CONNECT`, else the URL. */
|
|
41
|
+
readonly target: string;
|
|
42
|
+
/** The reason of the refusal: the message of the host check. */
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The options of `startPolicyProxy()`. */
|
|
47
|
+
export interface PolicyProxyOptions {
|
|
48
|
+
/** The host policy of each request. The default is `DEFAULT_HOST_POLICY`: each public host, and no other host. */
|
|
49
|
+
readonly policy?: HostPolicy | undefined;
|
|
50
|
+
/** This function gets each refusal at the time of the refusal. An error of the function does not stop the proxy. */
|
|
51
|
+
readonly onRefusal?: ((refusal: ProxyRefusal) => void) | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A proxy that runs. */
|
|
55
|
+
export interface PolicyProxy {
|
|
56
|
+
/** The address of the listener: `127.0.0.1`. */
|
|
57
|
+
readonly host: string;
|
|
58
|
+
/** The port of the listener. */
|
|
59
|
+
readonly port: number;
|
|
60
|
+
/** The URL of the proxy, for example `http://127.0.0.1:41234`. A browser gets it in `--proxy-server`. */
|
|
61
|
+
readonly url: string;
|
|
62
|
+
/** The refusals until now, in their order. The list keeps the first `MAX_PROXY_REFUSALS` refusals. */
|
|
63
|
+
readonly refusals: readonly ProxyRefusal[];
|
|
64
|
+
/**
|
|
65
|
+
* The number of requests that the proxy got: each `CONNECT` request and each plain request, also a refused
|
|
66
|
+
* request and a request with a bad form. The value stays after `close()`. When a program that
|
|
67
|
+
* has the URL of the proxy loads a page, and the value is 0, the program did not use the proxy.
|
|
68
|
+
*/
|
|
69
|
+
readonly requests: number;
|
|
70
|
+
/** This function stops the listener and closes each open connection. Then the port is free. A second call does nothing. */
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The answer of the proxy to a request that does not reach its host. */
|
|
75
|
+
interface Failure {
|
|
76
|
+
readonly status: 400 | 403 | 502;
|
|
77
|
+
readonly message: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The text of a 403 answer. The refusal record has the reason, and the page does not get it. */
|
|
81
|
+
const REFUSED = "The host policy of the proxy refuses this host.";
|
|
82
|
+
|
|
83
|
+
/** The text of a 502 answer when the connection fails. */
|
|
84
|
+
const NO_CONNECTION = "The proxy cannot connect to this host.";
|
|
85
|
+
|
|
86
|
+
/** The text of a 502 answer when the response of the host has a status that the proxy cannot send on, for example 99. */
|
|
87
|
+
const BAD_RESPONSE = "The host gave a response that the proxy cannot send on.";
|
|
88
|
+
|
|
89
|
+
/** The headers of one connection (RFC 9110, section 7.6.1). The proxy does not send them on. */
|
|
90
|
+
const HOP_BY_HOP: ReadonlySet<string> = new Set([
|
|
91
|
+
"connection",
|
|
92
|
+
"keep-alive",
|
|
93
|
+
"proxy-authenticate",
|
|
94
|
+
"proxy-authorization",
|
|
95
|
+
"proxy-connection",
|
|
96
|
+
"te",
|
|
97
|
+
"trailer",
|
|
98
|
+
"transfer-encoding",
|
|
99
|
+
"upgrade",
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
/** The headers without the headers of one connection, and without each header that `connection` names. */
|
|
103
|
+
function endToEnd(headers: IncomingHttpHeaders): OutgoingHttpHeaders {
|
|
104
|
+
const named = new Set(String(headers.connection ?? "").split(",").map((token) => token.trim().toLowerCase()));
|
|
105
|
+
const out: OutgoingHttpHeaders = {};
|
|
106
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
107
|
+
if (!HOP_BY_HOP.has(name) && !named.has(name)) out[name] = value;
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The target of `CONNECT`: a host name, an IPv4 address or an IPv6 address in brackets, then a port. */
|
|
113
|
+
const AUTHORITY = /^(\[[0-9a-f:.]+\]|[^\s/?#@[\]:]+):([0-9]{1,5})$/i;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* This function gives the URL of the target of a `CONNECT` request (`host:port`), or undefined for
|
|
117
|
+
* another form. The URL parser gives the normal form of the host, for example `127.0.0.1` for
|
|
118
|
+
* `0x7f.1`. Thus the check and the connection use the same host.
|
|
119
|
+
*/
|
|
120
|
+
function connectUrl(authority: string): URL | undefined {
|
|
121
|
+
const match = AUTHORITY.exec(authority);
|
|
122
|
+
if (!match) return undefined;
|
|
123
|
+
const port = Number(match[2]);
|
|
124
|
+
if (port < 1 || port > 65_535) return undefined;
|
|
125
|
+
try {
|
|
126
|
+
return new URL(`http://${match[1]}:${port}/`);
|
|
127
|
+
} catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The URL of a plain request: an absolute `http:` URL, or undefined. */
|
|
133
|
+
function plainUrl(target: string): URL | undefined {
|
|
134
|
+
if (!/^http:\/\//i.test(target)) return undefined;
|
|
135
|
+
try {
|
|
136
|
+
return new URL(target);
|
|
137
|
+
} catch {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** This function writes a failure to the socket of a `CONNECT` request, and ends the socket. */
|
|
143
|
+
function rawAnswer(socket: Duplex, failure: Failure): void {
|
|
144
|
+
const body = `${failure.message}\n`;
|
|
145
|
+
socket.end(
|
|
146
|
+
`HTTP/1.1 ${failure.status} ${STATUS_CODES[failure.status]}\r\n` +
|
|
147
|
+
`content-type: text/plain; charset=utf-8\r\ncontent-length: ${Buffer.byteLength(body)}\r\nconnection: close\r\n\r\n${body}`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** This function writes a failure as the response of a plain request. */
|
|
152
|
+
function answer(response: ServerResponse, failure: Failure): void {
|
|
153
|
+
const body = `${failure.message}\n`;
|
|
154
|
+
// A failed writeHead keeps the status text of the host. Thus the answer gives its own status text
|
|
155
|
+
response.writeHead(failure.status, String(STATUS_CODES[failure.status]), {
|
|
156
|
+
"content-type": "text/plain; charset=utf-8",
|
|
157
|
+
"content-length": Buffer.byteLength(body),
|
|
158
|
+
connection: "close",
|
|
159
|
+
});
|
|
160
|
+
response.end(body);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* This function starts a forward proxy on `127.0.0.1`, on a free port, and gives its address. The
|
|
165
|
+
* proxy applies the host policy to each request. Give its URL to a program, for example in the
|
|
166
|
+
* flag `--proxy-server` of a browser. Call `close()` at the end.
|
|
167
|
+
*
|
|
168
|
+
* - The listener has no token. While the proxy runs, each program on this computer can send
|
|
169
|
+
* requests through it, to each host that the policy permits.
|
|
170
|
+
* - The connections to the hosts have no idle time-out. Thus keep the proxy only for one run:
|
|
171
|
+
* `close()` closes each connection.
|
|
172
|
+
*
|
|
173
|
+
* ```ts
|
|
174
|
+
* const proxy = await startPolicyProxy({ policy: createHostPolicy({ allow: ["intranet.example"] }) });
|
|
175
|
+
* try {
|
|
176
|
+
* // Start the program with proxy.url
|
|
177
|
+
* } finally {
|
|
178
|
+
* await proxy.close();
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export async function startPolicyProxy(options: PolicyProxyOptions = {}): Promise<PolicyProxy> {
|
|
183
|
+
const policy = options.policy ?? DEFAULT_HOST_POLICY;
|
|
184
|
+
const refusals: ProxyRefusal[] = [];
|
|
185
|
+
const sockets = new Set<Duplex>();
|
|
186
|
+
let requests = 0;
|
|
187
|
+
let closed = false;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* This function keeps a socket until it closes, so that `close()` can close it. No socket comes
|
|
191
|
+
* after `close()`: the server takes no connection, the check of a request stops each new
|
|
192
|
+
* connection, and the close of the client socket stops a request in progress.
|
|
193
|
+
*/
|
|
194
|
+
const track = (socket: Duplex): void => {
|
|
195
|
+
sockets.add(socket);
|
|
196
|
+
socket.once("close", () => sockets.delete(socket));
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/** This function examines the host of a request. It gives the checked target, or the failure. */
|
|
200
|
+
const examine = async (url: URL, method: string, target: string): Promise<AllowedTarget | Failure> => {
|
|
201
|
+
try {
|
|
202
|
+
return await checkHost(policy, url, PROXY_PATH, `the ${method} request`);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (!isHostNotAllowed(error)) return { status: 502, message: NO_CONNECTION };
|
|
205
|
+
// isHostNotAllowed gives true only for an InvocationError
|
|
206
|
+
const refusal: ProxyRefusal = { method, target, reason: (error as Error).message };
|
|
207
|
+
if (refusals.length < MAX_PROXY_REFUSALS) refusals.push(refusal);
|
|
208
|
+
try {
|
|
209
|
+
options.onRefusal?.(refusal);
|
|
210
|
+
} catch {
|
|
211
|
+
// An error of the callback does not stop the proxy
|
|
212
|
+
}
|
|
213
|
+
return { status: 403, message: REFUSED };
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** A `CONNECT` request: a tunnel to the checked addresses of the target. */
|
|
218
|
+
const tunnel = async (request: IncomingMessage, client: Duplex, head: Buffer): Promise<void> => {
|
|
219
|
+
requests += 1;
|
|
220
|
+
let upstream: Socket | undefined;
|
|
221
|
+
// An error of the client socket closes it. Then the tunnel closes too
|
|
222
|
+
const drop = (): void => {
|
|
223
|
+
upstream?.destroy();
|
|
224
|
+
};
|
|
225
|
+
client.on("error", drop);
|
|
226
|
+
client.once("close", drop);
|
|
227
|
+
// The server sets the URL of each request
|
|
228
|
+
const authority = String(request.url);
|
|
229
|
+
const url = connectUrl(authority);
|
|
230
|
+
if (url === undefined) {
|
|
231
|
+
rawAnswer(client, { status: 400, message: "The target of CONNECT is host:port." });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const checked = await examine(url, "CONNECT", authority);
|
|
235
|
+
if (client.destroyed || closed) {
|
|
236
|
+
client.destroy();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if ("status" in checked) {
|
|
240
|
+
rawAnswer(client, checked);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const socket = connect({ host: checked.hostname, port: checked.port, lookup: pinnedLookup(checked) });
|
|
244
|
+
upstream = socket;
|
|
245
|
+
track(socket);
|
|
246
|
+
let open = false;
|
|
247
|
+
socket.once("connect", () => {
|
|
248
|
+
open = true;
|
|
249
|
+
client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
250
|
+
if (head.length > 0) socket.write(head);
|
|
251
|
+
socket.pipe(client);
|
|
252
|
+
client.pipe(socket);
|
|
253
|
+
});
|
|
254
|
+
socket.on("error", () => {
|
|
255
|
+
if (open) client.destroy();
|
|
256
|
+
else rawAnswer(client, { status: 502, message: NO_CONNECTION });
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/** A plain request: the request goes to the checked addresses of its host, and the response comes back. */
|
|
261
|
+
const forward = async (request: IncomingMessage, response: ServerResponse): Promise<void> => {
|
|
262
|
+
requests += 1;
|
|
263
|
+
// The server sets the method and the URL of each request
|
|
264
|
+
const method = String(request.method);
|
|
265
|
+
const url = plainUrl(String(request.url));
|
|
266
|
+
if (url === undefined) {
|
|
267
|
+
request.resume();
|
|
268
|
+
answer(response, { status: 400, message: "The proxy takes CONNECT requests, and requests for an absolute http: URL." });
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const checked = await examine(url, method, url.href);
|
|
272
|
+
if (response.destroyed || closed) {
|
|
273
|
+
response.destroy();
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if ("status" in checked) {
|
|
277
|
+
request.resume();
|
|
278
|
+
answer(response, checked);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const outgoing = plainRequest({
|
|
282
|
+
host: checked.hostname,
|
|
283
|
+
port: checked.port,
|
|
284
|
+
method,
|
|
285
|
+
path: `${url.pathname}${url.search}`,
|
|
286
|
+
// A proxy sends the host of the URL, not the host header of the request (RFC 9112, section 3.2.2)
|
|
287
|
+
headers: { ...endToEnd(request.headers), host: url.host },
|
|
288
|
+
setHost: false,
|
|
289
|
+
lookup: pinnedLookup(checked),
|
|
290
|
+
// A connection of its own: a pooled socket could belong to another check
|
|
291
|
+
agent: false,
|
|
292
|
+
});
|
|
293
|
+
outgoing.on("socket", track);
|
|
294
|
+
outgoing.on("response", (upstream) => {
|
|
295
|
+
try {
|
|
296
|
+
// The client parser sets the status. writeHead refuses some of them, for example 99
|
|
297
|
+
response.writeHead(Number(upstream.statusCode), upstream.statusMessage, endToEnd(upstream.headers));
|
|
298
|
+
} catch {
|
|
299
|
+
upstream.destroy();
|
|
300
|
+
answer(response, { status: 502, message: BAD_RESPONSE });
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
// A response that stops early stops the response to the client too
|
|
304
|
+
upstream.on("error", () => response.destroy());
|
|
305
|
+
upstream.pipe(response);
|
|
306
|
+
});
|
|
307
|
+
outgoing.on("error", () => {
|
|
308
|
+
if (response.headersSent) response.destroy();
|
|
309
|
+
else answer(response, { status: 502, message: NO_CONNECTION });
|
|
310
|
+
});
|
|
311
|
+
// When the client connection closes before the end of the response, the request to the host stops.
|
|
312
|
+
// A request body that stops early closes the client connection too
|
|
313
|
+
response.once("close", () => {
|
|
314
|
+
if (!response.writableFinished) outgoing.destroy();
|
|
315
|
+
});
|
|
316
|
+
request.pipe(outgoing);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const server = createServer();
|
|
320
|
+
server.on("connection", track);
|
|
321
|
+
// The two functions do not reject. If one does, the bound destroy closes the connection with the error
|
|
322
|
+
server.on("connect", (request: IncomingMessage, client: Duplex, head: Buffer) => {
|
|
323
|
+
tunnel(request, client, head).catch(client.destroy.bind(client));
|
|
324
|
+
});
|
|
325
|
+
server.on("request", (request: IncomingMessage, response: ServerResponse) => {
|
|
326
|
+
forward(request, response).catch(response.destroy.bind(response));
|
|
327
|
+
});
|
|
328
|
+
await new Promise<void>((resolve, reject) => {
|
|
329
|
+
// reject stays the listener of "error". After the start it does nothing, and an error does not stop the process
|
|
330
|
+
server.on("error", reject);
|
|
331
|
+
server.listen(0, PROXY_HOST, resolve);
|
|
332
|
+
});
|
|
333
|
+
const { port } = server.address() as AddressInfo;
|
|
334
|
+
|
|
335
|
+
let closing: Promise<void> | undefined;
|
|
336
|
+
const close = (): Promise<void> => {
|
|
337
|
+
closing ??= new Promise<void>((resolve) => {
|
|
338
|
+
closed = true;
|
|
339
|
+
server.close(() => resolve());
|
|
340
|
+
for (const socket of sockets) socket.destroy();
|
|
341
|
+
});
|
|
342
|
+
return closing;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
host: PROXY_HOST,
|
|
347
|
+
port,
|
|
348
|
+
url: `http://${PROXY_HOST}:${port}`,
|
|
349
|
+
get refusals(): readonly ProxyRefusal[] {
|
|
350
|
+
return [...refusals];
|
|
351
|
+
},
|
|
352
|
+
get requests(): number {
|
|
353
|
+
return requests;
|
|
354
|
+
},
|
|
355
|
+
close,
|
|
356
|
+
};
|
|
357
|
+
}
|