@workflow/web 5.3.1 → 5.3.3

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 (43) hide show
  1. package/README.md +11 -34
  2. package/build/client/assets/app-CmaRLUwS.css +1 -0
  3. package/build/client/assets/arrow-up-right-AHTyWXU2.js +9 -0
  4. package/build/client/assets/{entry.client-DDsh88VE.js → entry.client-BqbaswKw.js} +13 -35
  5. package/build/client/assets/{highlighted-body-JLMTFACH-CWHg5f-6.js → highlighted-body-JLMTFACH-_kzpqYmW.js} +2 -2
  6. package/build/client/assets/{home-DZqYMSiD.js → home-DjUPTrY5.js} +91 -159
  7. package/build/client/assets/{index-BS6T0Zjc.js → index-BUQuaV5X.js} +108 -174
  8. package/build/client/assets/manifest-9126df65.js +1 -0
  9. package/build/client/assets/{mermaid-WFAXDIZX-BLO7Z8RE.js → mermaid-WFAXDIZX-CNo_0yWo.js} +1499 -4067
  10. package/build/client/assets/mermaid-WFAXDIZX-F88p7PFX.css +1 -0
  11. package/build/client/assets/meta-9cjJ0pVb.js +6 -0
  12. package/build/client/assets/{root-wdKzRZGT.js → root-Bh-E5He-.js} +17 -35
  13. package/build/client/assets/root-kJB77No4.css +1 -0
  14. package/build/client/assets/rpc-client-DL_nSX36.js +2481 -0
  15. package/build/client/assets/{run-detail-DyXpnv9C.js → run-detail-5dPVsaSm.js} +533 -807
  16. package/build/client/assets/run-usage-BEswHGKU.js +1252 -0
  17. package/build/client/assets/run-usage-C_wyncgV.js +33 -0
  18. package/build/client/assets/skeleton-DE14mNQw.js +76 -0
  19. package/build/client/assets/{url-state-DhOv2zv0.js → url-state-5GKQwo-f.js} +546 -857
  20. package/build/client/assets/{zstd-browser-decoder-BNeg7hxG.js → zstd-browser-decoder-CbTMLAMd.js} +2 -2
  21. package/build/server/assets/{app-CNGxG3wL.js → app-C-e60j14.js} +13627 -12777
  22. package/build/server/assets/{esm-CETb4fkq.js → esm-BzrGWk7J.js} +2 -2
  23. package/build/server/assets/{highlighted-body-JLMTFACH-Bj8JsfUl.js → highlighted-body-JLMTFACH-B7y0X_Kn.js} +1 -1
  24. package/build/server/assets/{index-DGn_6xEN.js → index-DRDsjR--.js} +398 -490
  25. package/build/server/assets/{mermaid-WFAXDIZX-C_v93dNU.js → mermaid-WFAXDIZX-MsPxEM1Y.js} +1 -1
  26. package/build/server/assets/{token-b1ZjKN2Q.js → token-CKgyaeCJ.js} +5 -5
  27. package/build/server/assets/{token-5fcfNNDG.js → token-DXh0TnqB.js} +6 -6
  28. package/build/server/assets/{token-util-BJhEZw83.js → token-util-CCc0uYVy.js} +2 -2
  29. package/build/server/assets/{token-util-spPPOelu.js → token-util-DOHYMq7D.js} +1 -1
  30. package/build/server/assets/{wrapper-Cc-ChiPM.js → wrapper-BzLz38Oh.js} +2 -2
  31. package/build/server/assets/{zstd-browser-decoder-y4X_FyMk.js → zstd-browser-decoder-BSSEC3XP.js} +1 -1
  32. package/build/server/index.js +1 -1
  33. package/handler.d.ts +9 -0
  34. package/handler.js +16 -2
  35. package/host-guard.js +179 -0
  36. package/package.json +9 -8
  37. package/server.d.ts +15 -1
  38. package/server.js +14 -1
  39. package/build/client/assets/app-BE8uqS_d.css +0 -1
  40. package/build/client/assets/arrow-up-right-CNHh1bh2.js +0 -15
  41. package/build/client/assets/manifest-f2e93220.js +0 -1
  42. package/build/client/assets/mermaid-WFAXDIZX-D8CjRQta.css +0 -1
  43. package/build/client/assets/root-BBptRWmF.css +0 -1
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { c as co } from "./app-CNGxG3wL.js";
5
+ import { c as co } from "./app-C-e60j14.js";
6
6
  import "node:stream";
