@teamclaws/teamclaw 2026.11.11 → 2026.11.13

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.
@@ -147,10 +147,10 @@ async function taskCheckpointRoute(ctx) {
147
147
  await handleTaskCheckpointRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname);
148
148
  }
149
149
  async function taskResultContractRoute(ctx) {
150
- await handleTaskResultContractRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname);
150
+ await handleTaskResultContractRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname, ctx.peer);
151
151
  }
152
152
  async function taskResultRoute(ctx) {
153
- await handleTaskResultRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname);
153
+ await handleTaskResultRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname, ctx.peer);
154
154
  }
155
155
  async function taskExecutionEventRoute(ctx) {
156
156
  await handleTaskExecutionEventRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname);
@@ -1,4 +1,5 @@
1
1
  import { generateId, parseJsonBody, sendError, sendJson } from "../protocol.js";
2
+ import { isProtectionOn } from "./security.js";
2
3
  import { normalizeRecommendedSkills, validateActiveRoleId } from "../profile-loader.js";
3
4
  import { deriveProjectSlug, deriveStableProjectKey } from "../openclaw-workspace.js";
4
5
  import { backfillWorkerProgressContract, enrichDeliverablesWithPreviewInference, normalizeTaskHandoffContract, normalizeWorkerProgressContract, normalizeWorkerTaskResultContract, } from "../interaction-contracts.js";
@@ -433,11 +434,44 @@ export async function handleTaskCheckpointRequest(deps, req, res, pathname) {
433
434
  }
434
435
  sendJson(res, 200, { ok: true, updatedAt: task.checkpoint?.updatedAt });
435
436
  }
437
+ /**
438
+ * ClawHub security review 2026.11.11: a submitted previewCommand is run by
439
+ * the controller as a shell process (restricted env, confined cwd - but still
440
+ * arbitrary code as the controller user). While device protection is off,
441
+ * NO peer except loopback (the controller host itself) may supply one - the
442
+ * 2026.11.11 review showed LAN peers are equally unpaired in L0, so a LAN
443
+ * or remote caller's contract is recorded WITHOUT preview fields so it can
444
+ * never trigger a process. Protection on: the device gate authenticated the
445
+ * caller, so nothing is stripped. Container/LAN workers that need dynamic
446
+ * previews must run with device pairing enabled.
447
+ */
448
+ export function stripPreviewCommandsForUntrustedPeer(body, peer, protectionOn) {
449
+ if (protectionOn || !peer || peer.loopback) {
450
+ return;
451
+ }
452
+ for (const key of ["contract", "resultContract"]) {
453
+ const raw = body[key];
454
+ if (!raw || typeof raw !== "object") {
455
+ continue;
456
+ }
457
+ const deliverables = raw.deliverables;
458
+ if (!Array.isArray(deliverables)) {
459
+ continue;
460
+ }
461
+ for (const deliverable of deliverables) {
462
+ if (deliverable && typeof deliverable === "object") {
463
+ delete deliverable.previewCommand;
464
+ delete deliverable.previewCwd;
465
+ }
466
+ }
467
+ }
468
+ }
436
469
  // POST /api/v1/tasks/:id/result-contract
