@fuzdev/fuz_app 0.171.0 → 0.172.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/dist/http/CLAUDE.md +2 -1
- package/dist/http/error_schemas.d.ts +3 -4
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +4 -5
- package/dist/http/host.d.ts +137 -0
- package/dist/http/host.d.ts.map +1 -0
- package/dist/http/host.js +203 -0
- package/dist/http/origin.d.ts +9 -0
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +6 -2
- package/dist/http/origin_wildcard.d.ts +20 -5
- package/dist/http/origin_wildcard.d.ts.map +1 -1
- package/dist/http/origin_wildcard.js +22 -10
- package/dist/server/app_server.d.ts +10 -0
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +14 -3
- package/dist/testing/CLAUDE.md +5 -6
- package/dist/testing/cross_backend/in_process_setup.d.ts +1 -1
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +2 -1
- package/dist/testing/cross_backend/origin_conformance.d.ts +62 -1
- package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_conformance.js +19 -3
- package/dist/testing/cross_backend/origin_conformance.json +330 -0
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -6
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -15
- package/dist/testing/cross_backend/testing_origin_check.d.ts +16 -1
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +12 -4
- package/dist/testing/cross_backend/testing_server_core.d.ts +2 -2
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +3 -3
- package/dist/testing/stubs.d.ts +11 -4
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +10 -5
- package/package.json +1 -1
package/dist/http/CLAUDE.md
CHANGED
|
@@ -31,6 +31,7 @@ effects, see ../../../docs/architecture.md.
|
|
|
31
31
|
- `http/client_ip.ts` — `get_client_ip(c)` — reads the resolved IP off the context (set by `proxy.ts`'s middleware). Split out of `proxy.ts` so it's hono-free: dispatch + route modules that only _read_ the IP don't pull `hono/utils/ipaddr`, keeping cross-process test surfaces free of the optional `hono` peer.
|
|
32
32
|
- `http/ip_canonical.ts` — RFC 5952 IPv6 canonicalization + IPv4-mapped collapse, `rate_limit_ip_key` (an IPv6 client's `/64`), and its own `parse_ipv4_bits` / `parse_ipv6_bits` (the grammar of Rust's `IpAddr::from_str`); `IP_LITERAL_CHARS` regex. Imports nothing — the dispatcher keys its IP limiter through it, so it must stay hono-free (`src/test/hono_free_modules.test.ts` walks every `src/lib` module's graph).
|
|
33
33
|
- `http/origin.ts` — origin allowlist: the strict pattern grammar shared with the Rust spine, typed refusals, and the Origin-only middleware.
|
|
34
|
+
- `http/host.ts` — the host gate (DNS rebinding): `is_loopback_host`, `allows_host` / `allows_request_hosts` over the origin matchers, `create_host_gate_middleware_spec` (`'*'`, 403 `forbidden_host`, on by default in `create_app_server`) and its rate-limited refusal warning (`format_host_refusal_warning`). Twin of the Rust `fuz_http::host`; verdicts pinned by the host rows of `testing/cross_backend/origin_conformance.json` (../../../docs/security.md §DNS Rebinding).
|
|
34
35
|
- `http/jsonrpc.ts` — JSON-RPC 2.0 envelope schemas (MCP superset, fuz_schema), `JsonrpcErrorCode`.
|
|
35
36
|
- `http/jsonrpc_errors.ts` — `ThrownJsonrpcError`, `jsonrpc_errors` throwers, HTTP-status mappings.
|
|
36
37
|
- `http/jsonrpc_helpers.ts` — message builders, type guards, input/result normalizers, and `classify_jsonrpc_message`, the one envelope classifier both transports run.
|
|
@@ -214,7 +215,7 @@ action-handler surfaces (REST, RPC, WS); see ../../../docs/architecture.md
|
|
|
214
215
|
|
|
215
216
|
`http/error_schemas.ts` is the **declarative** error surface:
|
|
216
217
|
|
|
217
|
-
- `ERROR_*` `snake_case` string constants (`ERROR_FORBIDDEN_HOST` / `REST_FORBIDDEN_HOST` the
|
|
218
|
+
- `ERROR_*` `snake_case` string constants (`ERROR_FORBIDDEN_HOST` / `REST_FORBIDDEN_HOST` the host gate's) — single source of truth for codes; they double as JSON-RPC `data.reason`s, so they carry no HTTP status
|
|
218
219
|
- `rest_error(status, code, fields?, headers?)` → `RestErrorDef<S, C, F>` — one code at one status; the code must be a code, `REST_ERROR_CODE_PATTERN` (`^[a-z][a-z0-9_]*$`, `is_rest_error_code`) — a throw at definition, and a literal plainly off it (prose, uppercase, a leading digit) a type error — so prose goes in `message`; its body `loose_object({error: literal(code), ...fields})` as `.schema`; `headers` derives response headers from a body (`Retry-After`). Status and code must be literals. One `REST_*` definition per code a route or middleware answers (`REST_TABLE_NOT_FOUND`, `REST_RATE_LIMIT_EXCEEDED`, …); a code with a second body shape gets a second definition (`REST_AUTHENTICATION_REQUIRED_BOOTSTRAP`, `/account/status`'s 401 with `bootstrap_available`)
|
|
219
220
|
- `to_error_schemas(defs)` — a status map from definitions: one schema at a status maps to it, more to a `union` in list order
|
|
220
221
|
- `ErrorSchemas = Record<number, AnySchema>` — a status map, what `to_error_schemas` groups definitions into: one schema at a status, or a `union` of them
|
|
@@ -76,10 +76,9 @@ export declare const ERROR_INVALID_CONTENT_LENGTH: "invalid_content_length";
|
|
|
76
76
|
/** Request origin not in allowlist. */
|
|
77
77
|
export declare const ERROR_FORBIDDEN_ORIGIN: "forbidden_origin";
|
|
78
78
|
/**
|
|
79
|
-
* The request's `Host` names a host the server doesn't answer to — the
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* one declares it.
|
|
79
|
+
* The request's `Host` names a host the server doesn't answer to — the
|
|
80
|
+
* DNS-rebinding gate (`http/host.ts`, the Rust spine's `host_gate`, its
|
|
81
|
+
* `FORBIDDEN_HOST_REASON`).
|
|
83
82
|
*/
|
|
84
83
|
export declare const ERROR_FORBIDDEN_HOST: "forbidden_host";
|
|
85
84
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAYN,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,EAAG,mBAA4B,CAAC;AAEpE,2CAA2C;AAC3C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAG,kBAA2B,CAAC;AAIlE,wCAAwC;AACxC,eAAO,MAAM,6BAA6B,EAAG,yBAAkC,CAAC;AAEhF,+CAA+C;AAC/C,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAElF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAElF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,yCAAyC;AACzC,eAAO,MAAM,yBAAyB,EAAG,qBAA8B,CAAC;AAExE,sFAAsF;AACtF,eAAO,MAAM,yBAAy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;AAErD;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACxC,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,SAAS,CAAC;IAChB,yEAAyE;IACzE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,mBAAmB,GAAI,gEAOjC,wBAAwB,KAAG,KAAK,CAAC,YAAY,CAsC/C,CAAC"}
|
|
@@ -79,10 +79,9 @@ export const ERROR_INVALID_CONTENT_LENGTH = 'invalid_content_length';
|
|
|
79
79
|
/** Request origin not in allowlist. */
|
|
80
80
|
export const ERROR_FORBIDDEN_ORIGIN = 'forbidden_origin';
|
|
81
81
|
/**
|
|
82
|
-
* The request's `Host` names a host the server doesn't answer to — the
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* one declares it.
|
|
82
|
+
* The request's `Host` names a host the server doesn't answer to — the
|
|
83
|
+
* DNS-rebinding gate (`http/host.ts`, the Rust spine's `host_gate`, its
|
|
84
|
+
* `FORBIDDEN_HOST_REASON`).
|
|
86
85
|
*/
|
|
87
86
|
export const ERROR_FORBIDDEN_HOST = 'forbidden_host';
|
|
88
87
|
/**
|
|
@@ -363,7 +362,7 @@ export const REST_TOKEN_SCOPE_REQUIRED = rest_error(403, ERROR_TOKEN_SCOPE_REQUI
|
|
|
363
362
|
});
|
|
364
363
|
// 403: the origin check, bootstrap, signup
|
|
365
364
|
export const REST_FORBIDDEN_ORIGIN = rest_error(403, ERROR_FORBIDDEN_ORIGIN);
|
|
366
|
-
// 403: the
|
|
365
|
+
// 403: the host gate
|
|
367
366
|
export const REST_FORBIDDEN_HOST = rest_error(403, ERROR_FORBIDDEN_HOST);
|
|
368
367
|
export const REST_ALREADY_BOOTSTRAPPED = rest_error(403, ERROR_ALREADY_BOOTSTRAPPED);
|
|
369
368
|
export const REST_NO_MATCHING_INVITE = rest_error(403, ERROR_NO_MATCHING_INVITE);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host verification — refusing requests addressed to a name the server
|
|
3
|
+
* doesn't answer to, which is how DNS rebinding reaches a loopback server.
|
|
4
|
+
*
|
|
5
|
+
* In a rebinding attack, a page on an attacker's domain re-resolves that
|
|
6
|
+
* domain to `127.0.0.1` and talks to the local server **same-origin**: its
|
|
7
|
+
* GETs carry no `Origin` header, so the origin allowlist (`http/origin.ts`)
|
|
8
|
+
* doesn't apply. The `Host` header gives it away — the browser sets it from
|
|
9
|
+
* the URL, so it names the attacker's domain, never `localhost`.
|
|
10
|
+
*
|
|
11
|
+
* A host is allowed when its name is loopback (`localhost`, `127.0.0.0/8`,
|
|
12
|
+
* `[::1]`), at any port — a rebinding page can't put one of those in `Host`
|
|
13
|
+
* — or when an allowed origin names it (the allowlist is where the server's
|
|
14
|
+
* UI is served from, so its hosts are the server's own names). Matching
|
|
15
|
+
* reuses the origin matchers, so `http://localhost:*` or `https://*.fuz.dev`
|
|
16
|
+
* admit the hosts they'd admit as origins.
|
|
17
|
+
*
|
|
18
|
+
* A request without a `Host` header passes: browsers always send one, so its
|
|
19
|
+
* absence means a non-browser client, which the auth stack governs. A request
|
|
20
|
+
* with more than one `Host` is refused (RFC 9112 §3.2) — the runtimes join a
|
|
21
|
+
* repeated header into one value (`a, b`), which names no host.
|
|
22
|
+
*
|
|
23
|
+
* The gate is on by default (`AppServerOptions.host_gate`). A refusal is said
|
|
24
|
+
* in the log as well as answered: the first in each
|
|
25
|
+
* `HOST_REFUSAL_WARN_INTERVAL_MS` is a warning naming the refused `Host`
|
|
26
|
+
* (quoted ASCII-only and truncated, since the client wrote it) and the env var
|
|
27
|
+
* that lists the server's names, with a count of the refusals the interval
|
|
28
|
+
* held back. The response says neither, so a client learns nothing about the
|
|
29
|
+
* allowlist.
|
|
30
|
+
*
|
|
31
|
+
* Twin of the Rust spine's `fuz_http::host`.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
36
|
+
import type { MiddlewareHandler } from 'hono';
|
|
37
|
+
import type { MiddlewareSpec } from './middleware_spec.js';
|
|
38
|
+
/** Where the host gate mounts — every path, as the Rust stack mounts it in every group. */
|
|
39
|
+
export declare const HOST_MIDDLEWARE_PATH = "*";
|
|
40
|
+
/**
|
|
41
|
+
* The shortest gap between two refusal warnings, in milliseconds; the
|
|
42
|
+
* refusals between are counted and reported with the next one.
|
|
43
|
+
*/
|
|
44
|
+
export declare const HOST_REFUSAL_WARN_INTERVAL_MS = 60000;
|
|
45
|
+
/**
|
|
46
|
+
* True when `host` (a `Host` header value, `name[:port]`) names a loopback
|
|
47
|
+
* address: `localhost`, an IPv4 address in `127.0.0.0/8`, or `[::1]`.
|
|
48
|
+
*
|
|
49
|
+
* Anything after the name but a `:` and a port (decimal digits, at most 65535)
|
|
50
|
+
* makes it not loopback: `[::1]junk`, `localhost:abc`, and `localhost: 1` are
|
|
51
|
+
* refused. Twin of the Rust `is_loopback_host`.
|
|
52
|
+
*
|
|
53
|
+
* @param host - one `Host` header value
|
|
54
|
+
* @returns whether it names a loopback address
|
|
55
|
+
*/
|
|
56
|
+
export declare const is_loopback_host: (host: string) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Check one `Host` value: loopback, or named by an allowed origin on either
|
|
59
|
+
* scheme. Twin of the Rust `AllowedOrigins::allows_host`.
|
|
60
|
+
*
|
|
61
|
+
* @param host - one `Host` header value
|
|
62
|
+
* @param allowed_patterns - the matchers `parse_allowed_origins` built
|
|
63
|
+
* @returns whether the server answers to it
|
|
64
|
+
*/
|
|
65
|
+
export declare const allows_host: (host: string, allowed_patterns: ReadonlyArray<RegExp>) => boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Host check for a request's `Host` header values — true when there are none
|
|
68
|
+
* or one that passes `allows_host`. A value that isn't visible ASCII (a tab
|
|
69
|
+
* and the space allowed, as in a header value) is refused, and so is more than
|
|
70
|
+
* one `Host` (RFC 9112 §3.2). Twin of the Rust
|
|
71
|
+
* `AllowedOrigins::allows_request_hosts`.
|
|
72
|
+
*
|
|
73
|
+
* @param hosts - the request's `Host` values, `[]` for none
|
|
74
|
+
* @param allowed_patterns - the matchers `parse_allowed_origins` built
|
|
75
|
+
* @returns whether the request passes the host gate
|
|
76
|
+
*/
|
|
77
|
+
export declare const allows_request_hosts: (hosts: ReadonlyArray<string>, allowed_patterns: ReadonlyArray<RegExp>) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The refusal warning's text. Twin of the Rust `format_host_refusal_warning`.
|
|
80
|
+
*
|
|
81
|
+
* @param host - the refused `Host` as the request carried it
|
|
82
|
+
* @param allowed_origins_var - the env var the allowlist was read from
|
|
83
|
+
* @param held_back - the refusals held back since the last warning
|
|
84
|
+
* @returns one log line
|
|
85
|
+
*/
|
|
86
|
+
export declare const format_host_refusal_warning: (host: string, allowed_origins_var: string, held_back: number) => string;
|
|
87
|
+
/**
|
|
88
|
+
* Counts refusals between warnings, so a flood of foreign `Host`s writes one
|
|
89
|
+
* line per `HOST_REFUSAL_WARN_INTERVAL_MS` and holds no per-host state.
|
|
90
|
+
*/
|
|
91
|
+
export interface HostRefusalWarnings {
|
|
92
|
+
/**
|
|
93
|
+
* Record a refusal at `now_ms`: the refusals held back since the last
|
|
94
|
+
* warning when this one is warned, `null` when it is held back itself.
|
|
95
|
+
*/
|
|
96
|
+
note: (now_ms: number) => number | null;
|
|
97
|
+
}
|
|
98
|
+
/** Create the refusal warning's rate limit. */
|
|
99
|
+
export declare const create_host_refusal_warnings: () => HostRefusalWarnings;
|
|
100
|
+
/** Options for `create_host_gate_middleware`. */
|
|
101
|
+
export interface HostGateOptions {
|
|
102
|
+
/** The matchers `parse_allowed_origins` built — the server's allowlist. */
|
|
103
|
+
allowed_origins: ReadonlyArray<RegExp>;
|
|
104
|
+
/** Where the refusal warning goes. */
|
|
105
|
+
log: Logger;
|
|
106
|
+
/** The env var the allowlist was read from, named in the warning. Defaults to `ALLOWED_ORIGINS_VAR`. */
|
|
107
|
+
allowed_origins_var?: string;
|
|
108
|
+
/** The clock the warning's rate limit reads, in milliseconds. Defaults to `Date.now`. */
|
|
109
|
+
now?: () => number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Middleware enforcing `allows_request_hosts`, refusing with `403`
|
|
113
|
+
* `{"error": "forbidden_host"}` and warning (rate-limited, module doc).
|
|
114
|
+
*
|
|
115
|
+
* @param options - the allowlist, the log, and the warning's clock
|
|
116
|
+
* @returns the Hono middleware
|
|
117
|
+
*/
|
|
118
|
+
export declare const create_host_gate_middleware: (options: HostGateOptions) => MiddlewareHandler;
|
|
119
|
+
/**
|
|
120
|
+
* The host gate's spec without its handler — what the surface and each
|
|
121
|
+
* route's error map read, so a stub surface (`create_test_app_surface_spec`)
|
|
122
|
+
* lists the same layer.
|
|
123
|
+
*/
|
|
124
|
+
export declare const host_gate_middleware_shape: {
|
|
125
|
+
readonly name: "host";
|
|
126
|
+
readonly path: "*";
|
|
127
|
+
readonly errors: readonly [import("./error_schemas.js").RestErrorDef<403, "forbidden_host", Record<never, never>>];
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* The host gate as a middleware spec on every path (`HOST_MIDDLEWARE_PATH`),
|
|
131
|
+
* declaring its `403`, so the surface and each route's error map carry it.
|
|
132
|
+
*
|
|
133
|
+
* @param options - the allowlist, the log, and the warning's clock
|
|
134
|
+
* @returns the spec
|
|
135
|
+
*/
|
|
136
|
+
export declare const create_host_gate_middleware_spec: (options: HostGateOptions) => MiddlewareSpec;
|
|
137
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/host.ts"],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AAC,EAAE,MAAM,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,eAAe,KAAG,iBAgBtE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;CAIa,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,GAAI,SAAS,eAAe,KAAG,cAG1E,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host verification — refusing requests addressed to a name the server
|
|
3
|
+
* doesn't answer to, which is how DNS rebinding reaches a loopback server.
|
|
4
|
+
*
|
|
5
|
+
* In a rebinding attack, a page on an attacker's domain re-resolves that
|
|
6
|
+
* domain to `127.0.0.1` and talks to the local server **same-origin**: its
|
|
7
|
+
* GETs carry no `Origin` header, so the origin allowlist (`http/origin.ts`)
|
|
8
|
+
* doesn't apply. The `Host` header gives it away — the browser sets it from
|
|
9
|
+
* the URL, so it names the attacker's domain, never `localhost`.
|
|
10
|
+
*
|
|
11
|
+
* A host is allowed when its name is loopback (`localhost`, `127.0.0.0/8`,
|
|
12
|
+
* `[::1]`), at any port — a rebinding page can't put one of those in `Host`
|
|
13
|
+
* — or when an allowed origin names it (the allowlist is where the server's
|
|
14
|
+
* UI is served from, so its hosts are the server's own names). Matching
|
|
15
|
+
* reuses the origin matchers, so `http://localhost:*` or `https://*.fuz.dev`
|
|
16
|
+
* admit the hosts they'd admit as origins.
|
|
17
|
+
*
|
|
18
|
+
* A request without a `Host` header passes: browsers always send one, so its
|
|
19
|
+
* absence means a non-browser client, which the auth stack governs. A request
|
|
20
|
+
* with more than one `Host` is refused (RFC 9112 §3.2) — the runtimes join a
|
|
21
|
+
* repeated header into one value (`a, b`), which names no host.
|
|
22
|
+
*
|
|
23
|
+
* The gate is on by default (`AppServerOptions.host_gate`). A refusal is said
|
|
24
|
+
* in the log as well as answered: the first in each
|
|
25
|
+
* `HOST_REFUSAL_WARN_INTERVAL_MS` is a warning naming the refused `Host`
|
|
26
|
+
* (quoted ASCII-only and truncated, since the client wrote it) and the env var
|
|
27
|
+
* that lists the server's names, with a count of the refusals the interval
|
|
28
|
+
* held back. The response says neither, so a client learns nothing about the
|
|
29
|
+
* allowlist.
|
|
30
|
+
*
|
|
31
|
+
* Twin of the Rust spine's `fuz_http::host`.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
import { ERROR_FORBIDDEN_HOST, REST_FORBIDDEN_HOST } from './error_schemas.js';
|
|
36
|
+
import { parse_ipv4_bits, parse_ipv6_bits } from './ip_canonical.js';
|
|
37
|
+
import { quote_ascii, should_allow_origin } from './origin.js';
|
|
38
|
+
import { ALLOWED_ORIGINS_VAR } from './origin_wildcard.js';
|
|
39
|
+
/** Where the host gate mounts — every path, as the Rust stack mounts it in every group. */
|
|
40
|
+
export const HOST_MIDDLEWARE_PATH = '*';
|
|
41
|
+
/**
|
|
42
|
+
* The shortest gap between two refusal warnings, in milliseconds; the
|
|
43
|
+
* refusals between are counted and reported with the next one.
|
|
44
|
+
*/
|
|
45
|
+
export const HOST_REFUSAL_WARN_INTERVAL_MS = 60_000;
|
|
46
|
+
/** The longest excerpt of a refused `Host` a warning quotes. */
|
|
47
|
+
const HOST_EXCERPT_MAX = 200;
|
|
48
|
+
/** A port: decimal digits, at most 65535. */
|
|
49
|
+
const PORT_DIGITS = /^[0-9]+$/;
|
|
50
|
+
/**
|
|
51
|
+
* True when `host` (a `Host` header value, `name[:port]`) names a loopback
|
|
52
|
+
* address: `localhost`, an IPv4 address in `127.0.0.0/8`, or `[::1]`.
|
|
53
|
+
*
|
|
54
|
+
* Anything after the name but a `:` and a port (decimal digits, at most 65535)
|
|
55
|
+
* makes it not loopback: `[::1]junk`, `localhost:abc`, and `localhost: 1` are
|
|
56
|
+
* refused. Twin of the Rust `is_loopback_host`.
|
|
57
|
+
*
|
|
58
|
+
* @param host - one `Host` header value
|
|
59
|
+
* @returns whether it names a loopback address
|
|
60
|
+
*/
|
|
61
|
+
export const is_loopback_host = (host) => {
|
|
62
|
+
let name;
|
|
63
|
+
let rest;
|
|
64
|
+
if (host.startsWith('[')) {
|
|
65
|
+
const end = host.indexOf(']');
|
|
66
|
+
if (end === -1)
|
|
67
|
+
return false;
|
|
68
|
+
name = host.slice(0, end + 1);
|
|
69
|
+
rest = host.slice(end + 1);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const colon = host.lastIndexOf(':');
|
|
73
|
+
name = colon === -1 ? host : host.slice(0, colon);
|
|
74
|
+
rest = colon === -1 ? '' : host.slice(colon);
|
|
75
|
+
}
|
|
76
|
+
if (rest !== '') {
|
|
77
|
+
const port = rest.slice(1);
|
|
78
|
+
if (!rest.startsWith(':') || !PORT_DIGITS.test(port) || Number(port) > 65535)
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (name.toLowerCase() === 'localhost')
|
|
82
|
+
return true;
|
|
83
|
+
const ip = name.startsWith('[') && name.endsWith(']') ? name.slice(1, -1) : name;
|
|
84
|
+
const v4 = parse_ipv4_bits(ip);
|
|
85
|
+
if (v4 !== null)
|
|
86
|
+
return v4 >>> 24 === 127;
|
|
87
|
+
return parse_ipv6_bits(ip) === 1n;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Check one `Host` value: loopback, or named by an allowed origin on either
|
|
91
|
+
* scheme. Twin of the Rust `AllowedOrigins::allows_host`.
|
|
92
|
+
*
|
|
93
|
+
* @param host - one `Host` header value
|
|
94
|
+
* @param allowed_patterns - the matchers `parse_allowed_origins` built
|
|
95
|
+
* @returns whether the server answers to it
|
|
96
|
+
*/
|
|
97
|
+
export const allows_host = (host, allowed_patterns) => {
|
|
98
|
+
if (is_loopback_host(host))
|
|
99
|
+
return true;
|
|
100
|
+
// a `Host` can't hold these, and they'd change how the origin parses
|
|
101
|
+
if (host === '' || /[/?#@]/.test(host))
|
|
102
|
+
return false;
|
|
103
|
+
return (should_allow_origin(`http://${host}`, allowed_patterns) ||
|
|
104
|
+
should_allow_origin(`https://${host}`, allowed_patterns));
|
|
105
|
+
};
|
|
106
|
+
/** Visible ASCII, the space, and a tab — what a header value holds. */
|
|
107
|
+
const HEADER_TEXT = /^[\t\x20-\x7e]*$/;
|
|
108
|
+
/**
|
|
109
|
+
* Host check for a request's `Host` header values — true when there are none
|
|
110
|
+
* or one that passes `allows_host`. A value that isn't visible ASCII (a tab
|
|
111
|
+
* and the space allowed, as in a header value) is refused, and so is more than
|
|
112
|
+
* one `Host` (RFC 9112 §3.2). Twin of the Rust
|
|
113
|
+
* `AllowedOrigins::allows_request_hosts`.
|
|
114
|
+
*
|
|
115
|
+
* @param hosts - the request's `Host` values, `[]` for none
|
|
116
|
+
* @param allowed_patterns - the matchers `parse_allowed_origins` built
|
|
117
|
+
* @returns whether the request passes the host gate
|
|
118
|
+
*/
|
|
119
|
+
export const allows_request_hosts = (hosts, allowed_patterns) => {
|
|
120
|
+
if (hosts.length === 0)
|
|
121
|
+
return true;
|
|
122
|
+
if (hosts.length > 1)
|
|
123
|
+
return false;
|
|
124
|
+
const host = hosts[0];
|
|
125
|
+
return HEADER_TEXT.test(host) && allows_host(host, allowed_patterns);
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* The refusal warning's text. Twin of the Rust `format_host_refusal_warning`.
|
|
129
|
+
*
|
|
130
|
+
* @param host - the refused `Host` as the request carried it
|
|
131
|
+
* @param allowed_origins_var - the env var the allowlist was read from
|
|
132
|
+
* @param held_back - the refusals held back since the last warning
|
|
133
|
+
* @returns one log line
|
|
134
|
+
*/
|
|
135
|
+
export const format_host_refusal_warning = (host, allowed_origins_var, held_back) => {
|
|
136
|
+
const excerpt = host.length > HOST_EXCERPT_MAX ? host.slice(0, HOST_EXCERPT_MAX) + '...' : host;
|
|
137
|
+
const held = held_back === 0 ? '' : ` (${held_back} more refused since the last warning)`;
|
|
138
|
+
return (`host gate refused a request for Host ${quote_ascii(excerpt)}${held}: the server answers ` +
|
|
139
|
+
`only to loopback names and the hosts ${allowed_origins_var} names. If it should answer to ` +
|
|
140
|
+
`this name, add the origin it is served from to ${allowed_origins_var}`);
|
|
141
|
+
};
|
|
142
|
+
/** Create the refusal warning's rate limit. */
|
|
143
|
+
export const create_host_refusal_warnings = () => {
|
|
144
|
+
let last_warned = null;
|
|
145
|
+
let held_back = 0;
|
|
146
|
+
return {
|
|
147
|
+
note: (now_ms) => {
|
|
148
|
+
if (last_warned === null || now_ms - last_warned >= HOST_REFUSAL_WARN_INTERVAL_MS) {
|
|
149
|
+
last_warned = now_ms;
|
|
150
|
+
const count = held_back;
|
|
151
|
+
held_back = 0;
|
|
152
|
+
return count;
|
|
153
|
+
}
|
|
154
|
+
held_back++;
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Middleware enforcing `allows_request_hosts`, refusing with `403`
|
|
161
|
+
* `{"error": "forbidden_host"}` and warning (rate-limited, module doc).
|
|
162
|
+
*
|
|
163
|
+
* @param options - the allowlist, the log, and the warning's clock
|
|
164
|
+
* @returns the Hono middleware
|
|
165
|
+
*/
|
|
166
|
+
export const create_host_gate_middleware = (options) => {
|
|
167
|
+
const { allowed_origins, log, allowed_origins_var = ALLOWED_ORIGINS_VAR } = options;
|
|
168
|
+
const now = options.now ?? Date.now;
|
|
169
|
+
const warnings = create_host_refusal_warnings();
|
|
170
|
+
return async (c, next) => {
|
|
171
|
+
const host = c.req.header('host');
|
|
172
|
+
const hosts = host === undefined ? [] : [host];
|
|
173
|
+
if (!allows_request_hosts(hosts, allowed_origins)) {
|
|
174
|
+
const held_back = warnings.note(now());
|
|
175
|
+
if (held_back !== null) {
|
|
176
|
+
log.warn(format_host_refusal_warning(host ?? '', allowed_origins_var, held_back));
|
|
177
|
+
}
|
|
178
|
+
return c.json({ error: ERROR_FORBIDDEN_HOST }, 403);
|
|
179
|
+
}
|
|
180
|
+
return next();
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* The host gate's spec without its handler — what the surface and each
|
|
185
|
+
* route's error map read, so a stub surface (`create_test_app_surface_spec`)
|
|
186
|
+
* lists the same layer.
|
|
187
|
+
*/
|
|
188
|
+
export const host_gate_middleware_shape = {
|
|
189
|
+
name: 'host',
|
|
190
|
+
path: HOST_MIDDLEWARE_PATH,
|
|
191
|
+
errors: [REST_FORBIDDEN_HOST]
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* The host gate as a middleware spec on every path (`HOST_MIDDLEWARE_PATH`),
|
|
195
|
+
* declaring its `403`, so the surface and each route's error map carry it.
|
|
196
|
+
*
|
|
197
|
+
* @param options - the allowlist, the log, and the warning's clock
|
|
198
|
+
* @returns the spec
|
|
199
|
+
*/
|
|
200
|
+
export const create_host_gate_middleware_spec = (options) => ({
|
|
201
|
+
...host_gate_middleware_shape,
|
|
202
|
+
handler: create_host_gate_middleware(options)
|
|
203
|
+
});
|
package/dist/http/origin.d.ts
CHANGED
|
@@ -72,6 +72,15 @@ export interface AllowedOriginsError {
|
|
|
72
72
|
* @returns the reason as one line
|
|
73
73
|
*/
|
|
74
74
|
export declare const format_allowed_origins_error: (error: AllowedOriginsError) => string;
|
|
75
|
+
/**
|
|
76
|
+
* `value` in double quotes, ASCII-only: `"` and `\` backslash-escaped, every
|
|
77
|
+
* other UTF-16 code unit outside `\x20-\x7e` as `\uXXXX` — for a client- or
|
|
78
|
+
* env-written value shown in a log line. Twin of the Rust `fuz_sys::text::quoted`.
|
|
79
|
+
*
|
|
80
|
+
* @param value - the text to quote
|
|
81
|
+
* @returns the quoted text
|
|
82
|
+
*/
|
|
83
|
+
export declare const quote_ascii: (value: string) => string;
|
|
75
84
|
/**
|
|
76
85
|
* Parses an allowlist value (conventionally the `FUZ_ALLOWED_ORIGINS` env var)
|
|
77
86
|
* into regex matchers for request source verification.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"origin.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/origin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,GAAI,GAAG,OAAO,KAAG,OAC8B,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,88BAiBjC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,uBAAuB,0/BAAwD,CAAC;AAC7F,MAAM,MAAM,uBAAuB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE5E,wDAAwD;AACxD,eAAO,MAAM,8BAA8B,EAAE,QAAQ,CAAC,MAAM,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAwB5F,CAAC;AAEF,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,qEAAqE;IACrE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GAAI,OAAO,mBAAmB,KAAG,MAOzE,CAAC;
|
|
1
|
+
{"version":3,"file":"origin.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/origin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,K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AC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CAAE,EAC1D;IAAE,MAAM,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAA;CAAE,CAqBtC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uFAAuF;IACvF,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACnD,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;CAC1C;AAWD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,aAAa,GAAG,SAGlE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,MAAM,EACd,kBAAkB,aAAa,CAAC,MAAM,CAAC,KACrC,OAAqF,CAAC;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,qBAAqB,GAEhC,kBAAkB,aAAa,CAAC,MAAM,CAAC,EACvC,aAAY,aAAa,CAAC,kBAAkB,CAAM,KAChD,OAaF,CAAC"}
|
package/dist/http/origin.js
CHANGED
|
@@ -110,9 +110,13 @@ export const format_allowed_origins_error = (error) => {
|
|
|
110
110
|
const NEEDS_ASCII_ESCAPE = /[^\x20-\x7e]|["\\]/g;
|
|
111
111
|
/**
|
|
112
112
|
* `value` in double quotes, ASCII-only: `"` and `\` backslash-escaped, every
|
|
113
|
-
* other UTF-16 code unit outside `\x20-\x7e` as `\uXXXX
|
|
113
|
+
* other UTF-16 code unit outside `\x20-\x7e` as `\uXXXX` — for a client- or
|
|
114
|
+
* env-written value shown in a log line. Twin of the Rust `fuz_sys::text::quoted`.
|
|
115
|
+
*
|
|
116
|
+
* @param value - the text to quote
|
|
117
|
+
* @returns the quoted text
|
|
114
118
|
*/
|
|
115
|
-
const quote_ascii = (value) => '"' +
|
|
119
|
+
export const quote_ascii = (value) => '"' +
|
|
116
120
|
value.replace(NEEDS_ASCII_ESCAPE, (c) => c === '"' || c === '\\' ? '\\' + c : '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0')) +
|
|
117
121
|
'"';
|
|
118
122
|
/** Printable ASCII without the space. */
|
|
@@ -57,16 +57,30 @@ export type OriginWildcard = {
|
|
|
57
57
|
* @returns its wildcard shape, or `null`
|
|
58
58
|
*/
|
|
59
59
|
export declare const origin_wildcard_kind: (pattern: OriginPattern) => OriginWildcard | null;
|
|
60
|
+
/**
|
|
61
|
+
* What the server adds to a wildcard entry's text. The TS spine adds no
|
|
62
|
+
* note of its own, so only the host gate shapes it — the Rust
|
|
63
|
+
* `OriginWildcardOptions` without its notes.
|
|
64
|
+
*/
|
|
65
|
+
export interface OriginWildcardOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The server mounts the `Host` check (`http/host.ts`), which the same
|
|
68
|
+
* entries widen. On by default, as the gate is.
|
|
69
|
+
*/
|
|
70
|
+
readonly host_gate: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** The host gate on, as `create_app_server` mounts it by default. */
|
|
73
|
+
export declare const ORIGIN_WILDCARD_OPTIONS_DEFAULT: OriginWildcardOptions;
|
|
60
74
|
/**
|
|
61
75
|
* What a wildcard in `pattern` admits — the text `admit_origin_wildcards`
|
|
62
|
-
* warns or refuses with; `null` for an exact entry. The
|
|
63
|
-
* `
|
|
64
|
-
* `OriginWildcardOptions::DEFAULT`.
|
|
76
|
+
* warns or refuses with; `null` for an exact entry. The Rust
|
|
77
|
+
* `origin_wildcard_warning` text word for word, with no notes.
|
|
65
78
|
*
|
|
66
79
|
* @param pattern - a parsed allowlist entry
|
|
80
|
+
* @param options - whether the server mounts the host gate
|
|
67
81
|
* @returns the text, or `null`
|
|
68
82
|
*/
|
|
69
|
-
export declare const origin_wildcard_warning: (pattern: OriginPattern) => string | null;
|
|
83
|
+
export declare const origin_wildcard_warning: (pattern: OriginPattern, options?: OriginWildcardOptions) => string | null;
|
|
70
84
|
/** One wildcard entry an allowlist holds, with what it admits. */
|
|
71
85
|
export interface OriginWildcardEntry {
|
|
72
86
|
readonly entry: string;
|
|
@@ -85,11 +99,12 @@ export interface OriginWildcardEntry {
|
|
|
85
99
|
* @param allowed - whether the operator opted in (`FUZ_ALLOW_ORIGIN_WILDCARDS=true`)
|
|
86
100
|
* @param origins_var - what the list is called in the refusal: the env var it
|
|
87
101
|
* was read from, or the option that carried it
|
|
102
|
+
* @param options - whether the server mounts the host gate, which the text names
|
|
88
103
|
* @returns the wildcard entries admitted, or the refusal — naming each
|
|
89
104
|
* unclassifiable matcher, or else each wildcard entry, what it admits, and
|
|
90
105
|
* the flag (the Rust spine's boot error, word for word)
|
|
91
106
|
*/
|
|
92
|
-
export declare const admit_origin_wildcards: (origins: ReadonlyArray<RegExp>, allowed: boolean, origins_var?: string) => Result<{
|
|
107
|
+
export declare const admit_origin_wildcards: (origins: ReadonlyArray<RegExp>, allowed: boolean, origins_var?: string, options?: OriginWildcardOptions) => Result<{
|
|
93
108
|
wildcards: Array<OriginWildcardEntry>;
|
|
94
109
|
}, {
|
|
95
110
|
message: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"origin_wildcard.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/origin_wildcard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpE,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD;;;;GAIG;AACH,eAAO,M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AAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,aAAa,KAAG,cAAc,GAAG,IAc9E,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACrC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC5B;AAED,qEAAqE;AACrE,eAAO,MAAM,+BAA+B,EAAE,qBAA2C,CAAC;AAE1F;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,GACnC,SAAS,aAAa,EACtB,UAAS,qBAAuD,KAC9D,MAAM,GAAG,IA2CX,CAAC;AAEF,kEAAkE;AAClE,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,GAClC,SAAS,aAAa,CAAC,MAAM,CAAC,EAC9B,SAAS,OAAO,EAChB,cAAa,MAA4B,EACzC,UAAS,qBAAuD,KAC9D,MAAM,CAAC;IAAE,SAAS,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAA;CAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CA8BvE,CAAC"}
|
|
@@ -50,16 +50,18 @@ export const origin_wildcard_kind = (pattern) => {
|
|
|
50
50
|
return any_port ? { kind: 'port' } : null;
|
|
51
51
|
return any_port ? { kind: 'host_and_port', host } : { kind: 'host', host };
|
|
52
52
|
};
|
|
53
|
+
/** The host gate on, as `create_app_server` mounts it by default. */
|
|
54
|
+
export const ORIGIN_WILDCARD_OPTIONS_DEFAULT = { host_gate: true };
|
|
53
55
|
/**
|
|
54
56
|
* What a wildcard in `pattern` admits — the text `admit_origin_wildcards`
|
|
55
|
-
* warns or refuses with; `null` for an exact entry. The
|
|
56
|
-
* `
|
|
57
|
-
* `OriginWildcardOptions::DEFAULT`.
|
|
57
|
+
* warns or refuses with; `null` for an exact entry. The Rust
|
|
58
|
+
* `origin_wildcard_warning` text word for word, with no notes.
|
|
58
59
|
*
|
|
59
60
|
* @param pattern - a parsed allowlist entry
|
|
61
|
+
* @param options - whether the server mounts the host gate
|
|
60
62
|
* @returns the text, or `null`
|
|
61
63
|
*/
|
|
62
|
-
export const origin_wildcard_warning = (pattern) => {
|
|
64
|
+
export const origin_wildcard_warning = (pattern, options = ORIGIN_WILDCARD_OPTIONS_DEFAULT) => {
|
|
63
65
|
const wildcard = origin_wildcard_kind(pattern);
|
|
64
66
|
if (wildcard === null)
|
|
65
67
|
return null;
|
|
@@ -87,10 +89,19 @@ export const origin_wildcard_warning = (pattern) => {
|
|
|
87
89
|
hosts = `ANY host of that shape (no label of \`${host}\` is fixed: ${every})`;
|
|
88
90
|
}
|
|
89
91
|
const ports = pattern.port === 'any' ? 'ANY port on ' : pattern.port === 'exact' ? 'that port on ' : '';
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const sentences = [
|
|
93
|
+
`${kind}: a page served from ${ports}${hosts} is an allowed origin. The server trusts ` +
|
|
94
|
+
'every such page: one that is same-site with the host you log in at carries the ' +
|
|
95
|
+
'session cookie, and with it can call the API and open the WebSocket.'
|
|
96
|
+
];
|
|
97
|
+
if (options.host_gate) {
|
|
98
|
+
sentences.push(host_wildcard === null
|
|
99
|
+
? `The \`Host\` check answers to ${host} at any port too.`
|
|
100
|
+
: 'The `Host` check answers to the same hosts, on either scheme, so a page that ' +
|
|
101
|
+
're-points a matching domain at this machine (DNS rebinding) passes it.');
|
|
102
|
+
}
|
|
103
|
+
sentences.push('Name exact origins unless every such page is trusted');
|
|
104
|
+
return sentences.join(' ');
|
|
94
105
|
};
|
|
95
106
|
/**
|
|
96
107
|
* Admit `origins`' wildcard entries when `allowed`, returning what each admits
|
|
@@ -105,11 +116,12 @@ export const origin_wildcard_warning = (pattern) => {
|
|
|
105
116
|
* @param allowed - whether the operator opted in (`FUZ_ALLOW_ORIGIN_WILDCARDS=true`)
|
|
106
117
|
* @param origins_var - what the list is called in the refusal: the env var it
|
|
107
118
|
* was read from, or the option that carried it
|
|
119
|
+
* @param options - whether the server mounts the host gate, which the text names
|
|
108
120
|
* @returns the wildcard entries admitted, or the refusal — naming each
|
|
109
121
|
* unclassifiable matcher, or else each wildcard entry, what it admits, and
|
|
110
122
|
* the flag (the Rust spine's boot error, word for word)
|
|
111
123
|
*/
|
|
112
|
-
export const admit_origin_wildcards = (origins, allowed, origins_var = ALLOWED_ORIGINS_VAR) => {
|
|
124
|
+
export const admit_origin_wildcards = (origins, allowed, origins_var = ALLOWED_ORIGINS_VAR, options = ORIGIN_WILDCARD_OPTIONS_DEFAULT) => {
|
|
113
125
|
const wildcards = [];
|
|
114
126
|
const unparsed = [];
|
|
115
127
|
for (const regexp of origins) {
|
|
@@ -118,7 +130,7 @@ export const admit_origin_wildcards = (origins, allowed, origins_var = ALLOWED_O
|
|
|
118
130
|
unparsed.push(regexp);
|
|
119
131
|
continue;
|
|
120
132
|
}
|
|
121
|
-
const warning = origin_wildcard_warning(pattern);
|
|
133
|
+
const warning = origin_wildcard_warning(pattern, options);
|
|
122
134
|
if (warning)
|
|
123
135
|
wildcards.push({ entry: pattern.entry, warning });
|
|
124
136
|
}
|
|
@@ -98,6 +98,16 @@ export interface AppServerOptions {
|
|
|
98
98
|
* on any other matcher, flag or not. Defaults to `false`.
|
|
99
99
|
*/
|
|
100
100
|
allow_origin_wildcards?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Mount the `Host` check (`http/host.ts`), the DNS-rebinding gate, on every
|
|
103
|
+
* path ahead of the origin check: a request whose `Host` is neither a
|
|
104
|
+
* loopback name nor a host `allowed_origins` names is refused `403`
|
|
105
|
+
* `forbidden_host`, and logged at `warn` (rate-limited). Defaults to `true`;
|
|
106
|
+
* `false` is for a server reached by names its allowlist doesn't hold, which
|
|
107
|
+
* then accepts the rebinding exposure. Twin of the Rust spine's
|
|
108
|
+
* `StackOptions::host_gate`.
|
|
109
|
+
*/
|
|
110
|
+
host_gate?: boolean;
|
|
101
111
|
/**
|
|
102
112
|
* Paths the origin check skips, each with its reason. The check covers
|
|
103
113
|
* every path by default (`ORIGIN_MIDDLEWARE_PATH`) — a request with no
|