@fuzdev/fuz_app 0.170.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.
Files changed (73) hide show
  1. package/dist/actions/CLAUDE.md +3 -3
  2. package/dist/actions/action_codegen.d.ts +5 -3
  3. package/dist/actions/action_codegen.d.ts.map +1 -1
  4. package/dist/actions/action_codegen.js +11 -27
  5. package/dist/actions/action_rpc.d.ts.map +1 -1
  6. package/dist/actions/action_rpc.js +5 -6
  7. package/dist/actions/peer_ping.d.ts.map +1 -1
  8. package/dist/actions/peer_ping.js +3 -2
  9. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  10. package/dist/actions/ws_socket_session.js +2 -1
  11. package/dist/auth/middleware.d.ts +6 -2
  12. package/dist/auth/middleware.d.ts.map +1 -1
  13. package/dist/auth/middleware.js +14 -2
  14. package/dist/auth/request_context.d.ts.map +1 -1
  15. package/dist/auth/request_context.js +5 -7
  16. package/dist/http/CLAUDE.md +5 -3
  17. package/dist/http/error_schemas.d.ts +3 -4
  18. package/dist/http/error_schemas.d.ts.map +1 -1
  19. package/dist/http/error_schemas.js +4 -5
  20. package/dist/http/host.d.ts +137 -0
  21. package/dist/http/host.d.ts.map +1 -0
  22. package/dist/http/host.js +203 -0
  23. package/dist/http/json_text.d.ts +53 -0
  24. package/dist/http/json_text.d.ts.map +1 -0
  25. package/dist/http/json_text.js +152 -0
  26. package/dist/http/origin.d.ts +9 -0
  27. package/dist/http/origin.d.ts.map +1 -1
  28. package/dist/http/origin.js +6 -2
  29. package/dist/http/origin_wildcard.d.ts +20 -5
  30. package/dist/http/origin_wildcard.d.ts.map +1 -1
  31. package/dist/http/origin_wildcard.js +22 -10
  32. package/dist/http/route_result.d.ts +2 -1
  33. package/dist/http/route_result.d.ts.map +1 -1
  34. package/dist/http/route_spec.d.ts +1 -1
  35. package/dist/http/route_spec.d.ts.map +1 -1
  36. package/dist/http/route_spec.js +10 -9
  37. package/dist/http/schema_helpers.d.ts +10 -9
  38. package/dist/http/schema_helpers.d.ts.map +1 -1
  39. package/dist/server/app_server.d.ts +10 -0
  40. package/dist/server/app_server.d.ts.map +1 -1
  41. package/dist/server/app_server.js +14 -3
  42. package/dist/testing/CLAUDE.md +6 -7
  43. package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
  44. package/dist/testing/adversarial_input_cases.js +2 -4
  45. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  46. package/dist/testing/cross_backend/identity_parity.js +7 -2
  47. package/dist/testing/cross_backend/in_process_setup.d.ts +1 -1
  48. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  49. package/dist/testing/cross_backend/in_process_setup.js +2 -1
  50. package/dist/testing/cross_backend/origin_conformance.d.ts +62 -1
  51. package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
  52. package/dist/testing/cross_backend/origin_conformance.js +19 -3
  53. package/dist/testing/cross_backend/origin_conformance.json +330 -0
  54. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -6
  55. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  56. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -15
  57. package/dist/testing/cross_backend/testing_origin_check.d.ts +16 -1
  58. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  59. package/dist/testing/cross_backend/testing_origin_check.js +12 -4
  60. package/dist/testing/cross_backend/testing_server_core.d.ts +2 -2
  61. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  62. package/dist/testing/cross_backend/testing_server_core.js +3 -3
  63. package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -1
  64. package/dist/testing/cross_backend/ws_envelope.js +8 -0
  65. package/dist/testing/rpc_envelope_cases.d.ts +7 -0
  66. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  67. package/dist/testing/rpc_envelope_cases.js +21 -0
  68. package/dist/testing/schema_generators.d.ts.map +1 -1
  69. package/dist/testing/schema_generators.js +8 -18
  70. package/dist/testing/stubs.d.ts +11 -4
  71. package/dist/testing/stubs.d.ts.map +1 -1
  72. package/dist/testing/stubs.js +10 -5
  73. package/package.json +1 -1
