@teamclaws/teamclaw 2026.11.8 → 2026.11.10
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/dist/src/controller/http-server.js +5 -1
- package/dist/src/controller/preview-proxy.js +11 -5
- package/dist/src/controller/repo-routes.js +14 -2
- package/dist/src/controller/security.js +29 -0
- package/dist/src/protocol.js +43 -4
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/controller/http-server.ts +5 -1
- package/src/controller/preview-proxy.ts +11 -5
- package/src/controller/repo-routes.ts +13 -2
- package/src/controller/security.ts +31 -0
- package/src/protocol.ts +40 -4
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
// controller-tools.ts, kickoff-orchestrator.ts, prompt-injector.ts.
|
|
45
45
|
// ===========================================================================
|
|
46
46
|
import http from "node:http";
|
|
47
|
-
import { sendJson, sendError } from "../protocol.js";
|
|
47
|
+
import { sendJson, sendError, BodyTooLargeError } from "../protocol.js";
|
|
48
48
|
import { getActiveProfile } from "../profile-loader.js";
|
|
49
49
|
import { autoAssignPendingTasks } from "./task-assignment.js";
|
|
50
50
|
import { createTunnelManager, gatePageHtml } from "./tunnel-manager.js";
|
|
@@ -212,6 +212,10 @@ export function createControllerHttpServer(deps) {
|
|
|
212
212
|
}
|
|
213
213
|
catch (err) {
|
|
214
214
|
logger.error(`Controller HTTP error: ${err instanceof Error ? err.message : String(err)}`);
|
|
215
|
+
if (err instanceof BodyTooLargeError) {
|
|
216
|
+
sendError(res, 413, err.message);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
215
219
|
sendError(res, 500, "Internal server error");
|
|
216
220
|
}
|
|
217
221
|
});
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
import http from "node:http";
|
|
10
10
|
import zlib from "node:zlib";
|
|
11
11
|
import { sendJson } from "../protocol.js";
|
|
12
|
+
/** Opaque-origin sandbox applied to every preview-proxy response. */
|
|
13
|
+
export const PREVIEW_SANDBOX_CSP = "sandbox allow-scripts allow-forms";
|
|
14
|
+
;
|
|
12
15
|
/**
|
|
13
16
|
* Headers the preview proxy never forwards to the untrusted preview
|
|
14
17
|
* subprocess (ClawHub security review 2026.11.7 finding 2): every
|
|
@@ -85,6 +88,12 @@ export function handlePreviewProxyRequest(deps, req, res, requestUrl, pathname)
|
|
|
85
88
|
}, (proxyRes) => {
|
|
86
89
|
// Same review: never let the preview plant cookies on the controller origin.
|
|
87
90
|
delete proxyRes.headers["set-cookie"];
|
|
91
|
+
// Every preview response is served under the controller origin (the proxy
|
|
92
|
+
// path), not just text/html: SVG, XHTML and XML passthrough are active
|
|
93
|
+
// documents too (2026.11.8 rescan finding). A response-level sandbox CSP
|
|
94
|
+
// gives each of them an opaque origin; for non-document resources (js,
|
|
95
|
+
// css, images) the directive is simply ignored.
|
|
96
|
+
proxyRes.headers["content-security-policy"] = PREVIEW_SANDBOX_CSP;
|
|
88
97
|
const contentType = (proxyRes.headers["content-type"] ?? "").toLowerCase();
|
|
89
98
|
if (proxyRes.statusCode !== 200 && proxyRes.statusCode !== 201 && proxyRes.statusCode !== 301 && proxyRes.statusCode !== 302 && proxyRes.statusCode !== 304) {
|
|
90
99
|
res.writeHead(proxyRes.statusCode ?? 502, proxyRes.headers);
|
|
@@ -120,11 +129,8 @@ export function handlePreviewProxyRequest(deps, req, res, requestUrl, pathname)
|
|
|
120
129
|
// We've decoded and rewritten the body — remove upstream encoding headers.
|
|
121
130
|
delete resHeaders["content-encoding"];
|
|
122
131
|
delete resHeaders["transfer-encoding"];
|
|
123
|
-
// Preview HTML executes under the controller origin (the proxy path)
|
|
124
|
-
//
|
|
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";
|
|
132
|
+
// Preview HTML executes under the controller origin (the proxy path);
|
|
133
|
+
// the sandbox CSP was already applied to the shared header object above.
|
|
128
134
|
resHeaders["content-length"] = String(Buffer.byteLength(rewritten, "utf-8"));
|
|
129
135
|
res.writeHead(proxyRes.statusCode ?? 200, resHeaders);
|
|
130
136
|
res.end(rewritten);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sendJson, sendError, pinnedCorsAllowOrigin, readRequestBody } from "../protocol.js";
|
|
1
|
+
import { sendJson, sendError, pinnedCorsAllowOrigin, readRequestBody, MAX_BUNDLE_BODY_BYTES, BodyTooLargeError } from "../protocol.js";
|
|
2
2
|
import { getActiveProfile, validateActiveRoleId } from "../profile-loader.js";
|
|
3
3
|
import { ensureControllerGitRepo, exportControllerGitBundle, importControllerGitBundle } from "../git-collaboration.js";
|
|
4
4
|
import { recordTaskExecutionEvent } from "./task-execution.js";
|
|
@@ -73,7 +73,19 @@ export async function handleRepoBundleRequest(deps, res) {
|
|
|
73
73
|
export async function repoImportRoute(ctx) {
|
|
74
74
|
const { req, res, requestUrl, deps } = ctx;
|
|
75
75
|
const { config, logger, updateTeamState } = deps;
|
|
76
|
-
|
|
76
|
+
let body;
|
|
77
|
+
try {
|
|
78
|
+
// Repo bundles are binary git bundles - bounded by the bundle limit, not
|
|
79
|
+
// the JSON limit (2026.11.9 review: request bodies are capped everywhere).
|
|
80
|
+
body = await readRequestBody(req, MAX_BUNDLE_BODY_BYTES);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
if (err instanceof BodyTooLargeError) {
|
|
84
|
+
sendError(res, 413, `bundle body exceeds the ${err.limitBytes}-byte limit`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
77
89
|
if (!body.length) {
|
|
78
90
|
sendError(res, 400, "bundle body is required");
|
|
79
91
|
return;
|
|
@@ -350,6 +350,7 @@ export function applyResponseCorsPolicy(req, res, protectionOn) {
|
|
|
350
350
|
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
351
351
|
res.setHeader("Vary", "Origin");
|
|
352
352
|
}
|
|
353
|
+
const MUTATING_HTTP_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
353
354
|
/**
|
|
354
355
|
* True when the request path must NOT be blocked by the device gate:
|
|
355
356
|
* health (liveness probes), UI static assets and the tunnel gate pages
|
|
@@ -425,6 +426,22 @@ export function createSecurityMiddleware(deps) {
|
|
|
425
426
|
const state = deps.getTeamState();
|
|
426
427
|
const protectionOn = isProtectionOn(state);
|
|
427
428
|
applyResponseCorsPolicy(req, res, protectionOn);
|
|
429
|
+
// ClawHub security review 2026.11.9 (finding 3): a cross-site page in the
|
|
430
|
+
// OWNER's own browser reaches this controller as a loopback peer, so the
|
|
431
|
+
// loopback-only reset hatch would honour it (JSON POST + wildcard CORS in
|
|
432
|
+
// L0). Chromium / Firefox / Safari 16.4+ label such requests
|
|
433
|
+
// Sec-Fetch-Site: cross-site; refuse every mutating method carrying that
|
|
434
|
+
// label regardless of protection level. Non-browser clients omit the
|
|
435
|
+
// header and are unaffected; same-origin UI traffic is same-origin.
|
|
436
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
437
|
+
if (MUTATING_HTTP_METHODS.has(method) && req.headers["sec-fetch-site"] === "cross-site") {
|
|
438
|
+
deps.logger.warn(`Controller: rejected cross-site ${method} ${pathname} from ${peer.ip} (Sec-Fetch-Site: cross-site)`);
|
|
439
|
+
sendJson(res, 403, {
|
|
440
|
+
error: "forbidden",
|
|
441
|
+
hint: "Cross-site requests cannot change controller state; load the controller UI from its own origin.",
|
|
442
|
+
});
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
428
445
|
if (!protectionOn) {
|
|
429
446
|
recordNonLanPeerSignal(deps, state, peer, pathname);
|
|
430
447
|
return true;
|
|
@@ -797,6 +814,18 @@ export async function handleSecurityDeviceDeleteRequest(ctx) {
|
|
|
797
814
|
return;
|
|
798
815
|
}
|
|
799
816
|
const caller = authenticateDeviceToken(state, extractDeviceToken(req));
|
|
817
|
+
// ClawHub security review 2026.11.9 (finding 2): deleting the LAST paired
|
|
818
|
+
// device drops protection to L0 for everyone - exactly what /security/reset
|
|
819
|
+
// does - so it is a controller-host action too. Remote devices may revoke
|
|
820
|
+
// other devices, but the final one must be removed (or reset) from the host.
|
|
821
|
+
const isLastDevice = devices.length === 1;
|
|
822
|
+
if (isLastDevice && !(ctx.peer?.loopback ?? false)) {
|
|
823
|
+
sendJson(res, 403, {
|
|
824
|
+
error: "forbidden",
|
|
825
|
+
hint: "This is the last paired device; removing it would disable protection for everyone. Run the removal or POST /api/v1/security/reset from the controller host.",
|
|
826
|
+
});
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
800
829
|
deps.updateTeamState((s) => {
|
|
801
830
|
if (!s.security) {
|
|
802
831
|
return;
|
package/dist/src/protocol.js
CHANGED
|
@@ -58,7 +58,7 @@ export function secretsEqual(a, b) {
|
|
|
58
58
|
return left.length === right.length && timingSafeEqual(left, right);
|
|
59
59
|
}
|
|
60
60
|
async function parseJsonBody(req) {
|
|
61
|
-
const raw = await readRequestBody(req);
|
|
61
|
+
const raw = await readRequestBody(req, MAX_JSON_BODY_BYTES);
|
|
62
62
|
if (!raw.length) {
|
|
63
63
|
return {};
|
|
64
64
|
}
|
|
@@ -69,14 +69,53 @@ async function parseJsonBody(req) {
|
|
|
69
69
|
throw new Error(`Invalid JSON body: ${err instanceof Error ? err.message : String(err)}`);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
/** JSON request bodies never legitimately exceed a few MiB (task text, config). */
|
|
73
|
+
export const MAX_JSON_BODY_BYTES = 8 * 1024 * 1024;
|
|
74
|
+
/** Repo bundle imports are binary git bundles - large, but still bounded. */
|
|
75
|
+
export const MAX_BUNDLE_BODY_BYTES = 256 * 1024 * 1024;
|
|
76
|
+
export class BodyTooLargeError extends Error {
|
|
77
|
+
limitBytes;
|
|
78
|
+
constructor(limitBytes) {
|
|
79
|
+
super(`request body exceeds the ${limitBytes}-byte limit`);
|
|
80
|
+
this.limitBytes = limitBytes;
|
|
81
|
+
this.name = "BodyTooLargeError";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* ClawHub security review 2026.11.9 (finding 4): the reader used to buffer
|
|
86
|
+
* whatever the peer sent before any route looked at it, so an unauthenticated
|
|
87
|
+
* caller could exhaust gateway memory with a single oversized request. The
|
|
88
|
+
* stream is aborted as soon as the limit is crossed.
|
|
89
|
+
*/
|
|
90
|
+
async function readRequestBody(req, maxBytes = MAX_JSON_BODY_BYTES) {
|
|
73
91
|
return new Promise((resolve, reject) => {
|
|
74
92
|
const chunks = [];
|
|
75
|
-
|
|
93
|
+
let total = 0;
|
|
94
|
+
let settled = false;
|
|
95
|
+
req.on("data", (chunk) => {
|
|
96
|
+
if (settled)
|
|
97
|
+
return;
|
|
98
|
+
total += chunk.length;
|
|
99
|
+
if (total > maxBytes) {
|
|
100
|
+
settled = true;
|
|
101
|
+
req.destroy();
|
|
102
|
+
reject(new BodyTooLargeError(maxBytes));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
chunks.push(chunk);
|
|
106
|
+
});
|
|
76
107
|
req.on("end", () => {
|
|
108
|
+
if (settled)
|
|
109
|
+
return;
|
|
110
|
+
settled = true;
|
|
77
111
|
resolve(Buffer.concat(chunks));
|
|
78
112
|
});
|
|
79
|
-
req.on("error",
|
|
113
|
+
req.on("error", (err) => {
|
|
114
|
+
if (settled)
|
|
115
|
+
return;
|
|
116
|
+
settled = true;
|
|
117
|
+
reject(err);
|
|
118
|
+
});
|
|
80
119
|
});
|
|
81
120
|
}
|
|
82
121
|
/**
|
package/openclaw.plugin.json
CHANGED
|
@@ -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.
|
|
5
|
+
"version": "2026.11.10",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true
|
|
8
8
|
},
|
package/package.json
CHANGED
|
@@ -47,7 +47,7 @@ import http from "node:http";
|
|
|
47
47
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
48
48
|
import type { OpenClawPluginApi, PluginLogger } from "../../api.js";
|
|
49
49
|
import type { PluginConfig, TeamState } from "../types.js";
|
|
50
|
-
import { sendJson, sendError } from "../protocol.js";
|
|
50
|
+
import { sendJson, sendError, BodyTooLargeError } from "../protocol.js";
|
|
51
51
|
import { getActiveProfile, type TeamProfileCapabilities } from "../profile-loader.js";
|
|
52
52
|
import { TaskRouter } from "./task-router.js";
|
|
53
53
|
import { MessageRouter } from "./message-router.js";
|
|
@@ -287,6 +287,10 @@ export function createControllerHttpServer(deps: ControllerHttpDeps): http.Serve
|
|
|
287
287
|
await handleRequest(req, res, pathname, deps, peer);
|
|
288
288
|
} catch (err) {
|
|
289
289
|
logger.error(`Controller HTTP error: ${err instanceof Error ? err.message : String(err)}`);
|
|
290
|
+
if (err instanceof BodyTooLargeError) {
|
|
291
|
+
sendError(res, 413, err.message);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
290
294
|
sendError(res, 500, "Internal server error");
|
|
291
295
|
}
|
|
292
296
|
});
|
|
@@ -13,6 +13,9 @@ import type { PluginLogger } from "../../api.js";
|
|
|
13
13
|
import type { TeamState } from "../types.js";
|
|
14
14
|
import { sendJson } from "../protocol.js";
|
|
15
15
|
|
|
16
|
+
/** Opaque-origin sandbox applied to every preview-proxy response. */
|
|
17
|
+
export const PREVIEW_SANDBOX_CSP = "sandbox allow-scripts allow-forms";;
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* Headers the preview proxy never forwards to the untrusted preview
|
|
18
21
|
* subprocess (ClawHub security review 2026.11.7 finding 2): every
|
|
@@ -109,6 +112,12 @@ export function handlePreviewProxyRequest(
|
|
|
109
112
|
(proxyRes: http.IncomingMessage) => {
|
|
110
113
|
// Same review: never let the preview plant cookies on the controller origin.
|
|
111
114
|
delete proxyRes.headers["set-cookie"];
|
|
115
|
+
// Every preview response is served under the controller origin (the proxy
|
|
116
|
+
// path), not just text/html: SVG, XHTML and XML passthrough are active
|
|
117
|
+
// documents too (2026.11.8 rescan finding). A response-level sandbox CSP
|
|
118
|
+
// gives each of them an opaque origin; for non-document resources (js,
|
|
119
|
+
// css, images) the directive is simply ignored.
|
|
120
|
+
proxyRes.headers["content-security-policy"] = PREVIEW_SANDBOX_CSP;
|
|
112
121
|
const contentType = (proxyRes.headers["content-type"] ?? "").toLowerCase();
|
|
113
122
|
if (proxyRes.statusCode !== 200 && proxyRes.statusCode !== 201 && proxyRes.statusCode !== 301 && proxyRes.statusCode !== 302 && proxyRes.statusCode !== 304) {
|
|
114
123
|
res.writeHead(proxyRes.statusCode ?? 502, proxyRes.headers);
|
|
@@ -148,11 +157,8 @@ export function handlePreviewProxyRequest(
|
|
|
148
157
|
// We've decoded and rewritten the body — remove upstream encoding headers.
|
|
149
158
|
delete resHeaders["content-encoding"];
|
|
150
159
|
delete resHeaders["transfer-encoding"];
|
|
151
|
-
// Preview HTML executes under the controller origin (the proxy path)
|
|
152
|
-
//
|
|
153
|
-
// uses (2026.11.6 finding 6): scripts run, but cannot read the
|
|
154
|
-
// controller session or call /api/v1/* same-origin.
|
|
155
|
-
resHeaders["content-security-policy"] = "sandbox allow-scripts allow-forms";
|
|
160
|
+
// Preview HTML executes under the controller origin (the proxy path);
|
|
161
|
+
// the sandbox CSP was already applied to the shared header object above.
|
|
156
162
|
resHeaders["content-length"] = String(Buffer.byteLength(rewritten, "utf-8"));
|
|
157
163
|
res.writeHead(proxyRes.statusCode ?? 200, resHeaders);
|
|
158
164
|
res.end(rewritten);
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import type { ServerResponse } from "node:http";
|
|
12
12
|
import type { PluginLogger } from "../../api.js";
|
|
13
13
|
import type { GitRepoState, PluginConfig, TeamState } from "../types.js";
|
|
14
|
-
import { sendJson, sendError, pinnedCorsAllowOrigin, readRequestBody } from "../protocol.js";
|
|
14
|
+
import { sendJson, sendError, pinnedCorsAllowOrigin, readRequestBody, MAX_BUNDLE_BODY_BYTES, BodyTooLargeError } from "../protocol.js";
|
|
15
15
|
import { getActiveProfile, validateActiveRoleId } from "../profile-loader.js";
|
|
16
16
|
import { ensureControllerGitRepo, exportControllerGitBundle, importControllerGitBundle } from "../git-collaboration.js";
|
|
17
17
|
import { recordTaskExecutionEvent } from "./task-execution.js";
|
|
@@ -104,7 +104,18 @@ export async function handleRepoBundleRequest(deps: RepoRouteDeps, res: ServerRe
|
|
|
104
104
|
export async function repoImportRoute(ctx: RouteContext): Promise<void> {
|
|
105
105
|
const { req, res, requestUrl, deps } = ctx;
|
|
106
106
|
const { config, logger, updateTeamState } = deps;
|
|
107
|
-
|
|
107
|
+
let body: Buffer;
|
|
108
|
+
try {
|
|
109
|
+
// Repo bundles are binary git bundles - bounded by the bundle limit, not
|
|
110
|
+
// the JSON limit (2026.11.9 review: request bodies are capped everywhere).
|
|
111
|
+
body = await readRequestBody(req, MAX_BUNDLE_BODY_BYTES);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (err instanceof BodyTooLargeError) {
|
|
114
|
+
sendError(res, 413, `bundle body exceeds the ${err.limitBytes}-byte limit`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
108
119
|
if (!body.length) {
|
|
109
120
|
sendError(res, 400, "bundle body is required");
|
|
110
121
|
return;
|
|
@@ -410,6 +410,8 @@ export type SecurityMiddlewareDeps = {
|
|
|
410
410
|
|
|
411
411
|
export type SecurityMiddleware = (req: IncomingMessage, res: ServerResponse, pathname: string, peer: SecurityPeer) => boolean;
|
|
412
412
|
|
|
413
|
+
const MUTATING_HTTP_METHODS: ReadonlySet<string> = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
414
|
+
|
|
413
415
|
/**
|
|
414
416
|
* True when the request path must NOT be blocked by the device gate:
|
|
415
417
|
* health (liveness probes), UI static assets and the tunnel gate pages
|
|
@@ -496,6 +498,23 @@ export function createSecurityMiddleware(deps: SecurityMiddlewareDeps): Security
|
|
|
496
498
|
|
|
497
499
|
applyResponseCorsPolicy(req, res, protectionOn);
|
|
498
500
|
|
|
501
|
+
// ClawHub security review 2026.11.9 (finding 3): a cross-site page in the
|
|
502
|
+
// OWNER's own browser reaches this controller as a loopback peer, so the
|
|
503
|
+
// loopback-only reset hatch would honour it (JSON POST + wildcard CORS in
|
|
504
|
+
// L0). Chromium / Firefox / Safari 16.4+ label such requests
|
|
505
|
+
// Sec-Fetch-Site: cross-site; refuse every mutating method carrying that
|
|
506
|
+
// label regardless of protection level. Non-browser clients omit the
|
|
507
|
+
// header and are unaffected; same-origin UI traffic is same-origin.
|
|
508
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
509
|
+
if (MUTATING_HTTP_METHODS.has(method) && req.headers["sec-fetch-site"] === "cross-site") {
|
|
510
|
+
deps.logger.warn(`Controller: rejected cross-site ${method} ${pathname} from ${peer.ip} (Sec-Fetch-Site: cross-site)`);
|
|
511
|
+
sendJson(res, 403, {
|
|
512
|
+
error: "forbidden",
|
|
513
|
+
hint: "Cross-site requests cannot change controller state; load the controller UI from its own origin.",
|
|
514
|
+
});
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
|
|
499
518
|
if (!protectionOn) {
|
|
500
519
|
recordNonLanPeerSignal(deps, state, peer, pathname);
|
|
501
520
|
return true;
|
|
@@ -912,6 +931,18 @@ export async function handleSecurityDeviceDeleteRequest(ctx: RouteContext): Prom
|
|
|
912
931
|
return;
|
|
913
932
|
}
|
|
914
933
|
const caller = authenticateDeviceToken(state, extractDeviceToken(req));
|
|
934
|
+
// ClawHub security review 2026.11.9 (finding 2): deleting the LAST paired
|
|
935
|
+
// device drops protection to L0 for everyone - exactly what /security/reset
|
|
936
|
+
// does - so it is a controller-host action too. Remote devices may revoke
|
|
937
|
+
// other devices, but the final one must be removed (or reset) from the host.
|
|
938
|
+
const isLastDevice = devices.length === 1;
|
|
939
|
+
if (isLastDevice && !(ctx.peer?.loopback ?? false)) {
|
|
940
|
+
sendJson(res, 403, {
|
|
941
|
+
error: "forbidden",
|
|
942
|
+
hint: "This is the last paired device; removing it would disable protection for everyone. Run the removal or POST /api/v1/security/reset from the controller host.",
|
|
943
|
+
});
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
915
946
|
deps.updateTeamState((s) => {
|
|
916
947
|
if (!s.security) {
|
|
917
948
|
return;
|
package/src/protocol.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function secretsEqual(a: string, b: string): boolean {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
async function parseJsonBody(req: IncomingMessage): Promise<Record<string, unknown>> {
|
|
70
|
-
const raw = await readRequestBody(req);
|
|
70
|
+
const raw = await readRequestBody(req, MAX_JSON_BODY_BYTES);
|
|
71
71
|
if (!raw.length) {
|
|
72
72
|
return {};
|
|
73
73
|
}
|
|
@@ -79,14 +79,50 @@ async function parseJsonBody(req: IncomingMessage): Promise<Record<string, unkno
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
/** JSON request bodies never legitimately exceed a few MiB (task text, config). */
|
|
83
|
+
export const MAX_JSON_BODY_BYTES = 8 * 1024 * 1024;
|
|
84
|
+
/** Repo bundle imports are binary git bundles - large, but still bounded. */
|
|
85
|
+
export const MAX_BUNDLE_BODY_BYTES = 256 * 1024 * 1024;
|
|
86
|
+
|
|
87
|
+
export class BodyTooLargeError extends Error {
|
|
88
|
+
constructor(readonly limitBytes: number) {
|
|
89
|
+
super(`request body exceeds the ${limitBytes}-byte limit`);
|
|
90
|
+
this.name = "BodyTooLargeError";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* ClawHub security review 2026.11.9 (finding 4): the reader used to buffer
|
|
96
|
+
* whatever the peer sent before any route looked at it, so an unauthenticated
|
|
97
|
+
* caller could exhaust gateway memory with a single oversized request. The
|
|
98
|
+
* stream is aborted as soon as the limit is crossed.
|
|
99
|
+
*/
|
|
100
|
+
async function readRequestBody(req: IncomingMessage, maxBytes: number = MAX_JSON_BODY_BYTES): Promise<Buffer> {
|
|
83
101
|
return new Promise((resolve, reject) => {
|
|
84
102
|
const chunks: Buffer[] = [];
|
|
85
|
-
|
|
103
|
+
let total = 0;
|
|
104
|
+
let settled = false;
|
|
105
|
+
req.on("data", (chunk: Buffer) => {
|
|
106
|
+
if (settled) return;
|
|
107
|
+
total += chunk.length;
|
|
108
|
+
if (total > maxBytes) {
|
|
109
|
+
settled = true;
|
|
110
|
+
req.destroy();
|
|
111
|
+
reject(new BodyTooLargeError(maxBytes));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
chunks.push(chunk);
|
|
115
|
+
});
|
|
86
116
|
req.on("end", () => {
|
|
117
|
+
if (settled) return;
|
|
118
|
+
settled = true;
|
|
87
119
|
resolve(Buffer.concat(chunks));
|
|
88
120
|
});
|
|
89
|
-
req.on("error",
|
|
121
|
+
req.on("error", (err) => {
|
|
122
|
+
if (settled) return;
|
|
123
|
+
settled = true;
|
|
124
|
+
reject(err);
|
|
125
|
+
});
|
|
90
126
|
});
|
|
91
127
|
}
|
|
92
128
|
|