@teamclaws/teamclaw 2026.11.6 → 2026.11.8
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 +17 -11
- package/dist/src/config.js +3 -3
- package/dist/src/controller/http-server.js +18 -6
- package/dist/src/controller/managed-gateway-process.js +17 -1
- package/dist/src/controller/preview-proxy.js +55 -8
- package/dist/src/controller/provisioning/process-supervisor.js +11 -0
- package/dist/src/controller/route-table.js +2 -2
- package/dist/src/controller/security.js +85 -17
- package/dist/src/controller/task-assignment.js +62 -1
- package/dist/src/controller/task-routes.js +39 -2
- package/dist/src/controller/tunnel-manager.js +11 -0
- package/dist/src/controller/tunnel-routes.js +11 -0
- package/dist/src/controller/workspace-routes.js +16 -2
- package/dist/src/teamauto/github-client.js +19 -0
- package/dist/src/teamauto/repo-sync.js +96 -22
- package/dist/src/teamauto/scheduler.js +458 -36
- package/dist/src/teamauto/store.js +125 -3
- package/dist/src/types.js +5 -3
- package/dist/src/ui/app.js +2 -2
- package/dist/src/worker/worker-service.js +13 -1
- package/dist/src/workspace-browser.js +14 -0
- package/openclaw.plugin.json +5 -5
- package/package.json +4 -2
- package/src/config.ts +3 -3
- package/src/controller/http-server.ts +19 -5
- package/src/controller/managed-gateway-process.ts +17 -1
- package/src/controller/preview-proxy.ts +54 -8
- package/src/controller/provisioning/process-supervisor.ts +11 -0
- package/src/controller/route-table.ts +2 -2
- package/src/controller/security.ts +90 -17
- package/src/controller/task-assignment.ts +58 -1
- package/src/controller/task-routes.ts +39 -1
- package/src/controller/tunnel-manager.ts +12 -1
- package/src/controller/tunnel-routes.ts +11 -0
- package/src/controller/workspace-routes.ts +17 -2
- package/src/teamauto/github-client.ts +21 -1
- package/src/teamauto/repo-sync.ts +85 -21
- package/src/teamauto/scheduler.ts +434 -33
- package/src/teamauto/store.ts +133 -3
- package/src/types.ts +9 -7
- package/src/ui/app.js +2 -2
- package/src/worker/worker-service.ts +15 -1
- package/src/workspace-browser.ts +15 -0
package/README.md
CHANGED
|
@@ -15,7 +15,21 @@ It supports:
|
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
The recommended install is the official ClawHub registry (the default source for `openclaw plugins install` on OpenClaw 2026.10+ - no extra flags or source prefixes needed):
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
openclaw plugins install @teamclaws/teamclaw
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
OpenClaw walks you through the capability consent prompt; for scripts/CI, accept the declared capabilities non-interactively:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
openclaw plugins install --accept-capabilities @teamclaws/teamclaw
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> Note: the freshly published 2026.11.x builds ship compiled runtime output (`dist/index.js`). Until a pending package clears ClawHub's security scan, `latest` may still resolve to the legacy 2026.3.x artifact, which predates compiled entries - retry after the scan completes.
|
|
31
|
+
|
|
32
|
+
For a guided setup that also configures workspaces, workers, and auth, run:
|
|
19
33
|
|
|
20
34
|
```bash
|
|
21
35
|
npx -y @teamclaws/teamclaw install
|
|
@@ -52,18 +66,10 @@ npx -y @teamclaws/teamclaw install --agent-mode main
|
|
|
52
66
|
|
|
53
67
|
If you only want to install the plugin manually, use:
|
|
54
68
|
|
|
55
|
-
|
|
56
|
-
# OpenClaw 2026.10+
|
|
57
|
-
openclaw plugins install --accept-capabilities @teamclaws/teamclaw
|
|
58
|
-
|
|
59
|
-
# Legacy hosts (<2026.10)
|
|
60
|
-
openclaw plugins install --dangerously-force-unsafe-install @teamclaws/teamclaw
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
If you want to force the ClawHub package path, use:
|
|
69
|
+
Legacy hosts (<2026.10) that predate the ClawHub-by-default registry can still install from npm, forcing the legacy consent flag:
|
|
64
70
|
|
|
65
71
|
```bash
|
|
66
|
-
openclaw plugins install --
|
|
72
|
+
openclaw plugins install --dangerously-force-unsafe-install npm:@teamclaws/teamclaw
|
|
67
73
|
```
|
|
68
74
|
|
|
69
75
|
Then enable and configure TeamClaw in your `openclaw.json`.
|
package/dist/src/config.js
CHANGED
|
@@ -110,8 +110,8 @@ function buildConfigSchema() {
|
|
|
110
110
|
properties: {
|
|
111
111
|
autoPair: {
|
|
112
112
|
type: "boolean",
|
|
113
|
-
default:
|
|
114
|
-
description: "Allow zero-input pairing from LAN peers (POST /api/v1/security/pair-auto);
|
|
113
|
+
default: false,
|
|
114
|
+
description: "Allow zero-input pairing from LAN peers (POST /api/v1/security/pair-auto); off by default so every new device needs a pairing code - enable only on a trusted private network",
|
|
115
115
|
},
|
|
116
116
|
},
|
|
117
117
|
},
|
|
@@ -329,7 +329,7 @@ function buildConfigSchema() {
|
|
|
329
329
|
},
|
|
330
330
|
security: {
|
|
331
331
|
label: "Device Pairing Security",
|
|
332
|
-
help: "Controller device-pairing options; autoPair allows LAN devices to pair with zero input (POST /api/v1/security/pair-auto)
|
|
332
|
+
help: "Controller device-pairing options; autoPair (off by default) allows LAN devices to pair with zero input (POST /api/v1/security/pair-auto) - enable only on a trusted private network",
|
|
333
333
|
},
|
|
334
334
|
agentIsolationMode: {
|
|
335
335
|
label: "Agent Isolation Mode",
|
|
@@ -60,7 +60,7 @@ import { controllerRouteTable, createTunnelGateRoutes, createTunnelManagementRou
|
|
|
60
60
|
// pairing handlers (registered via route-table.ts). This file only wires
|
|
61
61
|
// them into the pipeline below - all pathname/method policy lives in
|
|
62
62
|
// security.ts.
|
|
63
|
-
import { classifySecurityPeer, corsPreflightDecision, createSecurityMiddleware, createWebSocketUpgradeGuard, isProtectionOn, } from "./security.js";
|
|
63
|
+
import { classifySecurityPeer, corsPreflightDecision, createSecurityMiddleware, createWebSocketUpgradeGuard, hasCloudflareEdgeHeaders, isProtectionOn, } from "./security.js";
|
|
64
64
|
// ===========================================================================
|
|
65
65
|
// Team profile switch dispatch-layer constants (Phase 2.1,
|
|
66
66
|
// vertical-team-profiles-design.md 2.3). The six-step switch machine itself
|
|
@@ -141,7 +141,15 @@ export function createControllerHttpServer(deps) {
|
|
|
141
141
|
// paired (protection off) this is a no-op passthrough (L0, the exact
|
|
142
142
|
// pre-issue behavior); once devices exist it enforces per-device tokens
|
|
143
143
|
// on every non-exempt /api route (exemptions and 401 shape in security.ts).
|
|
144
|
-
|
|
144
|
+
// ClawHub security review 2026.11.7 (finding 1): self-hosted tunnels serve
|
|
145
|
+
// a custom hostname, so the active tunnel mode decides whether tunnel
|
|
146
|
+
// visitors authenticate with the gate cookie (managed/quick) or a device
|
|
147
|
+
// token (self-hosted). Both gates read it through this accessor; the
|
|
148
|
+
// Cloudflare edge headers classify traffic the Host suffix cannot.
|
|
149
|
+
const tunnelMode = () => tunnelManagerSingleton?.status().mode ?? null;
|
|
150
|
+
const viaTunnelRequest = (req) => (tunnelManagerSingleton?.isTunnelRequest(typeof req.headers.host === "string" ? req.headers.host : undefined) ?? false)
|
|
151
|
+
|| hasCloudflareEdgeHeaders(req);
|
|
152
|
+
const securityGate = createSecurityMiddleware({ ...deps, tunnelMode });
|
|
145
153
|
const server = http.createServer(async (req, res) => {
|
|
146
154
|
// CORS preflight (issue #23: wildcard while protection is off - the
|
|
147
155
|
// historical bytes - and narrowed to the UI's own origin once on).
|
|
@@ -159,7 +167,7 @@ export function createControllerHttpServer(deps) {
|
|
|
159
167
|
// structure below is unchanged from the pre-PR-D if/else chain.
|
|
160
168
|
let tunnelManager = tunnelManagerSingleton;
|
|
161
169
|
if (!tunnelManager) {
|
|
162
|
-
tunnelManager = tunnelManagerSingleton = createTunnelManager({ logger, localPort: deps.config.port });
|
|
170
|
+
tunnelManager = tunnelManagerSingleton = createTunnelManager({ logger, localPort: deps.config.port, isProtectionOn: () => isProtectionOn(deps.getTeamState()) });
|
|
163
171
|
}
|
|
164
172
|
if (!tunnelRoutesSingleton) {
|
|
165
173
|
tunnelRoutesSingleton = {
|
|
@@ -170,7 +178,7 @@ export function createControllerHttpServer(deps) {
|
|
|
170
178
|
const tunnelCtx = {
|
|
171
179
|
req, res, requestUrl: url, pathname, deps, currentState: null,
|
|
172
180
|
};
|
|
173
|
-
const viaTunnel =
|
|
181
|
+
const viaTunnel = viaTunnelRequest(req);
|
|
174
182
|
// ==================== Device auth gate (issue #23) ====================
|
|
175
183
|
// Runs BEFORE the tunnel gate tables, the transition matrix and the
|
|
176
184
|
// capability gates so none of those surfaces answer - or leak response
|
|
@@ -186,7 +194,9 @@ export function createControllerHttpServer(deps) {
|
|
|
186
194
|
if (await dispatchRoutes(tunnelRoutesSingleton.gate, tunnelCtx)) {
|
|
187
195
|
return;
|
|
188
196
|
}
|
|
189
|
-
|
|
197
|
+
// Self-hosted tunnels have no gate token: their visitors were already
|
|
198
|
+
// authenticated by the device gate above (2026.11.7 finding 1).
|
|
199
|
+
if (tunnelMode() !== "self-hosted" && !tunnelManager.gateAllows(req)) {
|
|
190
200
|
res.writeHead(403, { "Content-Type": "text/html; charset=utf-8" });
|
|
191
201
|
res.end(gatePageHtml(String(req.headers.host), false));
|
|
192
202
|
return;
|
|
@@ -212,7 +222,9 @@ export function createControllerHttpServer(deps) {
|
|
|
212
222
|
verifyUpgrade: createWebSocketUpgradeGuard({
|
|
213
223
|
...deps,
|
|
214
224
|
isTunnelHost: (host) => tunnelManagerSingleton?.isTunnelRequest(host) ?? false,
|
|
225
|
+
viaTunnelRequest,
|
|
215
226
|
gateAllows: (req) => tunnelManagerSingleton?.gateAllows(req) ?? false,
|
|
227
|
+
tunnelMode,
|
|
216
228
|
}),
|
|
217
229
|
});
|
|
218
230
|
// Plugin shutdown: kill the local connector and tear down the remote
|
|
@@ -223,7 +235,7 @@ export function createControllerHttpServer(deps) {
|
|
|
223
235
|
// Boot reconciliation: reconnect a share persisted by a previous run
|
|
224
236
|
// (gateway restart or kill -9) so the tunnel id and gate token survive.
|
|
225
237
|
if (!tunnelManagerSingleton) {
|
|
226
|
-
tunnelManagerSingleton = createTunnelManager({ logger, localPort: deps.config.port });
|
|
238
|
+
tunnelManagerSingleton = createTunnelManager({ logger, localPort: deps.config.port, isProtectionOn: () => isProtectionOn(deps.getTeamState()) });
|
|
227
239
|
}
|
|
228
240
|
void tunnelManagerSingleton.recover().catch((err) => {
|
|
229
241
|
logger.warn(`TeamClaw tunnel: boot recovery failed: ${String(err)}`);
|
|
@@ -16,6 +16,18 @@ export function spawnManagedGatewayProcess(options) {
|
|
|
16
16
|
return child;
|
|
17
17
|
}
|
|
18
18
|
export function spawnManagedCommandProcess(options) {
|
|
19
|
+
// #terminal-activation guard: previewCommand is worker-influenced input
|
|
20
|
+
// (#237 W1) executed through the core sh -c wrapper. A prompt-injected
|
|
21
|
+
// `open`/osascript command hijacks LaunchServices and activates
|
|
22
|
+
// Terminal.app from the headless launchd context (reported live: default
|
|
23
|
+
// Terminal windows intermittently activating). Reject loudly - never
|
|
24
|
+
// silently - so the attempt is visible in logs.
|
|
25
|
+
const cmd = options.command.trim();
|
|
26
|
+
if (/^(open|osascript)\b/i.test(cmd) || /(^|[\s;&|])osascript\b/i.test(cmd) || /(^|\s)-a\s+Terminal\b/.test(cmd)) {
|
|
27
|
+
const reason = `blocked Terminal-activation command (preview contract violation): ${cmd.slice(0, 120)}`;
|
|
28
|
+
console.error(`[teamclaw] ${reason}`);
|
|
29
|
+
throw new Error(`[teamclaw] ${reason}`);
|
|
30
|
+
}
|
|
19
31
|
const cwd = options.cwd ?? process.cwd();
|
|
20
32
|
const child = spawn(process.execPath, buildManagedCommandWrapperArgs(options.command), {
|
|
21
33
|
...buildManagedProcessSpawnOptions({
|
|
@@ -208,9 +220,13 @@ const shutdownSignals = process.platform === "win32"
|
|
|
208
220
|
? ["SIGTERM", "SIGINT", "SIGBREAK"]
|
|
209
221
|
: ["SIGTERM", "SIGINT", "SIGHUP", "SIGQUIT"];
|
|
210
222
|
const shell = process.platform === "win32" ? "cmd.exe" : "sh";
|
|
223
|
+
// -c, NOT -lc: a LOGIN shell sources the user's profiles in a headless
|
|
224
|
+
// launchd context. Profile init scripts are interactive-session side-effect
|
|
225
|
+
// machines (open/LaunchServices hooks, TTY-needing helpers) and are the
|
|
226
|
+
// plausible amplifier behind intermittent Terminal.app activations.
|
|
211
227
|
const shellArgs = process.platform === "win32"
|
|
212
228
|
? ["/d", "/s", "/c", command]
|
|
213
|
-
: ["-
|
|
229
|
+
: ["-c", command];
|
|
214
230
|
|
|
215
231
|
let shuttingDown = false;
|
|
216
232
|
let parentMonitor = null;
|
|
@@ -9,6 +9,30 @@
|
|
|
9
9
|
import http from "node:http";
|
|
10
10
|
import zlib from "node:zlib";
|
|
11
11
|
import { sendJson } from "../protocol.js";
|
|
12
|
+
/**
|
|
13
|
+
* Headers the preview proxy never forwards to the untrusted preview
|
|
14
|
+
* subprocess (ClawHub security review 2026.11.7 finding 2): every
|
|
15
|
+
* credential channel the controller itself accepts, plus routing headers
|
|
16
|
+
* the proxy re-derives below.
|
|
17
|
+
*/
|
|
18
|
+
export const STRIPPED_PREVIEW_REQUEST_HEADERS = new Set([
|
|
19
|
+
"cookie",
|
|
20
|
+
"authorization",
|
|
21
|
+
"x-teamclaw-token",
|
|
22
|
+
"host",
|
|
23
|
+
"connection",
|
|
24
|
+
"keep-alive",
|
|
25
|
+
"proxy-authorization",
|
|
26
|
+
"proxy-connection",
|
|
27
|
+
"te",
|
|
28
|
+
"trailer",
|
|
29
|
+
"transfer-encoding",
|
|
30
|
+
"upgrade",
|
|
31
|
+
"accept-encoding",
|
|
32
|
+
"x-forwarded-for",
|
|
33
|
+
"x-forwarded-host",
|
|
34
|
+
"x-forwarded-proto",
|
|
35
|
+
]);
|
|
12
36
|
/**
|
|
13
37
|
* /api/v1/previews/:id/* - proxy to the preview subprocess. `pathname` starts
|
|
14
38
|
* with "/api/v1/previews/"; `requestUrl` is the parsed request URL (query
|
|
@@ -29,20 +53,38 @@ export function handlePreviewProxyRequest(deps, req, res, requestUrl, pathname)
|
|
|
29
53
|
return;
|
|
30
54
|
}
|
|
31
55
|
const proxyPathPrefix = `/api/v1/previews/${encodeURIComponent(previewId)}`;
|
|
56
|
+
// ClawHub security review 2026.11.7 (finding 2): the preview subprocess runs
|
|
57
|
+
// UNTRUSTED project code, yet the proxy used to forward every incoming
|
|
58
|
+
// header - including the controller session cookie, Authorization bearer
|
|
59
|
+
// and X-TeamClaw-Token - so a preview page could read the owner's device
|
|
60
|
+
// credential and replay it against the controller API. Strip every
|
|
61
|
+
// credential-bearing header (and hop-by-hop / host-routing headers that
|
|
62
|
+
// the proxy re-derives) before the request leaves this process. Preview
|
|
63
|
+
// apps that need their own cookies must set them on their own origin.
|
|
64
|
+
const forwardedHeaders = {};
|
|
65
|
+
for (const [name, value] of Object.entries(req.headers)) {
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
continue;
|
|
68
|
+
if (STRIPPED_PREVIEW_REQUEST_HEADERS.has(name.toLowerCase()))
|
|
69
|
+
continue;
|
|
70
|
+
forwardedHeaders[name] = value;
|
|
71
|
+
}
|
|
72
|
+
Object.assign(forwardedHeaders, {
|
|
73
|
+
host: `127.0.0.1:${preview.targetPort}`,
|
|
74
|
+
"accept-encoding": "identity",
|
|
75
|
+
"x-forwarded-for": req.socket.remoteAddress ?? "",
|
|
76
|
+
"x-forwarded-host": req.headers.host ?? "",
|
|
77
|
+
"x-forwarded-proto": "http",
|
|
78
|
+
});
|
|
32
79
|
const proxyReq = http.request({
|
|
33
80
|
hostname: "127.0.0.1",
|
|
34
81
|
port: preview.targetPort,
|
|
35
82
|
path: subPath + (requestUrl.search || ""),
|
|
36
83
|
method: req.method,
|
|
37
|
-
headers:
|
|
38
|
-
...req.headers,
|
|
39
|
-
host: `127.0.0.1:${preview.targetPort}`,
|
|
40
|
-
"accept-encoding": "identity",
|
|
41
|
-
"x-forwarded-for": req.socket.remoteAddress ?? "",
|
|
42
|
-
"x-forwarded-host": req.headers.host ?? "",
|
|
43
|
-
"x-forwarded-proto": "http",
|
|
44
|
-
},
|
|
84
|
+
headers: forwardedHeaders,
|
|
45
85
|
}, (proxyRes) => {
|
|
86
|
+
// Same review: never let the preview plant cookies on the controller origin.
|
|
87
|
+
delete proxyRes.headers["set-cookie"];
|
|
46
88
|
const contentType = (proxyRes.headers["content-type"] ?? "").toLowerCase();
|
|
47
89
|
if (proxyRes.statusCode !== 200 && proxyRes.statusCode !== 201 && proxyRes.statusCode !== 301 && proxyRes.statusCode !== 302 && proxyRes.statusCode !== 304) {
|
|
48
90
|
res.writeHead(proxyRes.statusCode ?? 502, proxyRes.headers);
|
|
@@ -78,6 +120,11 @@ export function handlePreviewProxyRequest(deps, req, res, requestUrl, pathname)
|
|
|
78
120
|
// We've decoded and rewritten the body — remove upstream encoding headers.
|
|
79
121
|
delete resHeaders["content-encoding"];
|
|
80
122
|
delete resHeaders["transfer-encoding"];
|
|
123
|
+
// Preview HTML executes under the controller origin (the proxy path),
|
|
124
|
+
// so give it the same opaque-origin sandbox the raw workspace route
|
|
125
|
+
// uses (2026.11.6 finding 6): scripts run, but cannot read the
|
|
126
|
+
// controller session or call /api/v1/* same-origin.
|
|
127
|
+
resHeaders["content-security-policy"] = "sandbox allow-scripts allow-forms";
|
|
81
128
|
resHeaders["content-length"] = String(Buffer.byteLength(rewritten, "utf-8"));
|
|
82
129
|
res.writeHead(proxyRes.statusCode ?? 200, resHeaders);
|
|
83
130
|
res.end(rewritten);
|
|
@@ -134,6 +134,17 @@ export class ProcessProvisioner {
|
|
|
134
134
|
OPENCLAW_STATE_DIR: stateDir,
|
|
135
135
|
OPENCLAW_CONFIG_PATH: configPath,
|
|
136
136
|
OPENCLAW_SKIP_CANVAS_HOST: "1",
|
|
137
|
+
// #disk-hygiene (screenshot report 2026-11-19): worker go builds can
|
|
138
|
+
// accumulate gigabytes of go-build/go-link dirs in the HOME tmp when
|
|
139
|
+
// deployments want them on a scratch volume. Opt-in ONLY - hardcoded
|
|
140
|
+
// paths would break any deployment without that volume. When the
|
|
141
|
+
// operator sets TEAMCLAW_GOCACHE / TEAMCLAW_GOTMPDIR, they are
|
|
142
|
+
// forwarded as GOCACHE / GOTMPDIR (an externally-set GOCACHE already
|
|
143
|
+
// flows through ...process.env untouched and is never overridden);
|
|
144
|
+
// unset -> Go defaults apply exactly as before. Kept ABOVE the
|
|
145
|
+
// workspaceDir spread so the contract test's env-tail shape holds.
|
|
146
|
+
...(process.env.TEAMCLAW_GOCACHE && !process.env.GOCACHE ? { GOCACHE: process.env.TEAMCLAW_GOCACHE } : {}),
|
|
147
|
+
...(process.env.TEAMCLAW_GOTMPDIR && !process.env.GOTMPDIR ? { GOTMPDIR: process.env.TEAMCLAW_GOTMPDIR } : {}),
|
|
137
148
|
TEAMCLAW_WORKER_ID: spec.workerId,
|
|
138
149
|
TEAMCLAW_LAUNCH_TOKEN: spec.launchToken,
|
|
139
150
|
...(spec.workspaceDir ? { TEAMCLAW_WORKSPACE_DIR: spec.workspaceDir } : {}),
|
|
@@ -354,8 +354,8 @@ export const controllerRouteTable = [
|
|
|
354
354
|
// pair/start- authenticated device or loopback (mints a fresh code,
|
|
355
355
|
// invalidating the previous one)
|
|
356
356
|
// pair - one-shot 60s code exchange -> {token, deviceId}
|
|
357
|
-
// pair-auto - LAN peer + config.security.autoPair + protection on
|
|
358
|
-
// reset -
|
|
357
|
+
// pair-auto - LAN peer + config.security.autoPair (opt-in) + protection on
|
|
358
|
+
// reset - loopback only (anti-lockout hatch; controller host action)
|
|
359
359
|
// GET /security and DELETE /security/devices/:id are NOT exempt: the
|
|
360
360
|
// middleware itself guarantees the caller holds a valid device token.
|
|
361
361
|
{ method: "POST", path: "/api/v1/security/enable", handler: handleSecurityEnableRequest },
|
|
@@ -182,6 +182,39 @@ export function classifySecurityPeer(ip, viaTunnel) {
|
|
|
182
182
|
lan: !viaTunnel && isLanIp(normalized),
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* ClawHub security review 2026.11.7 (finding 1): every request that rode
|
|
187
|
+
* through the Cloudflare edge carries CF-Connecting-IP / CF-Ray (added by
|
|
188
|
+
* the edge, not by cloudflared or the client). The managed tunnel suffixes
|
|
189
|
+
* in tunnel-manager catch *.teamclaw.dev / *.trycloudflare.com by Host,
|
|
190
|
+
* but a SELF-HOSTED tunnel serves a custom hostname, so its traffic used to
|
|
191
|
+
* classify as a plain loopback peer and inherit trusted-host access even
|
|
192
|
+
* while device protection was on. Treating edge-marked requests as tunnel
|
|
193
|
+
* traffic closes that: a forged CF header only ever DOWNGRADES the caller
|
|
194
|
+
* (tunnel peers are never loopback/LAN), never grants anything.
|
|
195
|
+
*/
|
|
196
|
+
export function hasCloudflareEdgeHeaders(req) {
|
|
197
|
+
const h = req.headers;
|
|
198
|
+
return Boolean(h["cf-connecting-ip"] || h["cf-ray"] || h["cf-worker"]);
|
|
199
|
+
}
|
|
200
|
+
/** Origin policy for browser WebSocket upgrades (review 2026.11.7 finding 3). */
|
|
201
|
+
export function isAllowedWebSocketOrigin(req) {
|
|
202
|
+
const origin = req.headers.origin;
|
|
203
|
+
if (typeof origin !== "string" || !origin.trim()) {
|
|
204
|
+
return true; // non-browser clients (CLI, workers, curl) send no Origin
|
|
205
|
+
}
|
|
206
|
+
const host = typeof req.headers.host === "string" ? req.headers.host : "";
|
|
207
|
+
if (!host) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const u = new URL(origin);
|
|
212
|
+
return (u.protocol === "http:" || u.protocol === "https:") && u.host.toLowerCase() === host.toLowerCase();
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
185
218
|
// ---------------------------------------------------------------------------
|
|
186
219
|
// State helpers
|
|
187
220
|
// ---------------------------------------------------------------------------
|
|
@@ -417,7 +450,13 @@ export function createSecurityMiddleware(deps) {
|
|
|
417
450
|
// visitor can never obtain a pairing code, so protection-on would just
|
|
418
451
|
// kill the tunnel with an unanswerable 401 (user design ruling
|
|
419
452
|
// 2026-11-12). LAN peers remain the pairing boundary.
|
|
420
|
-
|
|
453
|
+
// ClawHub security review 2026.11.7 (finding 1): that exemption only
|
|
454
|
+
// holds for GATED tunnels (*.teamclaw.dev / quick tunnels whose visitors
|
|
455
|
+
// carry the gate cookie). A SELF-HOSTED tunnel has no gate token and a
|
|
456
|
+
// custom hostname, so its visitors must authenticate like any other
|
|
457
|
+
// remote peer - otherwise "protection on" protected nothing there.
|
|
458
|
+
const selfHostedTunnel = peer.viaTunnel && deps.tunnelMode?.() === "self-hosted";
|
|
459
|
+
if ((peer.loopback || peer.viaTunnel) && !selfHostedTunnel) {
|
|
421
460
|
const authAny = authenticateDeviceToken(state, extractDeviceToken(req));
|
|
422
461
|
if (authAny)
|
|
423
462
|
touchDeviceLastSeen(deps, authAny.device.id);
|
|
@@ -435,9 +474,37 @@ export function createSecurityMiddleware(deps) {
|
|
|
435
474
|
}
|
|
436
475
|
export function createWebSocketUpgradeGuard(deps) {
|
|
437
476
|
return function verifyUpgrade(req) {
|
|
438
|
-
const viaTunnel = deps.
|
|
477
|
+
const viaTunnel = deps.viaTunnelRequest
|
|
478
|
+
? deps.viaTunnelRequest(req)
|
|
479
|
+
: deps.isTunnelHost(typeof req.headers.host === "string" ? req.headers.host : undefined);
|
|
439
480
|
const peer = classifySecurityPeer(req.socket.remoteAddress, viaTunnel);
|
|
440
481
|
const state = deps.getTeamState();
|
|
482
|
+
// ClawHub security review 2026.11.7 (finding 3): browsers always send
|
|
483
|
+
// Origin on WebSocket upgrades; a cross-site page could otherwise open
|
|
484
|
+
// /ws with the victim's session cookie and read the live event stream.
|
|
485
|
+
// Only the controller's own origin (same host) may upgrade; non-browser
|
|
486
|
+
// clients without an Origin header are unaffected.
|
|
487
|
+
if (!isAllowedWebSocketOrigin(req)) {
|
|
488
|
+
deps.logger.warn(`Controller: rejected WebSocket upgrade from ${peer.ip} with cross-site Origin ${String(req.headers.origin)}`);
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
const selfHostedTunnel = peer.viaTunnel && deps.tunnelMode?.() === "self-hosted";
|
|
492
|
+
// ClawHub security review 2026.11.6 (finding 3): the tunnel gate must
|
|
493
|
+
// run BEFORE the protection-off allowance. The HTTP path enforces
|
|
494
|
+
// gateAllows for every tunnel request regardless of device protection
|
|
495
|
+
// (http-server.ts), so a protection-off controller still gates its HTTP
|
|
496
|
+
// surface - but this guard used to return true first, which left /ws as
|
|
497
|
+
// the one tunnel surface a gate-cookie-less visitor could subscribe to
|
|
498
|
+
// (task/message/clarification event stream). Same layering as HTTP now.
|
|
499
|
+
// Self-hosted tunnels (2026.11.7 finding 1) have no gate cookie: their
|
|
500
|
+
// visitors fall through to the device-token check below instead.
|
|
501
|
+
if (peer.viaTunnel && !selfHostedTunnel) {
|
|
502
|
+
if (!deps.gateAllows || !deps.gateAllows(req)) {
|
|
503
|
+
deps.logger.warn(`Controller: rejected WebSocket upgrade from ${peer.ip} (via tunnel, no gate cookie)`);
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
441
508
|
if (!isProtectionOn(state)) {
|
|
442
509
|
recordNonLanPeerSignal(deps, state, peer, "/ws");
|
|
443
510
|
return true;
|
|
@@ -450,13 +517,8 @@ export function createWebSocketUpgradeGuard(deps) {
|
|
|
450
517
|
if (peer.loopback) {
|
|
451
518
|
return true;
|
|
452
519
|
}
|
|
453
|
-
//
|
|
454
|
-
//
|
|
455
|
-
// as the HTTP gate (a device token here would be an unanswerable
|
|
456
|
-
// wall, 8b03ed6). Verify the gate cookie instead.
|
|
457
|
-
if (peer.viaTunnel && deps.gateAllows && deps.gateAllows(req)) {
|
|
458
|
-
return true;
|
|
459
|
-
}
|
|
520
|
+
// Gated-tunnel upgrades were handled above (gate cookie). Self-hosted
|
|
521
|
+
// tunnel upgrades land here and authenticate with a device token.
|
|
460
522
|
let token = extractDeviceToken(req);
|
|
461
523
|
if (!token) {
|
|
462
524
|
const url = new URL(req.url ?? "/ws", `http://${req.headers.host ?? "localhost"}`);
|
|
@@ -683,10 +745,10 @@ export async function handleSecurityPairAutoRequest(ctx) {
|
|
|
683
745
|
});
|
|
684
746
|
return;
|
|
685
747
|
}
|
|
686
|
-
if ((deps.config.security?.autoPair ??
|
|
748
|
+
if ((deps.config.security?.autoPair ?? false) !== true) {
|
|
687
749
|
sendJson(res, 403, {
|
|
688
750
|
error: "auto-pairing is disabled on this controller",
|
|
689
|
-
hint: "
|
|
751
|
+
hint: "Zero-input LAN pairing is off by default (ClawHub security review); ask for a pairing code and POST /api/v1/security/pair {\"code\",\"kind\",\"name\"}.",
|
|
690
752
|
});
|
|
691
753
|
return;
|
|
692
754
|
}
|
|
@@ -719,7 +781,7 @@ export async function handleSecurityGetRequest(ctx) {
|
|
|
719
781
|
protection: isProtectionOn(state),
|
|
720
782
|
devices: (security?.devices ?? []).map(serializeDevice),
|
|
721
783
|
...(active ? { pairingCode: { expiresAt: active.expiresAt, purpose: active.purpose } } : {}),
|
|
722
|
-
autoPair: deps.config.security?.autoPair ??
|
|
784
|
+
autoPair: deps.config.security?.autoPair ?? false,
|
|
723
785
|
});
|
|
724
786
|
}
|
|
725
787
|
// DELETE /api/v1/security/devices/:id - authenticated (middleware). Revoking
|
|
@@ -746,15 +808,21 @@ export async function handleSecurityDeviceDeleteRequest(ctx) {
|
|
|
746
808
|
deps.logger.info(`Controller: revoked device ${deviceId}${revokedSelf ? " (self-revocation; that client must re-pair)" : ""}; protection now ${protection ? "on" : "off"}`);
|
|
747
809
|
sendJson(res, 200, { ok: true, revoked: deviceId, revokedSelf, protection });
|
|
748
810
|
}
|
|
749
|
-
// POST /api/v1/security/reset -
|
|
750
|
-
//
|
|
751
|
-
//
|
|
811
|
+
// POST /api/v1/security/reset - LOOPBACK ONLY (anti-lockout hatch), plus
|
|
812
|
+
// an explicit confirm token (#255 P1-8). ClawHub security review 2026.11.6
|
|
813
|
+
// (finding 2): a paired device token used to be enough to drop protection
|
|
814
|
+
// for EVERYONE - any LAN device that self-paired via auto-pair could reset
|
|
815
|
+
// the controller to L0. Reset is now a controller-host action only; remote
|
|
816
|
+
// owners revoke devices individually or re-enable from the host.
|
|
752
817
|
export async function handleSecurityResetRequest(ctx) {
|
|
753
818
|
const { req, res, deps, peer } = ctx;
|
|
754
819
|
const state = deps.getTeamState();
|
|
755
820
|
const auth = authenticateDeviceToken(state, extractDeviceToken(req));
|
|
756
|
-
if (!
|
|
757
|
-
|
|
821
|
+
if (!(peer?.loopback ?? false)) {
|
|
822
|
+
sendJson(res, 403, {
|
|
823
|
+
error: "forbidden",
|
|
824
|
+
hint: "Security reset is a controller-host action (loopback only); remote devices cannot drop protection for everyone. Revoke devices individually or run the reset from the controller host.",
|
|
825
|
+
});
|
|
758
826
|
return;
|
|
759
827
|
}
|
|
760
828
|
const body = await parseJsonBody(req);
|
|
@@ -541,7 +541,39 @@ export async function runAutoAssignRound(deps, preferredWorkerId, attemptedPairs
|
|
|
541
541
|
// bypassing the gate). Write-phase claim failures still continue
|
|
542
542
|
// unclaimed per the original 2026-11-15 semantics.
|
|
543
543
|
deps.getTeamAutoScheduler?.()?.claimTaskAtDequeue(updatedTask).then((claim) => {
|
|
544
|
-
if (claim?.
|
|
544
|
+
if (claim?.reason === "issue closed") {
|
|
545
|
+
// #5818: the claim check VERDICTED against the task - the issue was
|
|
546
|
+
// closed between enqueue and dequeue. That is terminal (no retry
|
|
547
|
+
// helps); running the leg anyway burned a full 8-minute worker on
|
|
548
|
+
// a closed issue (live: 952e7471). Cancel the dispatched execution
|
|
549
|
+
// and terminalize the task as cancelled - NOT back to pending (a
|
|
550
|
+
// pending task would redispatch; the sweep will not re-candidate a
|
|
551
|
+
// closed issue, but the queue entry would keep firing).
|
|
552
|
+
logger.warn(`Controller: issue closed before dispatch for ${updatedTask.id} - cancelling task`);
|
|
553
|
+
void (async () => {
|
|
554
|
+
await cancelTaskExecution(updatedTask.id, nextAssignment.worker.id, "target issue closed (#5818)", deps);
|
|
555
|
+
deps.updateTeamState((s) => {
|
|
556
|
+
const t = s.tasks[updatedTask.id];
|
|
557
|
+
if (!t)
|
|
558
|
+
return;
|
|
559
|
+
t.status = "failed";
|
|
560
|
+
t.error = "Cancelled: target issue was closed before dispatch (#5818) - no work performed.";
|
|
561
|
+
t.updatedAt = Date.now();
|
|
562
|
+
// #5825: cancelTaskExecution never resets the worker record,
|
|
563
|
+
// and cancelling also suppresses the worker-side completion
|
|
564
|
+
// report - so nothing ever flipped the seat idle. Release here
|
|
565
|
+
// (same shape as the normal completion path) or the worker
|
|
566
|
+
// stays orphan-busy forever (live: 2 busy, 1 in_progress).
|
|
567
|
+
const w = s.workers[nextAssignment.worker.id];
|
|
568
|
+
if (w && w.currentTaskId === updatedTask.id) {
|
|
569
|
+
w.status = "idle";
|
|
570
|
+
w.currentTaskId = undefined;
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
wsServer.broadcastUpdate({ type: "task:updated", data: serializeTask(deps.getTeamState()?.tasks[updatedTask.id] ?? updatedTask) });
|
|
574
|
+
})().catch(() => { });
|
|
575
|
+
}
|
|
576
|
+
else if (claim?.retryEligibility) {
|
|
545
577
|
logger.warn(`Controller: claim eligibility check failed for ${updatedTask.id} - reverting assignment to retry`);
|
|
546
578
|
// Unlike the #191 dispatch-failure path, the dispatch SUCCEEDED
|
|
547
579
|
// here: cancel the already-dispatched execution before reverting
|
|
@@ -556,6 +588,35 @@ export async function runAutoAssignRound(deps, preferredWorkerId, attemptedPairs
|
|
|
556
588
|
});
|
|
557
589
|
})().catch(() => { });
|
|
558
590
|
}
|
|
591
|
+
else if (claim?.reason === "external activity" || claim?.reason === "assignees present") {
|
|
592
|
+
// #5823: stand-down verdicts are TERMINAL like issue-closed (the
|
|
593
|
+
// seat/owner is not going away; retrying cannot help) - the old
|
|
594
|
+
// else-branch only cleared the hold and the leg ran to completion
|
|
595
|
+
// on an issue another seat owns (live: the #5819 self-fix leg
|
|
596
|
+
// stood down at 21:24 yet kept executing at 21:38). Same treatment
|
|
597
|
+
// as #5818: cancel the dispatched execution, terminalize with the
|
|
598
|
+
// stand-down reason, no dead-letter count.
|
|
599
|
+
logger.warn(`Controller: claim stood down (${claim.reason}) for ${updatedTask.id} - cancelling task`);
|
|
600
|
+
void (async () => {
|
|
601
|
+
await cancelTaskExecution(updatedTask.id, nextAssignment.worker.id, `claim stand-down: ${claim.reason} (#5823)`, deps);
|
|
602
|
+
deps.updateTeamState((s) => {
|
|
603
|
+
const t = s.tasks[updatedTask.id];
|
|
604
|
+
if (!t)
|
|
605
|
+
return;
|
|
606
|
+
t.status = "failed";
|
|
607
|
+
t.error = `Cancelled: claim stood down (${claim.reason}) - another seat/owner owns the issue (#5823). No work performed.`;
|
|
608
|
+
t.updatedAt = Date.now();
|
|
609
|
+
// #5825: same orphan-busy release as the #5818 branch above.
|
|
610
|
+
const w = s.workers[nextAssignment.worker.id];
|
|
611
|
+
if (w && w.currentTaskId === updatedTask.id) {
|
|
612
|
+
w.status = "idle";
|
|
613
|
+
w.currentTaskId = undefined;
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
clearAssignmentHold(updatedTask.id, deps);
|
|
617
|
+
wsServer.broadcastUpdate({ type: "task:updated", data: serializeTask(deps.getTeamState()?.tasks[updatedTask.id] ?? updatedTask) });
|
|
618
|
+
})().catch(() => { });
|
|
619
|
+
}
|
|
559
620
|
else {
|
|
560
621
|
// Claim attempt concluded definitively (claimed / stood down /
|
|
561
622
|
// WRITE failure continuing unclaimed): end the retry cycle.
|
|
@@ -10,7 +10,7 @@ import { buildEmptyTaskCleanupSummary, deleteTaskCascade } from "./task-cleanup.
|
|
|
10
10
|
import { allowsNoChangeCompletion, applyTaskResult, buildEffectiveTaskResultContract, consolidateDiscoveredPatterns, ensureTaskResultContract, enrichWithFilesystemHtmlScan, filterStaleDeliverables, projectHasMeaningfulFileChanges, taskRequiresMeaningfulProjectChangeGate, } from "./task-results.js";
|
|
11
11
|
import { requestTaskClarification } from "./clarification-routes.js";
|
|
12
12
|
import { buildControllerParallelHelpMessage, resolveControllerWorkflowSessionKey, } from "./controller-planning.js";
|
|
13
|
-
import { ControllerIntakeSwitchInProgressError, runControllerIntake, } from "./controller-intake.js";
|
|
13
|
+
import { ControllerIntakeSwitchInProgressError, isStillWaitingResponse, runControllerIntake, } from "./controller-intake.js";
|
|
14
14
|
import { buildStartupReadinessMessage, shouldBlockControllerUntilProvisioningReady, } from "./worker-routes.js";
|
|
15
15
|
import { buildControllerNoWorkersMessage, shouldBlockControllerWithoutWorkers, } from "./controller-capacity.js";
|
|
16
16
|
// Same value as the SWITCH_TASK_SUBMISSION_RETRY_AFTER_SECONDS constant the
|
|
@@ -489,7 +489,7 @@ export async function handleTaskResultRequest(deps, req, res, pathname) {
|
|
|
489
489
|
const { logger, getTeamState, updateTeamState } = deps;
|
|
490
490
|
const taskId = pathname.split("/")[4];
|
|
491
491
|
const body = await parseJsonBody(req);
|
|
492
|
-
|
|
492
|
+
let result = typeof body.result === "string" ? body.result : "";
|
|
493
493
|
let error = typeof body.error === "string" ? body.error : undefined;
|
|
494
494
|
const workerId = typeof body.workerId === "string" ? body.workerId : undefined;
|
|
495
495
|
const currentTask = getTeamState()?.tasks[taskId];
|
|
@@ -574,6 +574,43 @@ export async function handleTaskResultRequest(deps, req, res, pathname) {
|
|
|
574
574
|
return;
|
|
575
575
|
}
|
|
576
576
|
const gatedTask = getTeamState()?.tasks[taskId];
|
|
577
|
+
// #5767 fourth hole: a worker that never produced work can "complete" by
|
|
578
|
+
// submitting the waiting SENTINEL as its result (live: f12efcdb completed
|
|
579
|
+
// with `TEAMCLAW_STILL_WAITING`). The sentinel means "not done yet" - it
|
|
580
|
+
// must never satisfy completion. Reject with an empty stored result so the
|
|
581
|
+
// failed-without-result semantics apply (terminal write-back, claim
|
|
582
|
+
// recovery re-opens the issue, the next sweep retries).
|
|
583
|
+
if (!error && gatedTask && isStillWaitingResponse(result)) {
|
|
584
|
+
error = "Task submitted the TEAMCLAW_STILL_WAITING placeholder as its result - the task is still waiting, not complete. Result discarded; the issue will be re-opened for the next sweep.";
|
|
585
|
+
recordTaskExecutionEvent(taskId, {
|
|
586
|
+
type: "warning",
|
|
587
|
+
phase: "completion_gate",
|
|
588
|
+
source: "controller",
|
|
589
|
+
status: "failed",
|
|
590
|
+
message: error,
|
|
591
|
+
workerId,
|
|
592
|
+
role: gatedTask.assignedRole,
|
|
593
|
+
}, deps);
|
|
594
|
+
result = "";
|
|
595
|
+
}
|
|
596
|
+
// #5770 leg A: a MID-FLIGHT narration is not a final result either (live:
|
|
597
|
+
// "Tree is clean. Now implementing the fix - first the helper in ...").
|
|
598
|
+
// Present-progressive openers mean the work has NOT finished; accepting
|
|
599
|
+
// them completes a task with zero product. Reject like the sentinel -
|
|
600
|
+
// fresh attempt on the next sweep once the worker actually finishes.
|
|
601
|
+
if (!error && gatedTask && /\b(?:now|currently|next)\s+(?:implementing|working on|fixing|writing|adding|refactoring|investigating|starting)\b/i.test(result.slice(0, 400))) {
|
|
602
|
+
error = "Task submitted a mid-flight narration (present-progressive) as its result - the work is still in progress, not complete. Result discarded; the issue will be re-opened for the next sweep.";
|
|
603
|
+
recordTaskExecutionEvent(taskId, {
|
|
604
|
+
type: "warning",
|
|
605
|
+
phase: "completion_gate",
|
|
606
|
+
source: "controller",
|
|
607
|
+
status: "failed",
|
|
608
|
+
message: error,
|
|
609
|
+
workerId,
|
|
610
|
+
role: gatedTask.assignedRole,
|
|
611
|
+
}, deps);
|
|
612
|
+
result = "";
|
|
613
|
+
}
|
|
577
614
|
if (!error
|
|
578
615
|
&& gatedTask
|
|
579
616
|
&& taskRequiresMeaningfulProjectChangeGate(gatedTask)
|
|
@@ -448,6 +448,17 @@ export function createTunnelManager(deps) {
|
|
|
448
448
|
const st = readTunnelState();
|
|
449
449
|
if (!st || st.tunnelId === "quick")
|
|
450
450
|
return null; // one-off, not recoverable
|
|
451
|
+
// ClawHub security review 2026.11.6 (finding 4): a self-hosted tunnel's
|
|
452
|
+
// custom hostname never matches the built-in gate suffixes, so its
|
|
453
|
+
// traffic arrives as a loopback peer and inherits trusted-host access.
|
|
454
|
+
// Device protection is the only thing standing between that public
|
|
455
|
+
// ingress and the API - do not reconnect one while protection is off;
|
|
456
|
+
// drop the stale state so the owner re-enables deliberately.
|
|
457
|
+
if (st.tunnelId === "self-hosted" && deps.isProtectionOn && !deps.isProtectionOn()) {
|
|
458
|
+
logger.warn("TeamClaw tunnel: NOT recovering the previous self-hosted tunnel - device protection is off and a custom-domain tunnel bypasses the sharing gate; enable device pairing (POST /api/v1/security/enable) and start it again from the Tunnel page");
|
|
459
|
+
clearTunnelState();
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
451
462
|
const bin = findCloudflared();
|
|
452
463
|
if (!bin) {
|
|
453
464
|
logger.warn("TeamClaw tunnel: previous share found but cloudflared is not installed; not recovering");
|
|
@@ -176,6 +176,17 @@ export function createTunnelManagementRoutes(tunnelManager, deps) {
|
|
|
176
176
|
if (!tunnelStartAllowedFrom(req, res)) {
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
|
+
// ClawHub security review 2026.11.6 (finding 4): a self-hosted
|
|
180
|
+
// tunnel's custom hostname is outside the built-in gate, so its
|
|
181
|
+
// requests arrive as trusted loopback peers. Without device
|
|
182
|
+
// protection that is unauthenticated public access to the API.
|
|
183
|
+
if (!isProtectionOn(deps.getTeamState())) {
|
|
184
|
+
sendJson(res, 409, {
|
|
185
|
+
error: "device protection must be enabled before starting a self-hosted tunnel",
|
|
186
|
+
hint: "A custom-domain tunnel bypasses the sharing gate (its hostname is not *.teamclaw.dev), so every request reaches this controller as a trusted local peer. Enable device pairing first (POST /api/v1/security/enable from the controller host), then start the tunnel. Managed (*.teamclaw.dev) tunnels are gate-protected and unaffected.",
|
|
187
|
+
});
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
179
190
|
logger.info(`TeamClaw tunnel: start-self-hosted requested (${tunnelCaller(req)})`);
|
|
180
191
|
let token = "";
|
|
181
192
|
try {
|