437
- export async function handleTaskResultContractRequest(deps, req, res, pathname) {
470
+ export async function handleTaskResultContractRequest(deps, req, res, pathname, peer) {
438
471
  const { logger, getTeamState, updateTeamState } = deps;
439
472
  const taskId = pathname.split("/")[4];
440
473
  const body = await parseJsonBody(req);
474
+ stripPreviewCommandsForUntrustedPeer(body, peer, isProtectionOn(getTeamState()));
441
475
  const contract = normalizeWorkerTaskResultContract(body.contract ?? body.resultContract);
442
476
  const workerId = typeof body.workerId === "string" ? body.workerId : undefined;
443
477
  const currentTask = getTeamState()?.tasks[taskId];
@@ -485,10 +519,11 @@ export async function handleTaskResultContractRequest(deps, req, res, pathname)
485
519
  sendJson(res, 201, { task: serializeTask(state.tasks[taskId]) });
486
520
  }
487
521
  // POST /api/v1/tasks/:id/result
488
- export async function handleTaskResultRequest(deps, req, res, pathname) {
522
+ export async function handleTaskResultRequest(deps, req, res, pathname, peer) {
489
523
  const { logger, getTeamState, updateTeamState } = deps;
490
524
  const taskId = pathname.split("/")[4];
491
525
  const body = await parseJsonBody(req);
526
+ stripPreviewCommandsForUntrustedPeer(body, peer, isProtectionOn(getTeamState()));
492
527
  let result = typeof body.result === "string" ? body.result : "";
493
528
  let error = typeof body.error === "string" ? body.error : undefined;
494
529
  const workerId = typeof body.workerId === "string" ? body.workerId : undefined;
@@ -1,11 +1,27 @@
1
- import { sendJson, sendError } from "../protocol.js";
1
+ import { sendJson, sendError, MAX_FORM_BODY_BYTES, BodyTooLargeError } from "../protocol.js";
2
2
  import { getGithubAuthManager } from "./github-auth.js";
3
3
  import { gatePageHtml, computeGateCookie, GATE_COOKIE_NAME, selfHostedTokenFromEnv } from "./tunnel-manager.js";
4
4
  import { isLanIp, isProtectionOn, secretsEqual } from "./security.js";
5
+ /**
6
+ * ClawHub security review 2026.11.12 (finding 2): the gate verification
7
+ * endpoint is reachable from the internet before any authentication; the
8
+ * form reader used to buffer whatever was posted. Bodies are bounded by
9
+ * MAX_FORM_BODY_BYTES and oversized posts surface as BodyTooLargeError (413).
10
+ * Kept as an async-iterator read (not the shared event-based reader) so any
11
+ * async-iterable request body works.
12
+ */
5
13
  async function readFormBody(request) {
6
14
  const chunks = [];
7
- for await (const chunk of request)
8
- chunks.push(chunk);
15
+ let total = 0;
16
+ for await (const chunk of request) {
17
+ const buf = chunk;
18
+ total += buf.length;
19
+ if (total > MAX_FORM_BODY_BYTES) {
20
+ request.destroy?.();
21
+ throw new BodyTooLargeError(MAX_FORM_BODY_BYTES);
22
+ }
23
+ chunks.push(buf);
24
+ }
9
25
  const raw = Buffer.concat(chunks).toString("utf8");
10
26
  const out = {};
11
27
  for (const [k, v] of new URLSearchParams(raw))
@@ -79,7 +95,17 @@ export function createTunnelGateRoutes(tunnelManager) {
79
95
  sendJson(res, 429, { error: "Too many gate verification attempts. Wait a minute and try again." });
80
96
  return;
81
97
  }
82
- const form = await readFormBody(req);
98
+ let form;
99
+ try {
100
+ form = await readFormBody(req);
101
+ }
102
+ catch (err) {
103
+ if (err instanceof BodyTooLargeError) {
104
+ sendError(res, 413, err.message);
105
+ return;
106
+ }
107
+ throw err;
108
+ }
83
109
  // Issue #237 W3: gate tokens are 128-bit base64url and therefore
84
110
  // case-sensitive - only surrounding whitespace is normalized (the
85
111
  // old .toUpperCase() fold belonged to the retired 8-char token).
@@ -193,7 +219,13 @@ export function createTunnelManagementRoutes(tunnelManager, deps) {
193
219
  const body = await readFormBody(req);
194
220
  token = String(body.token ?? "");
195
221
  }
196
- catch { /* fall through to env */ }
222
+ catch (err) {
223
+ if (err instanceof BodyTooLargeError) {
224
+ sendError(res, 413, err.message);
225
+ return;
226
+ }
227
+ /* fall through to env */
228
+ }
197
229
  if (!token.trim()) {
198
230
  const envToken = selfHostedTokenFromEnv();
199
231
  if (!envToken) {
@@ -73,6 +73,8 @@ async function parseJsonBody(req) {
73
73
  export const MAX_JSON_BODY_BYTES = 8 * 1024 * 1024;
74
74
  /** Repo bundle imports are binary git bundles - large, but still bounded. */
75
75
  export const MAX_BUNDLE_BODY_BYTES = 256 * 1024 * 1024;
76
+ /** Tunnel gate / connector-token form bodies: a token is a few dozen bytes. */
77
+ export const MAX_FORM_BODY_BYTES = 64 * 1024;
76
78
  export class BodyTooLargeError extends Error {
77
79
  limitBytes;
78
80
  constructor(limitBytes) {
@@ -2,7 +2,7 @@
2
2
  "id": "teamclaw",
3
3
  "name": "TeamClaw",
4
4
  "description": "Virtual team collaboration - multiple OpenClaw instances form a virtual software company with role-based task routing.",
5
- "version": "2026.11.11",
5
+ "version": "2026.11.13",
6
6
  "activation": {
7
7
  "onStartup": true
8
8
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamclaws/teamclaw",
3
- "version": "2026.11.11",
3
+ "version": "2026.11.13",
4
4
  "description": "OpenClaw virtual software team orchestration plugin - controller, role-based workers, Web UI with internet tunnel sharing",
5
5
  "private": false,
6
6
  "keywords": [
@@ -338,11 +338,11 @@ async function taskCheckpointRoute(ctx: RouteContext): Promise<void> {
338
338
  }
339
339
 
340
340
  async function taskResultContractRoute(ctx: RouteContext): Promise<void> {
341
- await handleTaskResultContractRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname);
341
+ await handleTaskResultContractRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname, ctx.peer);
342
342
  }
343
343
 
344
344
  async function taskResultRoute(ctx: RouteContext): Promise<void> {
345
- await handleTaskResultRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname);
345
+ await handleTaskResultRequest(ctx.deps, ctx.req, ctx.res, ctx.pathname, ctx.peer);
346
346
  }
347
347
 
348
348
  async function taskExecutionEventRoute(ctx: RouteContext): Promise<void> {
@@ -18,6 +18,7 @@ import type {
18
18
  WorkerProgressContract,
19
19
  } from "../types.js";
20
20
  import { generateId, parseJsonBody, sendError, sendJson } from "../protocol.js";
21
+ import { isProtectionOn, type SecurityPeer } from "./security.js";
21
22
  import { normalizeRecommendedSkills, validateActiveRoleId } from "../profile-loader.js";
22
23
  import { deriveProjectSlug, deriveStableProjectKey } from "../openclaw-workspace.js";
23
24
  import {
@@ -522,11 +523,49 @@ export async function handleTaskCheckpointRequest(deps: ControllerTaskDomainDeps
522
523
  sendJson(res, 200, { ok: true, updatedAt: task.checkpoint?.updatedAt });
523
524
  }
524
525
 
526
+ /**
527
+ * ClawHub security review 2026.11.11: a submitted previewCommand is run by
528
+ * the controller as a shell process (restricted env, confined cwd - but still
529
+ * arbitrary code as the controller user). While device protection is off,
530
+ * NO peer except loopback (the controller host itself) may supply one - the
531
+ * 2026.11.11 review showed LAN peers are equally unpaired in L0, so a LAN
532
+ * or remote caller's contract is recorded WITHOUT preview fields so it can
533
+ * never trigger a process. Protection on: the device gate authenticated the
534
+ * caller, so nothing is stripped. Container/LAN workers that need dynamic
535
+ * previews must run with device pairing enabled.
536
+ */
537
+ export function stripPreviewCommandsForUntrustedPeer(
538
+ body: Record<string, unknown>,
539
+ peer: SecurityPeer | undefined,
540
+ protectionOn: boolean,
541
+ ): void {
542
+ if (protectionOn || !peer || peer.loopback) {
543
+ return;
544
+ }
545
+ for (const key of ["contract", "resultContract"]) {
546
+ const raw = body[key];
547
+ if (!raw || typeof raw !== "object") {
548
+ continue;
549
+ }
550
+ const deliverables = (raw as { deliverables?: unknown }).deliverables;
551
+ if (!Array.isArray(deliverables)) {
552
+ continue;
553
+ }
554
+ for (const deliverable of deliverables) {
555
+ if (deliverable && typeof deliverable === "object") {
556
+ delete (deliverable as Record<string, unknown>).previewCommand;
557
+ delete (deliverable as Record<string, unknown>).previewCwd;
558
+ }
559
+ }
560
+ }
561
+ }
562
+
525
563
  // POST /api/v1/tasks/:id/result-contract
526
- export async function handleTaskResultContractRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse, pathname: string): Promise<void> {
564
+ export async function handleTaskResultContractRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse, pathname: string, peer?: SecurityPeer): Promise<void> {
527
565
  const { logger, getTeamState, updateTeamState } = deps;
528
566
  const taskId = pathname.split("/")[4]!;
529
567
  const body = await parseJsonBody(req);
568
+ stripPreviewCommandsForUntrustedPeer(body, peer, isProtectionOn(getTeamState()));
530
569
  const contract = normalizeWorkerTaskResultContract(body.contract ?? body.resultContract);
531
570
  const workerId = typeof body.workerId === "string" ? body.workerId : undefined;
532
571
  const currentTask = getTeamState()?.tasks[taskId];
@@ -576,10 +615,11 @@ export async function handleTaskResultContractRequest(deps: ControllerTaskDomain
576
615
  }
577
616
 
578
617
  // POST /api/v1/tasks/:id/result
579
- export async function handleTaskResultRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse, pathname: string): Promise<void> {
618
+ export async function handleTaskResultRequest(deps: ControllerTaskDomainDeps, req: IncomingMessage, res: ServerResponse, pathname: string, peer?: SecurityPeer): Promise<void> {
580
619
  const { logger, getTeamState, updateTeamState } = deps;
581
620
  const taskId = pathname.split("/")[4]!;
582
621
  const body = await parseJsonBody(req);
622
+ stripPreviewCommandsForUntrustedPeer(body, peer, isProtectionOn(getTeamState()));
583
623
  let result = typeof body.result === "string" ? body.result : "";
584
624
  let error = typeof body.error === "string" ? body.error : undefined;
585
625
  const workerId = typeof body.workerId === "string" ? body.workerId : undefined;
@@ -8,16 +8,33 @@
8
8
  // http-server.js as TYPE ONLY (ControllerHttpDeps), so the module graph
9
9
  // stays acyclic - same discipline as security.ts.
10
10
  import type { IncomingMessage, ServerResponse } from "node:http";
11
- import { sendJson, sendError } from "../protocol.js";
11
+ import { sendJson, sendError, MAX_FORM_BODY_BYTES, BodyTooLargeError } from "../protocol.js";
12
12
  import { getGithubAuthManager } from "./github-auth.js";
13
13
  import { gatePageHtml, computeGateCookie, GATE_COOKIE_NAME, selfHostedTokenFromEnv, type TunnelManager } from "./tunnel-manager.js";
14
14
  import { isLanIp, isProtectionOn, secretsEqual } from "./security.js";
15
15
  import type { ControllerHttpDeps } from "./http-server.js";
16
16
  import type { RouteDef } from "./route-table.js";
17
17
 
18
+ /**
19
+ * ClawHub security review 2026.11.12 (finding 2): the gate verification
20
+ * endpoint is reachable from the internet before any authentication; the
21
+ * form reader used to buffer whatever was posted. Bodies are bounded by
22
+ * MAX_FORM_BODY_BYTES and oversized posts surface as BodyTooLargeError (413).
23
+ * Kept as an async-iterator read (not the shared event-based reader) so any
24
+ * async-iterable request body works.
25
+ */
18
26
  async function readFormBody(request: IncomingMessage): Promise<Record<string, unknown>> {
19
27
  const chunks: Buffer[] = [];
20
- for await (const chunk of request) chunks.push(chunk as Buffer);
28
+ let total = 0;
29
+ for await (const chunk of request) {
30
+ const buf = chunk as Buffer;
31
+ total += buf.length;
32
+ if (total > MAX_FORM_BODY_BYTES) {
33
+ request.destroy?.();
34
+ throw new BodyTooLargeError(MAX_FORM_BODY_BYTES);
35
+ }
36
+ chunks.push(buf);
37
+ }
21
38
  const raw = Buffer.concat(chunks).toString("utf8");
22
39
  const out: Record<string, unknown> = {};
23
40
  for (const [k, v] of new URLSearchParams(raw)) out[k] = v;
@@ -96,7 +113,16 @@ export function createTunnelGateRoutes(tunnelManager: TunnelManager): readonly R
96
113
  sendJson(res, 429, { error: "Too many gate verification attempts. Wait a minute and try again." });
97
114
  return;
98
115
  }
99
- const form = await readFormBody(req);
116
+ let form: Record<string, unknown>;
117
+ try {
118
+ form = await readFormBody(req);
119
+ } catch (err) {
120
+ if (err instanceof BodyTooLargeError) {
121
+ sendError(res, 413, err.message);
122
+ return;
123
+ }
124
+ throw err;
125
+ }
100
126
  // Issue #237 W3: gate tokens are 128-bit base64url and therefore
101
127
  // case-sensitive - only surrounding whitespace is normalized (the
102
128
  // old .toUpperCase() fold belonged to the retired 8-char token).
@@ -210,7 +236,13 @@ export function createTunnelManagementRoutes(tunnelManager: TunnelManager, deps:
210
236
  try {
211
237
  const body = await readFormBody(req) as { token?: unknown };
212
238
  token = String(body.token ?? "");
213
- } catch { /* fall through to env */ }
239
+ } catch (err) {
240
+ if (err instanceof BodyTooLargeError) {
241
+ sendError(res, 413, err.message);
242
+ return;
243
+ }
244
+ /* fall through to env */
245
+ }
214
246
  if (!token.trim()) {
215
247
  const envToken = selfHostedTokenFromEnv();
216
248
  if (!envToken) { sendError(res, 400, "connector token required (or set TEAMCLAW_TUNNEL_TOKEN)"); return; }
package/src/protocol.ts CHANGED
@@ -83,6 +83,8 @@ async function parseJsonBody(req: IncomingMessage): Promise<Record<string, unkno
83
83
  export const MAX_JSON_BODY_BYTES = 8 * 1024 * 1024;
84
84
  /** Repo bundle imports are binary git bundles - large, but still bounded. */
85
85
  export const MAX_BUNDLE_BODY_BYTES = 256 * 1024 * 1024;
86
+ /** Tunnel gate / connector-token form bodies: a token is a few dozen bytes. */
87
+ export const MAX_FORM_BODY_BYTES = 64 * 1024;
86
88
 
87
89
  export class BodyTooLargeError extends Error {
88
90
  constructor(readonly limitBytes: number) {