7
7
  import "stream";
8
8
  import "util";
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { k as requireTokenError, i as requireTokenUtil, h as getDefaultExportFromCjs } from "./app-CNGxG3wL.js";
5
+ import { k as requireTokenError, i as requireTokenUtil, h as getDefaultExportFromCjs } from "./app-C-e60j14.js";
6
6
  function _mergeNamespaces(n, m) {
7
7
  for (var i = 0; i < m.length; i++) {
8
8
  const e = m[i];
@@ -52,8 +52,8 @@ function requireToken() {
52
52
  var import_token_error = requireTokenError();
53
53
  var import_token_util = requireTokenUtil();
54
54
  async function refreshToken(options) {
55
- let projectId = options == null ? void 0 : options.project;
56
- let teamId = options == null ? void 0 : options.team;
55
+ let projectId = options?.project;
56
+ let teamId = options?.team;
57
57
  if (!projectId && !teamId) {
58
58
  const projectInfo = (0, import_token_util.findProjectInfo)();
59
59
  projectId = projectInfo.projectId;
@@ -69,9 +69,9 @@ function requireToken() {
69
69
  );
70
70
  }
71
71
  let maybeToken = (0, import_token_util.loadToken)(projectId);
72
- if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options == null ? void 0 : options.expirationBufferMs)) {
72
+ if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options?.expirationBufferMs)) {
73
73
  const authToken = await (0, import_token_util.getVercelToken)({
74
- expirationBufferMs: options == null ? void 0 : options.expirationBufferMs
74
+ expirationBufferMs: options?.expirationBufferMs
75
75
  });
76
76
  maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
77
77
  if (!maybeToken) {
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { h as getDefaultExportFromCjs } from "./app-CNGxG3wL.js";
6
- import { a as requireDist, b as requireTokenError, r as requireTokenUtil } from "./index-DGn_6xEN.js";
5
+ import { h as getDefaultExportFromCjs } from "./app-C-e60j14.js";
6
+ import { a as requireDist, b as requireTokenError, r as requireTokenUtil } from "./index-DRDsjR--.js";
7
7
  function _mergeNamespaces(n, m) {
8
8
  for (var i = 0; i < m.length; i++) {
9
9
  const e = m[i];
@@ -54,8 +54,8 @@ function requireToken() {
54
54
  var import_token_error = requireTokenError();
55
55
  var import_token_util = requireTokenUtil();
56
56
  async function refreshToken(options) {
57
- let projectId = options == null ? void 0 : options.project;
58
- let teamId = options == null ? void 0 : options.team;
57
+ let projectId = options?.project;
58
+ let teamId = options?.team;
59
59
  if (!projectId && !teamId) {
60
60
  const projectInfo = (0, import_token_util.findProjectInfo)();
61
61
  projectId = projectInfo.projectId;
@@ -71,13 +71,13 @@ function requireToken() {
71
71
  );
72
72
  }
73
73
  let maybeToken = (0, import_token_util.loadToken)(projectId);
74
- if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options == null ? void 0 : options.expirationBufferMs)) {
74
+ if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options?.expirationBufferMs)) {
75
75
  const configDir = (0, import_cli_config.getGlobalPathConfig)();
76
76
  if ((0, import_cli_config.getLikelyEffectiveCredStorage)(configDir) === "keyring" || isDpopLoginEnabled()) {
77
77
  maybeToken = await (0, import_token_util.getVercelOidcTokenFromCli)(projectId, teamId);
78
78
  } else {
79
79
  const authToken = await (0, import_token_util.getVercelToken)({
80
- expirationBufferMs: options == null ? void 0 : options.expirationBufferMs
80
+ expirationBufferMs: options?.expirationBufferMs
81
81
  });
82
82
  maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
83
83
  }
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { h as getDefaultExportFromCjs } from "./app-CNGxG3wL.js";
6
- import { r as requireTokenUtil } from "./index-DGn_6xEN.js";
5
+ import { h as getDefaultExportFromCjs } from "./app-C-e60j14.js";
6
+ import { r as requireTokenUtil } from "./index-DRDsjR--.js";
7
7
  function _mergeNamespaces(n, m) {
8
8
  for (var i = 0; i < m.length; i++) {
9
9
  const e = m[i];
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { h as getDefaultExportFromCjs, i as requireTokenUtil } from "./app-CNGxG3wL.js";
5
+ import { h as getDefaultExportFromCjs, i as requireTokenUtil } from "./app-C-e60j14.js";
6
6
  function _mergeNamespaces(n, m) {
7
7
  for (var i = 0; i < m.length; i++) {
8
8
  const e = m[i];
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { b as WebSocket } from "./app-CNGxG3wL.js";
6
- import { p, d, s, w, e, f, g } from "./app-CNGxG3wL.js";
5
+ import { b as WebSocket } from "./app-C-e60j14.js";
6
+ import { p, d, s, w, e, f, g } from "./app-C-e60j14.js";
7
7
  import "node:stream";
8
8
  import "stream";
9
9
  import "util";
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { a as registerZstdDecoder } from "./app-CNGxG3wL.js";
5
+ import { a as registerZstdDecoder } from "./app-C-e60j14.js";
6
6
  import "node:stream";
7
7
  import "stream";
8
8
  import "util";
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { m } from "./assets/app-CNGxG3wL.js";
5
+ import { m } from "./assets/app-C-e60j14.js";
6
6
  import "node:stream";
7
7
  import "stream";
8
8
  import "util";
package/handler.d.ts CHANGED
@@ -7,6 +7,15 @@ export interface CreateWorkflowWebHandlerOptions {
7
7
  * asset URLs are reprefixed to this base. Defaults to `"/"` (root).
8
8
  */
9
9
  basename?: string;
10
+ /**
11
+ * Host names, besides `localhost`, `*.localhost` and IP addresses, that
12
+ * requests may address the dashboard by in their `Host` header. Requests
13
+ * under any other name, and cross-origin `POST`s, get a `403`. An array, or a
14
+ * comma-separated string. `.example.com` matches the domain and its
15
+ * subdomains; `true` or `"*"` disables the check. Defaults to
16
+ * `WORKFLOW_WEB_ALLOWED_HOSTS`.
17
+ */
18
+ allowedHosts?: string | string[] | true;
10
19
  }
11
20
 
12
21
  /**
package/handler.js CHANGED
@@ -19,6 +19,7 @@
19
19
  import { existsSync } from 'node:fs';
20
20
  import path from 'node:path';
21
21
  import { fileURLToPath, pathToFileURL } from 'node:url';
22
+ import { checkRequest, normalizeAllowedHosts } from './host-guard.js';
22
23
  import { recordDashboard } from './registry.js';
23
24
  import { createStaticHandler } from './static.js';
24
25
 
@@ -38,11 +39,18 @@ function normalizeBasename(basename) {
38
39
  const handlerCache = new Map();
39
40
 
40
41
  /**
41
- * @param {{ basename?: string }} [options]
42
+ * @param {{ basename?: string, allowedHosts?: string | string[] | true }} [options]
43
+ * `allowedHosts`: host names, besides `localhost`, `*.localhost` and IP
44
+ * literals, that requests may address the dashboard by (see `host-guard.js`).
45
+ * Defaults to `WORKFLOW_WEB_ALLOWED_HOSTS`; `true` or `"*"` disables the
46
+ * check.
42
47
  * @returns {Promise<(request: Request) => Promise<Response>>}
43
48
  */
44
49
  export async function createWorkflowWebHandler(options = {}) {
45
50
  const basename = normalizeBasename(options.basename ?? '/');
51
+ const allowedHosts = normalizeAllowedHosts(
52
+ options.allowedHosts ?? process.env.WORKFLOW_WEB_ALLOWED_HOSTS
53
+ );
46
54
  let promise = handlerCache.get(basename);
47
55
  if (!promise) {
48
56
  promise = buildHandler(basename).catch((err) => {
@@ -51,7 +59,13 @@ export async function createWorkflowWebHandler(options = {}) {
51
59
  });
52
60
  handlerCache.set(basename, promise);
53
61
  }
54
- return promise;
62
+ const handler = await promise;
63
+ // The host server owns the connection and usually listens on every
64
+ // interface without validating `Host` itself, so the dashboard applies the
65
+ // same guard as the standalone server. It runs before the registry records
66
+ // the request's origin, so a rejected request never advertises its host.
67
+ return async (request) =>
68
+ checkRequest(request, allowedHosts) ?? handler(request);
55
69
  }
56
70
 
57
71
  async function buildHandler(basename) {
package/host-guard.js ADDED
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Request guard for the standalone server (`server.js`) against DNS rebinding
3
+ * and cross-site writes.
4
+ *
5
+ * The UI has no authentication, so the only thing keeping a web page on an
6
+ * unrelated site from talking to it is the browser's same-origin policy. DNS
7
+ * rebinding defeats that policy: the attacker's page re-points its own host
8
+ * name at an address this server listens on, and from then on its requests are
9
+ * same-origin and their responses readable. Such a request always carries the
10
+ * attacker's host name in its `Host` header, which is what this guard rejects.
11
+ *
12
+ * Accepted `Host` values:
13
+ * - `localhost` and `*.localhost` (resolved to loopback by browsers, never by
14
+ * an attacker's DNS);
15
+ * - IP literals, which involve no DNS lookup and so cannot be rebound;
16
+ * - names listed in `allowedHosts` (exact names, or `.example.com` for a domain
17
+ * and all its subdomains), or every name when `allowedHosts` is `true`.
18
+ *
19
+ * Unsafe methods additionally require that an `Origin` header, when present,
20
+ * names the same host as `Host` or a name in `allowedHosts`, so that a
21
+ * cross-site page cannot send blind writes either.
22
+ *
23
+ * The guard does not restrict which interfaces the server listens on: a client
24
+ * that can reach the machine directly can still address it by IP. The UI has
25
+ * no authentication, so network exposure is for the operator to control.
26
+ *
27
+ * Internal: ships in the package for `server.js` but is not in the `exports`
28
+ * map.
29
+ */
30
+
31
+ import { isIP } from 'node:net';
32
+
33
+ const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
34
+
35
+ /**
36
+ * Split a `Host` header value (or URL host) into its lowercased host name,
37
+ * without port, brackets, or trailing dot. Returns undefined when malformed.
38
+ *
39
+ * @param {string | null | undefined} host
40
+ * @returns {string | undefined}
41
+ */
42
+ export function parseHostHeader(host) {
43
+ if (!host) return undefined;
44
+ const value = host.trim().toLowerCase();
45
+ let name;
46
+ if (value.startsWith('[')) {
47
+ const end = value.indexOf(']');
48
+ if (end === -1) return undefined;
49
+ const rest = value.slice(end + 1);
50
+ if (rest !== '' && !/^:\d+$/.test(rest)) return undefined;
51
+ name = value.slice(1, end);
52
+ return isIP(name) === 6 ? name : undefined;
53
+ }
54
+ const colon = value.indexOf(':');
55
+ if (colon !== -1) {
56
+ if (!/^\d+$/.test(value.slice(colon + 1))) return undefined;
57
+ name = value.slice(0, colon);
58
+ } else {
59
+ name = value;
60
+ }
61
+ if (name.endsWith('.')) name = name.slice(0, -1);
62
+ return name || undefined;
63
+ }
64
+
65
+ /**
66
+ * Parse `WORKFLOW_WEB_ALLOWED_HOSTS`-style input: a comma-separated list, or
67
+ * `true`/`*` for any host.
68
+ *
69
+ * @param {string | undefined} value
70
+ * @returns {string[] | true}
71
+ */
72
+ export function parseAllowedHosts(value) {
73
+ if (!value) return [];
74
+ const trimmed = value.trim();
75
+ if (trimmed === '*' || trimmed.toLowerCase() === 'true') return true;
76
+ return trimmed
77
+ .split(',')
78
+ .map((entry) => entry.trim().toLowerCase())
79
+ .filter(Boolean);
80
+ }
81
+
82
+ /**
83
+ * Normalize the `allowedHosts` option: an array of names, a comma-separated
84
+ * string, or `true` for any host.
85
+ *
86
+ * @param {string | string[] | true | undefined} value
87
+ * @returns {string[] | true}
88
+ */
89
+ export function normalizeAllowedHosts(value) {
90
+ if (value === true) return true;
91
+ if (Array.isArray(value)) {
92
+ if (value.includes('*')) return true;
93
+ return value.map((entry) => entry.trim().toLowerCase()).filter(Boolean);
94
+ }
95
+ return parseAllowedHosts(value);
96
+ }
97
+
98
+ /**
99
+ * @param {string | null | undefined} hostHeader
100
+ * @param {string[] | true} [allowedHosts]
101
+ * @returns {boolean}
102
+ */
103
+ export function isAllowedHost(hostHeader, allowedHosts = []) {
104
+ if (allowedHosts === true) return true;
105
+ const name = parseHostHeader(hostHeader);
106
+ if (!name) return false;
107
+ if (isIP(name)) return true;
108
+ if (name === 'localhost' || name.endsWith('.localhost')) return true;
109
+ return matchesAllowList(name, allowedHosts);
110
+ }
111
+
112
+ /**
113
+ * @param {string} name - Parsed host name.
114
+ * @param {string[]} allowedHosts
115
+ * @returns {boolean}
116
+ */
117
+ function matchesAllowList(name, allowedHosts) {
118
+ for (const entry of allowedHosts) {
119
+ if (entry.startsWith('.')) {
120
+ if (name === entry.slice(1) || name.endsWith(entry)) return true;
121
+ } else if (name === entry) {
122
+ return true;
123
+ }
124
+ }
125
+ return false;
126
+ }
127
+
128
+ /**
129
+ * Return a rejection `Response` for a request that fails the guard, or
130
+ * undefined when the request may proceed.
131
+ *
132
+ * @param {Request} request
133
+ * @param {string[] | true} [allowedHosts]
134
+ * @returns {Response | undefined}
135
+ */
136
+ export function checkRequest(request, allowedHosts = []) {
137
+ const host = request.headers.get('host');
138
+ if (!isAllowedHost(host, allowedHosts)) {
139
+ return new Response(
140
+ 'Forbidden: unrecognized Host header. To serve the workflow web UI under ' +
141
+ 'this host name, add it to WORKFLOW_WEB_ALLOWED_HOSTS.\n',
142
+ { status: 403, headers: { 'content-type': 'text/plain; charset=utf-8' } }
143
+ );
144
+ }
145
+
146
+ if (!SAFE_METHODS.has(request.method)) {
147
+ const origin = request.headers.get('origin');
148
+ // No `Origin` means a non-browser client (the CLI, curl, scripts): browsers
149
+ // always send one on cross-origin and on same-origin unsafe requests. Do
150
+ // not require it, or those clients break.
151
+ if (origin) {
152
+ let originHost;
153
+ try {
154
+ originHost = new URL(origin).host;
155
+ } catch {
156
+ originHost = undefined;
157
+ }
158
+ // Same origin compares the full host (name and port), so another local
159
+ // origin on a different port is cross-origin. An origin on an explicitly
160
+ // allowed name also passes, for reverse proxies that rewrite `Host` to
161
+ // the upstream address.
162
+ const sameOrigin =
163
+ originHost !== undefined &&
164
+ originHost.toLowerCase() === host?.toLowerCase();
165
+ const allowedOrigin =
166
+ originHost !== undefined &&
167
+ (allowedHosts === true ||
168
+ matchesAllowList(parseHostHeader(originHost) ?? '', allowedHosts));
169
+ if (!sameOrigin && !allowedOrigin) {
170
+ return new Response('Forbidden: cross-origin request\n', {
171
+ status: 403,
172
+ headers: { 'content-type': 'text/plain; charset=utf-8' },
173
+ });
174
+ }
175
+ }
176
+ }
177
+
178
+ return undefined;
179
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workflow/web",
3
3
  "description": "Workflow Observability UI",
4
- "version": "5.3.1",
4
+ "version": "5.3.3",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [
@@ -13,6 +13,7 @@
13
13
  "registry.js",
14
14
  "registry.d.ts",
15
15
  "static.js",
16
+ "host-guard.js",
16
17
  "package.json"
17
18
  ],
18
19
  "exports": {
@@ -40,7 +41,7 @@
40
41
  "directory": "packages/web"
41
42
  },
42
43
  "dependencies": {
43
- "@workflow/world-local": "5.5.1",
44
+ "@workflow/world-local": "5.6.0",
44
45
  "srvx": "^0.12.4"
45
46
  },
46
47
  "devDependencies": {
@@ -63,12 +64,12 @@
63
64
  "@types/react": "19",
64
65
  "@types/react-dom": "19",
65
66
  "@vercel/react-router": "1.3.7",
66
- "@workflow/core": "5.7.1",
67
- "@workflow/errors": "5.1.5",
67
+ "@workflow/core": "5.8.0",
68
+ "@workflow/errors": "5.2.0",
68
69
  "@workflow/utils": "5.1.1",
69
- "@workflow/web-shared": "5.3.1",
70
- "@workflow/world": "5.3.0",
71
- "@workflow/world-vercel": "5.7.1",
70
+ "@workflow/web-shared": "5.3.3",
71
+ "@workflow/world": "5.4.0",
72
+ "@workflow/world-vercel": "5.8.0",
72
73
  "@xyflow/react": "12.12.1",
73
74
  "cbor-x": "^1",
74
75
  "class-variance-authority": "0.7.1",
@@ -87,7 +88,7 @@
87
88
  "swr": "^2.5.1",
88
89
  "tailwindcss": "4",
89
90
  "typescript": "^6.0.3",
90
- "vite": "^6",
91
+ "vite": "^7.3.8",
91
92
  "vitest": "^5.1.0"
92
93
  },
93
94
  "scripts": {
package/server.d.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  import type { Server } from 'srvx';
2
2
 
3
+ export interface StartServerOptions {
4
+ /**
5
+ * Host names, besides `localhost`, `*.localhost` and IP addresses, that
6
+ * requests may address the server by in their `Host` header. An array, or a
7
+ * comma-separated string. `.example.com` matches the domain and its
8
+ * subdomains; `true` or `"*"` disables the check. Defaults to
9
+ * `WORKFLOW_WEB_ALLOWED_HOSTS`.
10
+ */
11
+ allowedHosts?: string | string[] | true;
12
+ }
13
+
3
14
  /**
4
15
  * Start the standalone observability UI server on `port` (defaults to `PORT`, then 3000),
5
16
  * and resolve once it is listening.
6
17
  */
7
- export function startServer(port?: number): Promise<Server>;
18
+ export function startServer(
19
+ port?: number,
20
+ options?: StartServerOptions
21
+ ): Promise<Server>;
package/server.js CHANGED
@@ -11,6 +11,7 @@
11
11
  import path from 'node:path';
12
12
  import { fileURLToPath, pathToFileURL } from 'node:url';
13
13
  import { serve } from 'srvx';
14
+ import { checkRequest, normalizeAllowedHosts } from './host-guard.js';
14
15
  import { createStaticHandler } from './static.js';
15
16
 
16
17
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -22,10 +23,16 @@ const serverEntry = path.join(buildDir, 'server', 'index.js');
22
23
  * Start the production HTTP server.
23
24
  *
24
25
  * @param {number} [port] - Port to listen on. Defaults to PORT env or 3000.
26
+ * @param {object} [options]
27
+ * @param {string | string[] | true} [options.allowedHosts] - Host names,
28
+ * besides `localhost`, `*.localhost` and IP literals, that requests may
29
+ * address the server by: an array, or a comma-separated string in the format
30
+ * of `WORKFLOW_WEB_ALLOWED_HOSTS`, which is the default. `.example.com`
31
+ * matches the domain and its subdomains; `true` or `"*"` disables the check.
25
32
  * @returns {Promise<import("srvx").Server>} The listening server. The
26
33
  * underlying Node `http.Server` remains reachable via `server.node.server`.
27
34
  */
28
- export async function startServer(port) {
35
+ export async function startServer(port, options = {}) {
29
36
  // Import the compiled server build, which exports `createFetchHandler` (the
30
37
  // React Router request handler, as a Web `Request` -> `Response` function).
31
38
  const { createFetchHandler } = await import(pathToFileURL(serverEntry).href);
@@ -35,10 +42,16 @@ export async function startServer(port) {
35
42
  // over a real network, where trading CPU for bytes is worth it.
36
43
  const serveStatic = createStaticHandler({ dir: clientDir });
37
44
  const ssr = createFetchHandler('/');
45
+ const allowedHosts = normalizeAllowedHosts(
46
+ options.allowedHosts ?? process.env.WORKFLOW_WEB_ALLOWED_HOSTS
47
+ );
38
48
 
39
49
  const server = serve({
40
50
  port: port ?? parseInt(process.env.PORT || '3000', 10),
41
51
  async fetch(request) {
52
+ // Reject DNS-rebound and cross-site requests before anything else runs.
53
+ const rejection = checkRequest(request, allowedHosts);
54
+ if (rejection) return rejection;
42
55
  return (await serveStatic(request)) ?? ssr(request);
43
56
  },
44
57
  // Safety net — prevents an unhandled error from taking down the server when