@workflow/web 4.1.32 → 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 +11 -34
- package/build/client/assets/{highlighted-body-B3W2YXNL-Bim_Vs7c.js → highlighted-body-B3W2YXNL-CK5bxjZc.js} +1 -1
- package/build/client/assets/{home-BaDfLHa9.js → home-vGjXNC_q.js} +2 -2
- package/build/client/assets/{manifest-830ddfa8.js → manifest-5d325d67.js} +1 -1
- package/build/client/assets/{mermaid-3ZIDBTTL-Q2_PQwJo.js → mermaid-3ZIDBTTL-CCVNMOf9.js} +2970 -1298
- package/build/client/assets/{root-DpF6w_fA.js → root-DjobWPwY.js} +1 -1
- package/build/client/assets/{run-detail-BP7Q8-uY.js → run-detail-nLEl00wq.js} +2 -2
- package/build/client/assets/{workflow-graph-viewer-CazJ_HP0.js → workflow-graph-viewer-CTw33ANm.js} +1 -1
- package/build/server/assets/{app-Z_Os_Okl.js → app-CYvC9qzx.js} +1 -1
- package/build/server/assets/{highlighted-body-B3W2YXNL-CbAkIAJ-.js → highlighted-body-B3W2YXNL-rgouBaKE.js} +2 -2
- package/build/server/assets/{index-DSSbZLUP.js → index-DTsZ56KK.js} +3 -3
- package/build/server/assets/{mermaid-3ZIDBTTL-DrIhQkL1.js → mermaid-3ZIDBTTL-DrSJagSv.js} +2 -2
- package/build/server/assets/{server-build-Blw7jSyo.js → server-build-Bx0fBara.js} +5130 -11808
- package/build/server/assets/{token-CYktKmaH.js → token-3JN9PPgD.js} +2 -2
- package/build/server/assets/{token-util-CqAM_3Fj.js → token-util-Dq4hPEUy.js} +2 -2
- package/build/server/index.js +1 -1
- package/host-guard.js +176 -0
- package/package.json +6 -5
- package/server.d.ts +15 -1
- package/server.js +28 -3
|
@@ -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-
|
|
6
|
-
import { a6 as requireTokenError, a5 as requireTokenUtil } from "./server-build-
|
|
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-
|
|
6
|
-
import { a5 as requireTokenUtil } from "./server-build-
|
|
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];
|
package/build/server/index.js
CHANGED
|
@@ -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-
|
|
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.
|
|
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,12 +72,12 @@
|
|
|
71
72
|
"vite": "^6",
|
|
72
73
|
"vitest": "^3",
|
|
73
74
|
"jsdom": "^26",
|
|
74
|
-
"@workflow/core": "4.8.
|
|
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.
|
|
78
|
-
"@workflow/world": "4.5.
|
|
79
|
-
"@workflow/world-vercel": "4.7.
|
|
78
|
+
"@workflow/web-shared": "4.1.34",
|
|
79
|
+
"@workflow/world": "4.5.2",
|
|
80
|
+
"@workflow/world-vercel": "4.7.9"
|
|
80
81
|
},
|
|
81
82
|
"scripts": {
|
|
82
83
|
"dev": "react-router dev",
|
package/server.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
2
|
|
|
3
|
-
export
|
|
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, () => {
|