@@ -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"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAI9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAQpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,OAsB/C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,kBAAkB,aAAa,CAAC,MAAM,CAAC,KAAG,OAQnF,CAAC;AAKF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAChC,OAAO,aAAa,CAAC,MAAM,CAAC,EAC5B,kBAAkB,aAAa,CAAC,MAAM,CAAC,KACrC,OAKF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,GACvC,MAAM,MAAM,EACZ,qBAAqB,MAAM,EAC3B,WAAW,MAAM,KACf,MAQF,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,+CAA+C;AAC/C,eAAO,MAAM,4BAA4B,QAAO,mBAe/C,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC/B,2EAA2E;IAC3E,eAAe,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,wGAAwG;IACxG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,yFAAyF;IACzF,GAAG,CAAC,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
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * JSON text read as the Rust spine's `serde_json` reads it.
3
+ *
4
+ * `JSON.parse` accepts three things `serde_json` refuses: an escaped lone
5
+ * surrogate (`"\ud800"`, in a string or a key), a number out of `f64` range
6
+ * (`1e400`, which `JSON.parse` reads as `Infinity`), and nesting 128 deep or
7
+ * more. Accepted, they don't survive storage: a lone surrogate is written to a
8
+ * text column as U+FFFD and refused by a `jsonb` one, and `Infinity`
9
+ * serializes as `null`. `parse_json_text` refuses all three, so a request body
10
+ * or frame gets the same verdict on both spines (`invalid_json_body` for a
11
+ * REST body, `parse_error` for a JSON-RPC body or frame, `invalid_params` for
12
+ * `GET /rpc`'s `params`).
13
+ *
14
+ * The check is one linear pass over the text after `JSON.parse` accepts it
15
+ * (`is_serde_json_text`): a few milliseconds a MiB, whatever the text holds.
16
+ *
17
+ * @module
18
+ */
19
+ /** The nesting depth `serde_json` refuses: a value nested this deep or deeper fails. */
20
+ export declare const JSON_DEPTH_LIMIT = 128;
21
+ /**
22
+ * Parses JSON text as `JSON.parse` does, refusing what `serde_json` refuses:
23
+ * an escaped lone surrogate, a number out of `f64` range, and nesting
24
+ * `JSON_DEPTH_LIMIT` deep or more.
25
+ *
26
+ * @param text - the JSON text
27
+ * @returns the parsed value
28
+ * @throws SyntaxError when `JSON.parse` throws or the text has one of the three
29
+ */
30
+ export declare const parse_json_text: (text: string) => unknown;
31
+ /** A request body read as JSON by `read_json_body`: the value, or a refusal. */
32
+ export type JsonBodyResult = {
33
+ ok: true;
34
+ value: unknown;
35
+ } | {
36
+ ok: false;
37
+ };
38
+ /** The request a body is read from: Hono's `c.req`, structurally, so this module stays hono-free. */
39
+ export interface JsonBodyRequest {
40
+ raw: Request;
41
+ text: () => Promise<string>;
42
+ }
43
+ /**
44
+ * Reads a request body as JSON text through `parse_json_text`, once per
45
+ * request: the authorization phase's `acting` read and input validation share
46
+ * the one parse. Reads the body with `c.req.text()`, as `parse_json_text`
47
+ * reads the text and not a parsed value.
48
+ *
49
+ * @param req - the request, Hono's `c.req`
50
+ * @returns the parsed body, or `{ok: false}` when it isn't JSON text `parse_json_text` accepts
51
+ */
52
+ export declare const read_json_body: (req: JsonBodyRequest) => Promise<JsonBodyResult>;
53
+ //# sourceMappingURL=json_text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json_text.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/json_text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAwFpC;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,OAM9C,CAAC;AAEF,gFAAgF;AAChF,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC;AAE1E,qGAAqG;AACrG,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5B;AAID;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,eAAe,KAAG,OAAO,CAAC,cAAc,CAgB3E,CAAC"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * JSON text read as the Rust spine's `serde_json` reads it.
3
+ *
4
+ * `JSON.parse` accepts three things `serde_json` refuses: an escaped lone
5
+ * surrogate (`"\ud800"`, in a string or a key), a number out of `f64` range
6
+ * (`1e400`, which `JSON.parse` reads as `Infinity`), and nesting 128 deep or
7
+ * more. Accepted, they don't survive storage: a lone surrogate is written to a
8
+ * text column as U+FFFD and refused by a `jsonb` one, and `Infinity`
9
+ * serializes as `null`. `parse_json_text` refuses all three, so a request body
10
+ * or frame gets the same verdict on both spines (`invalid_json_body` for a
11
+ * REST body, `parse_error` for a JSON-RPC body or frame, `invalid_params` for
12
+ * `GET /rpc`'s `params`).
13
+ *
14
+ * The check is one linear pass over the text after `JSON.parse` accepts it
15
+ * (`is_serde_json_text`): a few milliseconds a MiB, whatever the text holds.
16
+ *
17
+ * @module
18
+ */
19
+ /** The nesting depth `serde_json` refuses: a value nested this deep or deeper fails. */
20
+ export const JSON_DEPTH_LIMIT = 128;
21
+ /**
22
+ * The digits a number's mantissa (or exponent, `NUMBER_EXPONENT_DIGITS_CHECKED`)
23
+ * reaches before it can be out of `f64` range: with an exponent of two digits
24
+ * at most, a mantissa needs more than 200 digits to pass `f64::MAX`. A number
25
+ * this long is read with `Number` to see.
26
+ */
27
+ const NUMBER_MANTISSA_DIGITS_CHECKED = 200;
28
+ const NUMBER_EXPONENT_DIGITS_CHECKED = 3;
29
+ const hex4 = (text, at) => parseInt(text.slice(at, at + 4), 16);
30
+ const is_high_surrogate = (u) => u >= 0xd800 && u <= 0xdbff;
31
+ const is_low_surrogate = (u) => u >= 0xdc00 && u <= 0xdfff;
32
+ /**
33
+ * Whether `text`, which `JSON.parse` accepted, holds nothing `serde_json`
34
+ * refuses — one pass over the text, so its cost is linear whatever it holds:
35
+ *
36
+ * - every `\u` escape of a surrogate is a high one followed at once by a low
37
+ * one's escape, in a string or a key
38
+ * - nesting stays under `JSON_DEPTH_LIMIT`, counted outside strings
39
+ * - a number long enough to leave `f64` range is finite as `Number` reads it
40
+ *
41
+ * The text, not the parsed value, is what is read: `JSON.parse` keeps the last
42
+ * of two duplicate keys, so a refused value under the first would never be seen,
43
+ * where `serde_json` refuses it as it reads.
44
+ */
45
+ const is_serde_json_text = (text) => {
46
+ let depth = 0;
47
+ const length = text.length;
48
+ for (let i = 0; i < length; i++) {
49
+ const c = text.charCodeAt(i);
50
+ if (c === 0x22) {
51
+ // a string: the text is valid JSON, so every escape is well formed
52
+ for (i++;; i++) {
53
+ const d = text.charCodeAt(i);
54
+ if (d === 0x22)
55
+ break;
56
+ if (d !== 0x5c)
57
+ continue;
58
+ i++;
59
+ if (text.charCodeAt(i) !== 0x75)
60
+ continue;
61
+ const unit = hex4(text, i + 1);
62
+ i += 4;
63
+ if (is_low_surrogate(unit))
64
+ return false;
65
+ if (!is_high_surrogate(unit))
66
+ continue;
67
+ if (text.charCodeAt(i + 1) !== 0x5c ||
68
+ text.charCodeAt(i + 2) !== 0x75 ||
69
+ !is_low_surrogate(hex4(text, i + 3))) {
70
+ return false;
71
+ }
72
+ i += 6;
73
+ }
74
+ }
75
+ else if (c === 0x5b || c === 0x7b) {
76
+ if (++depth >= JSON_DEPTH_LIMIT)
77
+ return false;
78
+ }
79
+ else if (c === 0x5d || c === 0x7d) {
80
+ depth--;
81
+ }
82
+ else if (c === 0x2d || (c >= 0x30 && c <= 0x39)) {
83
+ const start = i;
84
+ let mantissa_digits = 0;
85
+ let exponent_digits = 0;
86
+ let in_exponent = false;
87
+ for (; i < length; i++) {
88
+ const d = text.charCodeAt(i);
89
+ if (d >= 0x30 && d <= 0x39) {
90
+ if (in_exponent)
91
+ exponent_digits++;
92
+ else
93
+ mantissa_digits++;
94
+ }
95
+ else if (d === 0x65 || d === 0x45) {
96
+ in_exponent = true;
97
+ }
98
+ else if (d !== 0x2d && d !== 0x2b && d !== 0x2e) {
99
+ break;
100
+ }
101
+ }
102
+ if ((mantissa_digits >= NUMBER_MANTISSA_DIGITS_CHECKED ||
103
+ exponent_digits >= NUMBER_EXPONENT_DIGITS_CHECKED) &&
104
+ !Number.isFinite(Number(text.slice(start, i)))) {
105
+ return false;
106
+ }
107
+ i--;
108
+ }
109
+ }
110
+ return true;
111
+ };
112
+ /**
113
+ * Parses JSON text as `JSON.parse` does, refusing what `serde_json` refuses:
114
+ * an escaped lone surrogate, a number out of `f64` range, and nesting
115
+ * `JSON_DEPTH_LIMIT` deep or more.
116
+ *
117
+ * @param text - the JSON text
118
+ * @returns the parsed value
119
+ * @throws SyntaxError when `JSON.parse` throws or the text has one of the three
120
+ */
121
+ export const parse_json_text = (text) => {
122
+ const value = JSON.parse(text);
123
+ if (!is_serde_json_text(text)) {
124
+ throw new SyntaxError('JSON text has a value the Rust spine refuses');
125
+ }
126
+ return value;
127
+ };
128
+ const json_body_cache = new WeakMap();
129
+ /**
130
+ * Reads a request body as JSON text through `parse_json_text`, once per
131
+ * request: the authorization phase's `acting` read and input validation share
132
+ * the one parse. Reads the body with `c.req.text()`, as `parse_json_text`
133
+ * reads the text and not a parsed value.
134
+ *
135
+ * @param req - the request, Hono's `c.req`
136
+ * @returns the parsed body, or `{ok: false}` when it isn't JSON text `parse_json_text` accepts
137
+ */
138
+ export const read_json_body = (req) => {
139
+ let result = json_body_cache.get(req.raw);
140
+ if (!result) {
141
+ result = req.text().then((text) => {
142
+ try {
143
+ return { ok: true, value: parse_json_text(text) };
144
+ }
145
+ catch {
146
+ return { ok: false };
147
+ }
148
+ }, () => ({ ok: false }));
149
+ json_body_cache.set(req.raw, result);
150
+ }
151
+ return result;
152
+ };
@@ -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;IACn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
  * `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 TS spine mounts no
63
- * `Host` check and adds no note, so this is the Rust text with
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,MAAM,0BAA0B,+BAA+B,CAAC;AAEvE,8DAA8D;AAC9D,MAAM,MAAM,YAAY;AACvB,4DAA4D;AAC1D;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE;AACrB,qEAAqE;GACnE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC,uEAAuE;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