@teamclaws/teamclaw 2026.11.9 → 2026.11.11
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/repo-routes.js +14 -2
- package/dist/src/controller/security.js +29 -0
- package/dist/src/protocol.js +43 -4
- package/dist/src/teamauto/repo-sync.js +45 -9
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/controller/http-server.ts +5 -1
- package/src/controller/repo-routes.ts +13 -2
- package/src/controller/security.ts +31 -0
- package/src/protocol.ts +40 -4
- package/src/teamauto/repo-sync.ts +46 -9
|
@@ -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
|
});
|
|
@@ -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
|
/**
|
|
@@ -13,9 +13,23 @@ export function teamAutoProjectDir(repoId) {
|
|
|
13
13
|
* Git operations for TeamAuto. Authentication uses the device-flow token
|
|
14
14
|
* inline in the remote URL (x-access-token basic auth) - proven to survive
|
|
15
15
|
* GitHub's smart-HTTP redirects where extraheader injection does not. The
|
|
16
|
-
* token never touches disk:
|
|
17
|
-
*
|
|
16
|
+
* token never touches disk: fetch/push rewrite the URL per invocation, and
|
|
17
|
+
* the one command that DOES store a URL (the initial clone) has its origin
|
|
18
|
+
* remote rewritten to the clean https URL right afterwards (ClawHub security
|
|
19
|
+
* review 2026.11.10). Every git error is redacted before it can reach a log,
|
|
20
|
+
* the store or a status response.
|
|
18
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* Strip GitHub credentials from anything derived from git output: inline
|
|
24
|
+
* x-access-token userinfo and raw token shapes (gho_/ghp_..., github_pat_...).
|
|
25
|
+
* Exported for tests; applied by run() to every failure message.
|
|
26
|
+
*/
|
|
27
|
+
export function redactGitSecrets(text) {
|
|
28
|
+
return text
|
|
29
|
+
// Drop the whole userinfo so no "user:secret@" shape survives.
|
|
30
|
+
.replace(/x-access-token:[^@\s/]+@/gi, "[REDACTED]@")
|
|
31
|
+
.replace(/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/g, "[REDACTED]");
|
|
32
|
+
}
|
|
19
33
|
function gitEnv() {
|
|
20
34
|
return {
|
|
21
35
|
...process.env,
|
|
@@ -25,13 +39,28 @@ function gitEnv() {
|
|
|
25
39
|
};
|
|
26
40
|
}
|
|
27
41
|
async function run(args, cwd) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
try {
|
|
43
|
+
const { stdout } = await exec("git", args, {
|
|
44
|
+
cwd,
|
|
45
|
+
env: gitEnv(),
|
|
46
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
47
|
+
timeout: 120_000,
|
|
48
|
+
});
|
|
49
|
+
return stdout;
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
// git echoes the failing URL on stderr (the inline token userinfo ends
|
|
53
|
+
// up in the message), and callers persist error messages into the store
|
|
54
|
+
// and status responses. Redact before the error leaves this module.
|
|
55
|
+
if (err instanceof Error) {
|
|
56
|
+
err.message = redactGitSecrets(err.message);
|
|
57
|
+
const withStderr = err;
|
|
58
|
+
if (typeof withStderr.stderr === "string") {
|
|
59
|
+
withStderr.stderr = redactGitSecrets(withStderr.stderr);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
35
64
|
}
|
|
36
65
|
export function createRepoSync(auth, logger) {
|
|
37
66
|
async function tokenizedUrl(cloneUrl) {
|
|
@@ -39,6 +68,10 @@ export function createRepoSync(auth, logger) {
|
|
|
39
68
|
const clean = cloneUrl.replace(/^https:\/\//, "").replace(/\.git$/, "");
|
|
40
69
|
return `https://x-access-token:${token}@${clean}.git`;
|
|
41
70
|
}
|
|
71
|
+
/** The token-less https URL that is safe to persist in .git/config. */
|
|
72
|
+
function cleanUrl(cloneUrl) {
|
|
73
|
+
return `https://${cloneUrl.replace(/^https:\/\//, "").replace(/\.git$/, "")}.git`;
|
|
74
|
+
}
|
|
42
75
|
async function repoDir(repoId) {
|
|
43
76
|
const { reposRoot, legacyReposRoot } = resolveTeamAutoPaths();
|
|
44
77
|
await fs.mkdir(reposRoot, { recursive: true });
|
|
@@ -82,6 +115,9 @@ export function createRepoSync(auth, logger) {
|
|
|
82
115
|
if (!exists) {
|
|
83
116
|
const authed = await tokenizedUrl(cloneUrl);
|
|
84
117
|
await run(["clone", "--filter=blob:none", "--no-checkout", authed, dir]);
|
|
118
|
+
// `git clone <url>` persists <url> as the origin remote - rewrite it to
|
|
119
|
+
// the clean https URL so the token never lands in .git/config.
|
|
120
|
+
await run(["remote", "set-url", "origin", cleanUrl(cloneUrl)], dir);
|
|
85
121
|
await run(["checkout", defaultBranch], dir);
|
|
86
122
|
}
|
|
87
123
|
else {
|
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.11",
|
|
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
|
});
|
|
@@ -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
|
|
|
@@ -45,10 +45,25 @@ export function teamAutoProjectDir(repoId: string): string {
|
|
|
45
45
|
* Git operations for TeamAuto. Authentication uses the device-flow token
|
|
46
46
|
* inline in the remote URL (x-access-token basic auth) - proven to survive
|
|
47
47
|
* GitHub's smart-HTTP redirects where extraheader injection does not. The
|
|
48
|
-
* token never touches disk:
|
|
49
|
-
*
|
|
48
|
+
* token never touches disk: fetch/push rewrite the URL per invocation, and
|
|
49
|
+
* the one command that DOES store a URL (the initial clone) has its origin
|
|
50
|
+
* remote rewritten to the clean https URL right afterwards (ClawHub security
|
|
51
|
+
* review 2026.11.10). Every git error is redacted before it can reach a log,
|
|
52
|
+
* the store or a status response.
|
|
50
53
|
*/
|
|
51
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Strip GitHub credentials from anything derived from git output: inline
|
|
57
|
+
* x-access-token userinfo and raw token shapes (gho_/ghp_..., github_pat_...).
|
|
58
|
+
* Exported for tests; applied by run() to every failure message.
|
|
59
|
+
*/
|
|
60
|
+
export function redactGitSecrets(text: string): string {
|
|
61
|
+
return text
|
|
62
|
+
// Drop the whole userinfo so no "user:secret@" shape survives.
|
|
63
|
+
.replace(/x-access-token:[^@\s/]+@/gi, "[REDACTED]@")
|
|
64
|
+
.replace(/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/g, "[REDACTED]");
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
function gitEnv(): Record<string, string> {
|
|
53
68
|
return {
|
|
54
69
|
...process.env,
|
|
@@ -59,13 +74,27 @@ function gitEnv(): Record<string, string> {
|
|
|
59
74
|
}
|
|
60
75
|
|
|
61
76
|
async function run(args: string[], cwd?: string): Promise<string> {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
try {
|
|
78
|
+
const { stdout } = await exec("git", args, {
|
|
79
|
+
cwd,
|
|
80
|
+
env: gitEnv(),
|
|
81
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
82
|
+
timeout: 120_000,
|
|
83
|
+
});
|
|
84
|
+
return stdout;
|
|
85
|
+
} catch (err) {
|
|
86
|
+
// git echoes the failing URL on stderr (the inline token userinfo ends
|
|
87
|
+
// up in the message), and callers persist error messages into the store
|
|
88
|
+
// and status responses. Redact before the error leaves this module.
|
|
89
|
+
if (err instanceof Error) {
|
|
90
|
+
err.message = redactGitSecrets(err.message);
|
|
91
|
+
const withStderr = err as Error & { stderr?: unknown };
|
|
92
|
+
if (typeof withStderr.stderr === "string") {
|
|
93
|
+
withStderr.stderr = redactGitSecrets(withStderr.stderr);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
69
98
|
}
|
|
70
99
|
|
|
71
100
|
export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: string) => void }) {
|
|
@@ -75,6 +104,11 @@ export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: stri
|
|
|
75
104
|
return `https://x-access-token:${token}@${clean}.git`;
|
|
76
105
|
}
|
|
77
106
|
|
|
107
|
+
/** The token-less https URL that is safe to persist in .git/config. */
|
|
108
|
+
function cleanUrl(cloneUrl: string): string {
|
|
109
|
+
return `https://${cloneUrl.replace(/^https:\/\//, "").replace(/\.git$/, "")}.git`;
|
|
110
|
+
}
|
|
111
|
+
|
|
78
112
|
async function repoDir(repoId: string): Promise<string> {
|
|
79
113
|
const { reposRoot, legacyReposRoot } = resolveTeamAutoPaths();
|
|
80
114
|
await fs.mkdir(reposRoot, { recursive: true });
|
|
@@ -115,6 +149,9 @@ export function createRepoSync(auth: GithubAuthManager, logger: { warn: (m: stri
|
|
|
115
149
|
if (!exists) {
|
|
116
150
|
const authed = await tokenizedUrl(cloneUrl);
|
|
117
151
|
await run(["clone", "--filter=blob:none", "--no-checkout", authed, dir]);
|
|
152
|
+
// `git clone <url>` persists <url> as the origin remote - rewrite it to
|
|
153
|
+
// the clean https URL so the token never lands in .git/config.
|
|
154
|
+
await run(["remote", "set-url", "origin", cleanUrl(cloneUrl)], dir);
|
|
118
155
|
await run(["checkout", defaultBranch], dir);
|
|
119
156
|
} else {
|
|
120
157
|
const authed = await tokenizedUrl(cloneUrl);
|