@workflow/web 4.1.33 → 4.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,55 +11,32 @@ Observability Web UI Package bundled in the [Workflow SDK](https://useworkflow.d
11
11
 
12
12
  While this UI is bundled with the Workflow CLI, you can also self-host it.
13
13
 
14
- There are multiple approaches:
14
+ There are two approaches:
15
15
 
16
16
  1. Run `npx workflow web --noBrowser` on a server
17
- 2. Clone this repo and deploy as a normal Next.js app
18
- 3. Deploy the published `@workflow/web` package
17
+ 2. Run the published `@workflow/web` package's server directly
19
18
 
20
19
  All options require the environment to be configured with the right environment variables for the World you're using.
21
20
 
21
+ ### Allowed host names
22
+
23
+ To protect against DNS rebinding, the server rejects requests whose `Host` header is not `localhost`, a `*.localhost` name, or an IP address. If you reach the UI under a domain name (for example behind a reverse proxy), list it in `WORKFLOW_WEB_ALLOWED_HOSTS` or pass `--webAllowedHosts` to the CLI: comma-separated, `.example.com` matches the domain and its subdomains, and `*` disables the check. Cross-origin `POST` requests are rejected as well, unless their origin is one of these names.
24
+
22
25
  ### Option 1: Run with the CLI
23
26
 
24
27
  ```bash
25
- npx workflow web --noBrowser
28
+ npx workflow web --noBrowser --webAllowedHosts workflow.example.com
26
29
  ```
27
30
 
28
31
  This will start the web UI on the default port `3456`.
29
32
 
30
- ### Option 2: Clone and deploy
31
-
32
- - Build and deploy like any Next.js app.
33
- - Configure the backend via environment variables (same variables the CLI writes).
34
-
35
- ### Option 3: Deploy the published `@workflow/web` package
36
-
37
- The published `@workflow/web` package contains a prebuilt `.next` directory and `package.json`.
38
- You can install it and run `next start` from the package directory.
33
+ ### Option 2: Run the published `@workflow/web` package
39
34
 
40
- Example (Node server / container):
35
+ The published `@workflow/web` package contains a prebuilt `build/` directory and a standalone server entry point, `server.js`.
41
36
 
42
37
  ```bash
43
- mkdir workflow-observability-ui
44
- cd workflow-observability-ui
45
-
46
- npm init -y
47
- # You must provide React runtime dependencies in your host project.
48
- npm i @workflow/web react react-dom
49
-
50
- # Run Next.js from the installed package (it contains the .next output)
51
- cd node_modules/@workflow/web
52
- npx --yes next start -p "${PORT:-3456}"
53
- ```
54
-
55
- If you prefer, you can set a `start` script in your host `package.json` like:
56
-
57
- ```json
58
- {
59
- "scripts": {
60
- "start": "cd node_modules/@workflow/web && next start -p $PORT"
61
- }
62
- }
38
+ npm i @workflow/web
39
+ PORT=3456 WORKFLOW_WEB_ALLOWED_HOSTS=workflow.example.com node node_modules/@workflow/web/server.js
63
40
  ```
64
41
 
65
42
  ### Configuration (environment variables)
@@ -9457,7 +9457,7 @@ const app = express();
9457
9457
  app.all(
9458
9458
  "/{*splat}",
9459
9459
  createRequestHandler({
9460
- build: () => import("./server-build-D0sUavwG.js").then((n) => n.a7)
9460
+ build: () => import("./server-build-Bx0fBara.js").then((n) => n.a7)
9461
9461
  })
9462
9462
  );
9463
9463
  app.use(
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof globalThis.require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { a1 as R, a2 as Ks, a3 as jsxRuntimeExports, a4 as Qe } from "./server-build-D0sUavwG.js";
6
- import { r as reactExports } from "./app-DFeBwpXW.js";
5
+ import { a1 as R, a2 as Ks, a3 as jsxRuntimeExports, a4 as Qe } from "./server-build-Bx0fBara.js";
6
+ import { r as reactExports } from "./app-CYvC9qzx.js";
7
7
  import "node:stream";
8
8
  import "util";
9
9
  import "crypto";
@@ -2,9 +2,9 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof globalThis.require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { H as HookSchema } from "./server-build-D0sUavwG.js";
6
- import { B, D, a, E, b, c, d, e, L, M, f, g, P, Q, h, R, S, i, j, k, l, m, n, o, p, T, q, r, s, t, u, V, W, v, w, x, y, z, A, C, F, G, I, J, K, O, U, X, Y, Z, _, $, a0 } from "./server-build-D0sUavwG.js";
7
- import "./app-DFeBwpXW.js";
5
+ import { H as HookSchema } from "./server-build-Bx0fBara.js";
6
+ import { B, D, a, E, b, c, d, e, L, M, f, g, P, Q, h, R, S, i, j, k, l, m, n, o, p, T, q, r, s, t, u, V, W, v, w, x, y, z, A, C, F, G, I, J, K, O, U, X, Y, Z, _, $, a0 } from "./server-build-Bx0fBara.js";
7
+ import "./app-CYvC9qzx.js";
8
8
  import "stream";
9
9
  import "express";
10
10
  import "node:stream";
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof globalThis.require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { N as Nt } from "./server-build-D0sUavwG.js";
6
- import "./app-DFeBwpXW.js";
5
+ import { N as Nt } from "./server-build-Bx0fBara.js";
6
+ import "./app-CYvC9qzx.js";
7
7
  import "stream";
8
8
  import "express";
9
9
  import "node:stream";
@@ -18,7 +18,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
18
18
  if (typeof globalThis.require === "undefined") {
19
19
  globalThis.require = __wkfCreateRequire(import.meta.url);
20
20
  }
21
- import { a as requireReact, S as ServerRouter, c as createReadableStreamFromReadable, r as reactExports, g as getDefaultExportFromCjs, R as React, b as ReactExports, d as commonjsGlobal, w as withComponentProps, e as withErrorBoundaryProps, M as Meta, L as Links, f as ScrollRestoration, h as Scripts, O as Outlet, u as useNavigate, i as useSearchParams, j as Link$1, k as useRouteError, l as isRouteErrorResponse, m as useLocation, n as useParams } from "./app-DFeBwpXW.js";
21
+ import { a as requireReact, S as ServerRouter, c as createReadableStreamFromReadable, r as reactExports, g as getDefaultExportFromCjs, R as React, b as ReactExports, d as commonjsGlobal, w as withComponentProps, e as withErrorBoundaryProps, M as Meta, L as Links, f as ScrollRestoration, h as Scripts, O as Outlet, u as useNavigate, i as useSearchParams, j as Link$1, k as useRouteError, l as isRouteErrorResponse, m as useLocation, n as useParams } from "./app-CYvC9qzx.js";
22
22
  import require$$0$5, { PassThrough, Transform as Transform$1 } from "node:stream";
23
23
  import require$$0 from "util";
24
24
  import require$$1 from "crypto";
@@ -74618,7 +74618,7 @@ var tn = f("block", "before:content-[counter(line)]", "before:inline-block", "be
74618
74618
  var et = ({ className: e, language: t, style: o, isIncomplete: n, ...s2 }) => jsxRuntimeExports.jsx("div", { className: f("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2", e), "data-incomplete": n || void 0, "data-language": t, "data-streamdown": "code-block", style: { contentVisibility: "auto", containIntrinsicSize: "auto 200px", ...o }, ...s2 });
74619
74619
  var Se = reactExports.createContext({ code: "" }), de = () => reactExports.useContext(Se);
74620
74620
  var ot = ({ language: e }) => jsxRuntimeExports.jsx("div", { className: "flex h-8 items-center text-muted-foreground text-xs", "data-language": e, "data-streamdown": "code-block-header", children: jsxRuntimeExports.jsx("span", { className: "ml-1 font-mono lowercase", children: e }) });
74621
- var cn$1 = /\n+$/, dn = reactExports.lazy(() => import("./highlighted-body-B3W2YXNL-DucHV668.js").then((e) => ({ default: e.HighlightedCodeBlockBody }))), rt = ({ code: e, language: t, className: o, children: n, isIncomplete: s2 = false, ...r2 }) => {
74621
+ var cn$1 = /\n+$/, dn = reactExports.lazy(() => import("./highlighted-body-B3W2YXNL-rgouBaKE.js").then((e) => ({ default: e.HighlightedCodeBlockBody }))), rt = ({ code: e, language: t, className: o, children: n, isIncomplete: s2 = false, ...r2 }) => {
74622
74622
  let i = reactExports.useMemo(() => e.replace(cn$1, ""), [e]), c = reactExports.useMemo(() => ({ bg: "transparent", fg: "inherit", tokens: i.split(`
74623
74623
  `).map((a2) => [{ content: a2, color: "inherit", bgColor: "transparent", htmlStyle: {}, offset: 0 }]) }), [i]);
74624
74624
  return jsxRuntimeExports.jsx(Se.Provider, { value: { code: e }, children: jsxRuntimeExports.jsxs(et, { isIncomplete: s2, language: t, children: [jsxRuntimeExports.jsx(ot, { language: t }), n ? jsxRuntimeExports.jsx("div", { className: "pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end", children: jsxRuntimeExports.jsx("div", { className: "pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur", "data-streamdown": "code-block-actions", children: n }) }) : null, jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: jsxRuntimeExports.jsx(Qe, { className: o, language: t, result: c, ...r2 }), children: jsxRuntimeExports.jsx(dn, { className: o, code: i, language: t, raw: c, ...r2 }) })] }) });
@@ -74940,7 +74940,7 @@ var Dt = ({ children: e, className: t, onDownload: o, onError: n }) => {
74940
74940
  }, []), jsxRuntimeExports.jsxs("div", { className: "relative", ref: i, children: [jsxRuntimeExports.jsx("button", { className: f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", t), disabled: c, onClick: () => r2(!s2), title: "Download table", type: "button", children: e != null ? e : jsxRuntimeExports.jsx(Z, { size: 14 }) }), s2 ? jsxRuntimeExports.jsxs("div", { className: "absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg", children: [jsxRuntimeExports.jsx("button", { className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40", onClick: () => a2("csv"), title: "Download table as CSV", type: "button", children: "CSV" }), jsxRuntimeExports.jsx("button", { className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40", onClick: () => a2("markdown"), title: "Download table as Markdown", type: "button", children: "Markdown" })] }) : null] });
74941
74941
  };
74942
74942
  var Vt = ({ children: e, className: t, showControls: o, ...n }) => jsxRuntimeExports.jsxs("div", { className: "my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2", "data-streamdown": "table-wrapper", children: [o ? jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-end gap-1", children: [jsxRuntimeExports.jsx(Ht, {}), jsxRuntimeExports.jsx(Dt, {})] }) : null, jsxRuntimeExports.jsx("div", { className: "border-collapse overflow-x-auto overscroll-y-auto rounded-md border border-border bg-background", children: jsxRuntimeExports.jsx("table", { className: f("w-full divide-y divide-border", t), "data-streamdown": "table", ...n, children: e }) })] });
74943
- var Jn = reactExports.lazy(() => import("./mermaid-3ZIDBTTL-DCNPJ1qb.js").then((e) => ({ default: e.Mermaid }))), Kn = /language-([^\s]+)/;
74943
+ var Jn = reactExports.lazy(() => import("./mermaid-3ZIDBTTL-DrSJagSv.js").then((e) => ({ default: e.Mermaid }))), Kn = /language-([^\s]+)/;
74944
74944
  function ke(e, t) {
74945
74945
  if (!(e != null && e.position || t != null && t.position)) return true;
74946
74946
  if (!(e != null && e.position && (t != null && t.position))) return false;
@@ -84849,7 +84849,7 @@ createLogger("build", {
84849
84849
  debugNamespace: "workflow:build"
84850
84850
  });
84851
84851
  const MAX_QUEUE_DELIVERIES = 48;
84852
- const version$1 = "4.8.17";
84852
+ const version$1 = "4.8.18";
84853
84853
  const execFileAsync = promisify(execFile);
84854
84854
  function parsePort$1(value, radix = 10) {
84855
84855
  const port = parseInt(value, radix);
@@ -116918,7 +116918,7 @@ function createLocalWorld(args) {
116918
116918
  const basedir = mergedConfig.dataDir;
116919
116919
  const hooksDir = path$3.join(basedir, "hooks");
116920
116920
  const taggedHookFiles = await listTaggedFiles(hooksDir, tag);
116921
- const { HookSchema: HookSchema2 } = await import("./index-DOJ452m_.js");
116921
+ const { HookSchema: HookSchema2 } = await import("./index-DTsZ56KK.js");
116922
116922
  await Promise.all(taggedHookFiles.map(async (hookFile) => {
116923
116923
  const hook = await readJSON(path$3.join(hooksDir, hookFile), HookSchema2);
116924
116924
  if (hook == null ? void 0 : hook.token) {
@@ -117450,8 +117450,8 @@ function requireGetVercelOidcToken() {
117450
117450
  }
117451
117451
  try {
117452
117452
  const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
117453
- await import("./token-util-BoIjkgfM.js").then((n) => n.t),
117454
- await import("./token-v98bLjzH.js").then((n) => n.t)
117453
+ await import("./token-util-Dq4hPEUy.js").then((n) => n.t),
117454
+ await import("./token-3JN9PPgD.js").then((n) => n.t)
117455
117455
  ]);
117456
117456
  if (!token || isExpired(getTokenPayload(token), options == null ? void 0 : options.expirationBufferMs)) {
117457
117457
  await refreshToken(options);
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof globalThis.require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { g as getDefaultExportFromCjs } from "./app-DFeBwpXW.js";
6
- import { a6 as requireTokenError, a5 as requireTokenUtil } from "./server-build-D0sUavwG.js";
5
+ import { g as getDefaultExportFromCjs } from "./app-CYvC9qzx.js";
6
+ import { a6 as requireTokenError, a5 as requireTokenUtil } from "./server-build-Bx0fBara.js";
7
7
  function _mergeNamespaces(n, m) {
8
8
  for (var i = 0; i < m.length; i++) {
9
9
  const e = m[i];
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof globalThis.require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { g as getDefaultExportFromCjs } from "./app-DFeBwpXW.js";
6
- import { a5 as requireTokenUtil } from "./server-build-D0sUavwG.js";
5
+ import { g as getDefaultExportFromCjs } from "./app-CYvC9qzx.js";
6
+ import { a5 as requireTokenUtil } from "./server-build-Bx0fBara.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 globalThis.require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { o } from "./assets/app-DFeBwpXW.js";
5
+ import { o } from "./assets/app-CYvC9qzx.js";
6
6
  import "express";
7
7
  import "stream";
8
8
  export {
package/host-guard.js ADDED
@@ -0,0 +1,176 @@
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
+ if (origin) {
149
+ let originHost;
150
+ try {
151
+ originHost = new URL(origin).host;
152
+ } catch {
153
+ originHost = undefined;
154
+ }
155
+ // Same origin compares the full host (name and port), so another local
156
+ // origin on a different port is cross-origin. An origin on an explicitly
157
+ // allowed name also passes, for reverse proxies that rewrite `Host` to
158
+ // the upstream address.
159
+ const sameOrigin =
160
+ originHost !== undefined &&
161
+ originHost.toLowerCase() === host?.toLowerCase();
162
+ const allowedOrigin =
163
+ originHost !== undefined &&
164
+ (allowedHosts === true ||
165
+ matchesAllowList(parseHostHeader(originHost) ?? '', allowedHosts));
166
+ if (!sameOrigin && !allowedOrigin) {
167
+ return new Response('Forbidden: cross-origin request\n', {
168
+ status: 403,
169
+ headers: { 'content-type': 'text/plain; charset=utf-8' },
170
+ });
171
+ }
172
+ }
173
+ }
174
+
175
+ return undefined;
176
+ }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@workflow/web",
3
3
  "description": "Workflow Observability UI",
4
- "version": "4.1.33",
4
+ "version": "4.1.34",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [
8
8
  "build",
9
9
  "server.js",
10
10
  "server.d.ts",
11
+ "host-guard.js",
11
12
  "package.json"
12
13
  ],
13
14
  "exports": {
@@ -71,10 +72,10 @@
71
72
  "vite": "^6",
72
73
  "vitest": "^3",
73
74
  "jsdom": "^26",
74
- "@workflow/core": "4.8.17",
75
+ "@workflow/core": "4.8.18",
75
76
  "@workflow/errors": "4.2.2",
76
77
  "@workflow/utils": "4.1.4",
77
- "@workflow/web-shared": "4.1.33",
78
+ "@workflow/web-shared": "4.1.34",
78
79
  "@workflow/world": "4.5.2",
79
80
  "@workflow/world-vercel": "4.7.9"
80
81
  },
package/server.d.ts CHANGED
@@ -1,3 +1,17 @@
1
1
  import type { Server } from 'node:http';
2
2
 
3
- export function startServer(port?: number): Promise<Server>;
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
+
14
+ export function startServer(
15
+ port?: number,
16
+ options?: StartServerOptions
17
+ ): Promise<Server>;
package/server.js CHANGED
@@ -11,11 +11,12 @@
11
11
  import path from 'node:path';
12
12
  import { fileURLToPath, pathToFileURL } from 'node:url';
13
13
  import express from 'express';
14
+ import { checkRequest, normalizeAllowedHosts } from './host-guard.js';
14
15
 
15
16
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
17
  const buildDir = path.resolve(__dirname, 'build');
17
18
 
18
- async function createApp() {
19
+ async function createApp(allowedHosts) {
19
20
  // Import the compiled server build, which exports { app } (an Express app
20
21
  // with the React Router request handler already mounted by server/app.ts)
21
22
  const { app } = await import(
@@ -26,6 +27,20 @@ async function createApp() {
26
27
  // We create a wrapper app so static middleware runs first.
27
28
  const server = express();
28
29
 
30
+ // Reject DNS-rebound and cross-site requests before anything else runs. The
31
+ // guard reads only the method and the raw `Host`/`Origin` headers.
32
+ server.use(async (req, res, next) => {
33
+ const rejection = checkRequest(
34
+ { method: req.method, headers: { get: (name) => req.get(name) } },
35
+ allowedHosts
36
+ );
37
+ if (!rejection) return next();
38
+ res
39
+ .status(rejection.status)
40
+ .type('text/plain')
41
+ .send(await rejection.text());
42
+ });
43
+
29
44
  // Serve immutable assets with long-lived cache
30
45
  server.use(
31
46
  '/assets',
@@ -48,11 +63,21 @@ async function createApp() {
48
63
  * Start the production HTTP server.
49
64
  *
50
65
  * @param {number} [port] - Port to listen on. Defaults to PORT env or 3000.
66
+ * @param {object} [options]
67
+ * @param {string | string[] | true} [options.allowedHosts] - Host names,
68
+ * besides `localhost`, `*.localhost` and IP literals, that requests may
69
+ * address the server by: an array, or a comma-separated string in the format
70
+ * of `WORKFLOW_WEB_ALLOWED_HOSTS`, which is the default. `.example.com`
71
+ * matches the domain and its subdomains; `true` or `"*"` disables the check.
51
72
  * @returns {Promise<import("http").Server>} The HTTP server instance.
52
73
  */
53
- export async function startServer(port) {
74
+ export async function startServer(port, options = {}) {
54
75
  const resolvedPort = port ?? parseInt(process.env.PORT || '3000', 10);
55
- const app = await createApp();
76
+ const app = await createApp(
77
+ normalizeAllowedHosts(
78
+ options.allowedHosts ?? process.env.WORKFLOW_WEB_ALLOWED_HOSTS
79
+ )
80
+ );
56
81
 
57
82
  return new Promise((resolve, reject) => {
58
83
  const server = app.listen(resolvedPort, () => {