co-maintainer 0.6.8 → 0.6.9
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/package.json +1 -1
- package/dist/src/cli/commands/serve.js +6 -0
- package/dist/src/cli/commands/set.js +19 -0
- package/dist/src/cli/review_github.js +6 -2
- package/dist/src/cli/review_result.js +6 -5
- package/dist/src/pr/checkout.js +14 -5
- package/dist/src/pr/codegraph_tools.js +5 -3
- package/dist/src/remote/client.js +14 -4
- package/dist/src/remote/server/body.d.ts +11 -0
- package/dist/src/remote/server/body.js +14 -5
- package/dist/src/server/app.js +5 -6
- package/dist/src/server/http.js +5 -0
- package/dist/src/server/pages/router.js +12 -2
- package/dist/src/server/pages/settings.js +1 -1
- package/dist/src/server/webhook/index.js +16 -6
- package/dist/src/services/jobs.js +8 -3
- package/dist/src/store/sessions.d.ts +3 -0
- package/dist/src/store/sessions.js +5 -0
- package/dist/src/util/runtime.js +7 -0
- package/dist/src/util/sanitize.d.ts +6 -0
- package/dist/src/util/sanitize.js +10 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import { startRemakeScheduler, stopRemakeScheduler, } from "../../services/remak
|
|
|
12
12
|
import { registerRemoteReviewHandler } from "../../services/remote_review.js";
|
|
13
13
|
import { startRemoteWatchdog } from "../../remote/server/sessions.js";
|
|
14
14
|
import { passwordProblem } from "../../util/password.js";
|
|
15
|
+
import { deleteAllSessions } from "../../store/sessions.js";
|
|
15
16
|
import { serveHttp } from "../../server/http.js";
|
|
16
17
|
import { currentPlatform, getEnv } from "../../util/runtime.js";
|
|
17
18
|
import { die } from "../error.js";
|
|
@@ -159,6 +160,11 @@ export async function runServe(args) {
|
|
|
159
160
|
console.log(`[serve] warning: ${warning}`);
|
|
160
161
|
await openAppDb();
|
|
161
162
|
console.log(`[serve] app.db ready at ${appDbPath()}`);
|
|
163
|
+
if (args.some((arg) => arg.startsWith("--password="))) {
|
|
164
|
+
// A password reset on the command line revokes every existing session, so a
|
|
165
|
+
// leaked cookie cannot outlive it.
|
|
166
|
+
deleteAllSessions();
|
|
167
|
+
}
|
|
162
168
|
const fromCli = await discoverCliRepos();
|
|
163
169
|
if (fromCli.length > 0) {
|
|
164
170
|
console.log(`[serve] added ${fromCli.length} repositor${fromCli.length === 1 ? "y" : "ies"} built from the CLI: ${fromCli.join(", ")}`);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { readConfig, configPath, savedKeyProvider, writeRepoConfig, writeUserConfig, } from "../../config.js";
|
|
2
2
|
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../../review/system_prompt.js";
|
|
3
3
|
import { hashPassword, passwordProblem } from "../../util/password.js";
|
|
4
|
+
import { deleteAllSessions } from "../../store/sessions.js";
|
|
5
|
+
import { appDbPath, closeAppDb, openAppDb } from "../../store/app_db.js";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
4
7
|
import { readTextFile } from "../../util/runtime.js";
|
|
5
8
|
import { verifyAnthropic, verifyOpenAi, verifyOpenRouter, } from "../../ai/verify.js";
|
|
6
9
|
import { verifyOpenCode } from "../../ai/opencode.js";
|
|
@@ -351,6 +354,22 @@ export async function runSet(args) {
|
|
|
351
354
|
}
|
|
352
355
|
}
|
|
353
356
|
await writeUserConfig(patch);
|
|
357
|
+
// A changed password, allowed user, or sign-in method must not leave old
|
|
358
|
+
// dashboard sessions valid. Only touch the session store if it already
|
|
359
|
+
// exists (a server has run); never create it just to clear it.
|
|
360
|
+
const credentialChanged = patch.dashboardPasswordHash !== undefined ||
|
|
361
|
+
patch.passwordAuthDisabled !== undefined ||
|
|
362
|
+
patch.githubAuthEnabled !== undefined ||
|
|
363
|
+
patch.githubOAuthAllowedUser !== undefined;
|
|
364
|
+
if (credentialChanged && existsSync(appDbPath())) {
|
|
365
|
+
await openAppDb();
|
|
366
|
+
try {
|
|
367
|
+
deleteAllSessions();
|
|
368
|
+
}
|
|
369
|
+
finally {
|
|
370
|
+
await closeAppDb();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
354
373
|
const summary = Object.entries(patch).map(([key, value]) => value === undefined
|
|
355
374
|
? `${key} (unset)`
|
|
356
375
|
: `${key}=${secretFields.has(key) ? "•".repeat(8) : value}`);
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* end the step's commands. Every finding is one escaped line, and nothing else
|
|
11
11
|
* from the review is printed to stdout in this mode. */
|
|
12
12
|
import { appendFileSync } from "node:fs";
|
|
13
|
+
import { stripControlChars } from "../util/sanitize.js";
|
|
13
14
|
import { formatRunSummary } from "../util/run_summary.js";
|
|
14
15
|
import { humanShortTitle, sortHumanFindings, } from "./review_result.js";
|
|
15
16
|
/** GitHub shows at most this many error and this many warning annotations per
|
|
@@ -91,7 +92,7 @@ export function githubSummary(input) {
|
|
|
91
92
|
const text = [short, row.body.split("\n")[0] ?? ""]
|
|
92
93
|
.filter(Boolean)
|
|
93
94
|
.join(": ");
|
|
94
|
-
lines.push(`| ${cell(row.severity, 10)}${row.blocking ? " (blocking)" : ""} | ${row.state} | ${where(row)} | ${cell(text || row.title)} |`);
|
|
95
|
+
lines.push(`| ${cell(row.severity, 10)}${row.blocking ? " (blocking)" : ""} | ${stripControlChars(row.state)} | ${where(row)} | ${cell(text || row.title)} |`);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
lines.push("", `**Summary:** ${rows.filter((r) => r.state === "new").length} new · ${rows.filter((r) => r.state === "open").length} open · ${closed} closed · ${blocking} blocking`);
|
|
@@ -121,9 +122,12 @@ export function emitGithubOutput(input) {
|
|
|
121
122
|
* printed on stderr, and the runner reads workflow commands from stderr too.
|
|
122
123
|
* A line that would start one is given a prefix so it stays plain text. */
|
|
123
124
|
export function neutralizeCommands(text) {
|
|
124
|
-
// The runner also ends a line at a bare carriage return.
|
|
125
|
+
// The runner also ends a line at a bare carriage return. Split first so a
|
|
126
|
+
// `\r` still ends a line, then strip any other control characters (ESC/OSC)
|
|
127
|
+
// from each line before neutralising a leading `::` workflow command.
|
|
125
128
|
return text
|
|
126
129
|
.split(/\r\n|\r|\n/)
|
|
130
|
+
.map((line) => stripControlChars(line))
|
|
127
131
|
.map((line) => (line.trimStart().startsWith("::") ? `[log] ${line}` : line))
|
|
128
132
|
.join("\n");
|
|
129
133
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseFindings } from "../pr/findings.js";
|
|
2
2
|
import { readSuggestion, stripSuggestion } from "../pr/suggestion.js";
|
|
3
|
+
import { stripControlChars } from "../util/sanitize.js";
|
|
3
4
|
import { anchorTextFromPatch, } from "../review/carry_over.js";
|
|
4
5
|
import { DEFAULT_REVIEW_BLOCKING, isBlocking, } from "../review/blocking.js";
|
|
5
6
|
import { humanCopy } from "../services/review.js";
|
|
@@ -219,23 +220,23 @@ export function formatHumanReview(input) {
|
|
|
219
220
|
any = true;
|
|
220
221
|
lines.push(`${group.label} (${rows.length})`);
|
|
221
222
|
for (const row of rows) {
|
|
222
|
-
const loc = humanLocation(row);
|
|
223
|
+
const loc = stripControlChars(humanLocation(row));
|
|
223
224
|
const label = `[${row.severity} · ${row.blocking ? "blocking" : "non-blocking"}]`;
|
|
224
|
-
const short = humanShortTitle(row);
|
|
225
|
+
const short = stripControlChars(humanShortTitle(row));
|
|
225
226
|
const head = `${group.bullet} ${loc} ${label}${short ? ` \`${short}\`` : ""}`;
|
|
226
227
|
lines.push(` ${head}`);
|
|
227
228
|
if (row.state === "closed")
|
|
228
229
|
continue;
|
|
229
230
|
if (row.body) {
|
|
230
231
|
for (const part of row.body.split("\n"))
|
|
231
|
-
lines.push(` ${part}`);
|
|
232
|
+
lines.push(` ${stripControlChars(part)}`);
|
|
232
233
|
}
|
|
233
234
|
if (row.suggestion && row.path) {
|
|
234
235
|
const { lineFrom, lineTo, text } = row.suggestion;
|
|
235
|
-
lines.push(` Suggested replacement for ${row.path}:${lineFrom}${lineTo !== lineFrom ? `-${lineTo}` : ""}`);
|
|
236
|
+
lines.push(` Suggested replacement for ${stripControlChars(row.path)}:${lineFrom}${lineTo !== lineFrom ? `-${lineTo}` : ""}`);
|
|
236
237
|
lines.push(" ```");
|
|
237
238
|
for (const part of text.split("\n"))
|
|
238
|
-
lines.push(` ${part}`);
|
|
239
|
+
lines.push(` ${stripControlChars(part)}`);
|
|
239
240
|
lines.push(" ```");
|
|
240
241
|
}
|
|
241
242
|
}
|
package/dist/src/pr/checkout.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { cloneDir, worktreeDir } from "../config.js";
|
|
2
2
|
import { log } from "../util/log.js";
|
|
3
3
|
import { withKeyedLock } from "../util/keyed_lock.js";
|
|
4
|
-
import { commandOutput,
|
|
4
|
+
import { commandOutput, stat } from "../util/runtime.js";
|
|
5
5
|
export function withCloneLock(repo, fn) {
|
|
6
6
|
return withKeyedLock(`clone:${repo}`, fn);
|
|
7
7
|
}
|
|
8
8
|
export async function runCommand(command, args, cwd) {
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
// Spawn the executable directly, never through `cmd /c`. git is a real .exe
|
|
10
|
+
// on Windows, so cmd is unnecessary, and routing a pull request's file paths
|
|
11
|
+
// through cmd let a path like `x&evil` run as a second command. `runtime.ts`
|
|
12
|
+
// also sets NoDefaultCurrentDirectoryInExePath=1 so the working directory is
|
|
13
|
+
// never searched for the executable.
|
|
14
|
+
const output = await commandOutput(command, {
|
|
15
|
+
args,
|
|
13
16
|
cwd,
|
|
14
17
|
stdout: "piped",
|
|
15
18
|
stderr: "piped",
|
|
@@ -38,6 +41,8 @@ async function cloneInto(repo, dir, run) {
|
|
|
38
41
|
const result = await run("git", [
|
|
39
42
|
"-c",
|
|
40
43
|
"core.longpaths=true",
|
|
44
|
+
"-c",
|
|
45
|
+
"core.symlinks=false",
|
|
41
46
|
"clone",
|
|
42
47
|
"--filter=blob:none",
|
|
43
48
|
`https://github.com/${repo}`,
|
|
@@ -54,6 +59,10 @@ async function cloneInto(repo, dir, run) {
|
|
|
54
59
|
`repository scope and falls back to the diff only` +
|
|
55
60
|
(firstLine ? `: ${firstLine}` : ""));
|
|
56
61
|
}
|
|
62
|
+
// A pull request may ship symlinks; without this a codegraph tool could read
|
|
63
|
+
// through one to a file outside the tree. Persist it in the clone so every
|
|
64
|
+
// worktree checkout writes symlinks as plain files instead of following them.
|
|
65
|
+
await run("git", ["config", "core.symlinks", "false"], dir);
|
|
57
66
|
log("checkout", `cloned in ${((performance.now() - started) / 1000).toFixed(1)}s`);
|
|
58
67
|
return dir;
|
|
59
68
|
}
|
|
@@ -185,9 +185,11 @@ export function codegraphTools(binary, worktree, runner = createCodegraphRunner(
|
|
|
185
185
|
return Promise.resolve("codegraph-node requires 'name' or 'file'.");
|
|
186
186
|
}
|
|
187
187
|
if (name) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
// codegraph reads `name` as a file when it contains a slash, so hold
|
|
189
|
+
// it to the same in-repo check as `file`.
|
|
190
|
+
const nameErr = rejectEscapingPath(name);
|
|
191
|
+
if (nameErr)
|
|
192
|
+
return Promise.resolve(nameErr);
|
|
191
193
|
}
|
|
192
194
|
if (file) {
|
|
193
195
|
const pathErr = rejectEscapingPath(file);
|
|
@@ -5,6 +5,7 @@ import { formatHumanReview, humanFindingsFromJson, reviewExitCodeFromJsonFinding
|
|
|
5
5
|
import { baseUrl, die, readApiError, remoteFetch, remoteFromEnv, } from "./http.js";
|
|
6
6
|
import { readConfig, writeUserConfig } from "../config.js";
|
|
7
7
|
import { getEnv } from "../util/runtime.js";
|
|
8
|
+
import { stripControlChars } from "../util/sanitize.js";
|
|
8
9
|
import { prepareLocalCodegraph } from "../local/codegraph_prepare.js";
|
|
9
10
|
import { canPrompt } from "../tools/codegraph.js";
|
|
10
11
|
import { runRemoteToolCalls, toolHandlerMap, } from "./client_tools.js";
|
|
@@ -123,8 +124,9 @@ export async function runRemoteReview(cli) {
|
|
|
123
124
|
const hostKey = baseUrl(host);
|
|
124
125
|
const shown = config.remoteNoticeShownFor ?? [];
|
|
125
126
|
if (!shown.includes(hostKey) && !cli.json) {
|
|
126
|
-
console.error("Remote review sends your unpublished diff to the server you configured
|
|
127
|
-
"
|
|
127
|
+
console.error("Remote review sends your unpublished diff to the server you configured, " +
|
|
128
|
+
"and the server may ask it to read other files in this repository while " +
|
|
129
|
+
"reviewing. Use a host you trust.");
|
|
128
130
|
await writeUserConfig({
|
|
129
131
|
remoteNoticeShownFor: [...shown, hostKey],
|
|
130
132
|
});
|
|
@@ -185,6 +187,10 @@ export async function runRemoteReview(cli) {
|
|
|
185
187
|
const { jobId } = (await submit.json());
|
|
186
188
|
let afterLogSeq = 0;
|
|
187
189
|
let toolResults = [];
|
|
190
|
+
let toolCallsRun = 0;
|
|
191
|
+
// A trustworthy server drives at most a few tool rounds; cap the total so a
|
|
192
|
+
// malicious one cannot make the client read its tree without limit.
|
|
193
|
+
const MAX_REMOTE_TOOL_CALLS = 200;
|
|
188
194
|
const intervalMs = hs.sync.intervalSeconds * 1000;
|
|
189
195
|
while (true) {
|
|
190
196
|
const sync = await remoteFetch(host, token, `/api/remote/reviews/${jobId}/sync`, {
|
|
@@ -205,10 +211,14 @@ export async function runRemoteReview(cli) {
|
|
|
205
211
|
if (!cli.json) {
|
|
206
212
|
console.error(cli.output === "github"
|
|
207
213
|
? neutralizeCommands(line.message)
|
|
208
|
-
: line.message);
|
|
214
|
+
: stripControlChars(line.message));
|
|
209
215
|
}
|
|
210
216
|
}
|
|
211
217
|
if (payload.toolCalls?.length) {
|
|
218
|
+
toolCallsRun += payload.toolCalls.length;
|
|
219
|
+
if (toolCallsRun > MAX_REMOTE_TOOL_CALLS) {
|
|
220
|
+
die("remote_tool_calls_exceeded", `the server asked for more than ${MAX_REMOTE_TOOL_CALLS} tool calls`);
|
|
221
|
+
}
|
|
212
222
|
toolResults = await runRemoteToolCalls(payload.toolCalls, localTools);
|
|
213
223
|
continue;
|
|
214
224
|
}
|
|
@@ -265,7 +275,7 @@ export async function runRemoteReview(cli) {
|
|
|
265
275
|
return;
|
|
266
276
|
}
|
|
267
277
|
if (payload.status === "failed" || payload.status === "canceled") {
|
|
268
|
-
die(payload.abort?.reason ?? "remote_failed", payload.abort?.message ?? "Remote review did not complete.");
|
|
278
|
+
die(stripControlChars(payload.abort?.reason ?? "remote_failed"), stripControlChars(payload.abort?.message ?? "Remote review did not complete."));
|
|
269
279
|
}
|
|
270
280
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
271
281
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
/** Bounded request body read (bytes, streaming). */
|
|
2
|
+
export type BoundedBytesResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
bytes: Uint8Array;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
reason: "too_large";
|
|
8
|
+
};
|
|
2
9
|
export type BoundedBodyResult = {
|
|
3
10
|
ok: true;
|
|
4
11
|
text: string;
|
|
@@ -6,6 +13,10 @@ export type BoundedBodyResult = {
|
|
|
6
13
|
ok: false;
|
|
7
14
|
reason: "too_large" | "empty";
|
|
8
15
|
};
|
|
16
|
+
/** Reads the raw body, streaming, and refuses once more than `maxBytes` have
|
|
17
|
+
* arrived — this holds with no Content-Length (chunked) too. The caller gets
|
|
18
|
+
* the exact bytes, which the webhook HMAC needs. */
|
|
19
|
+
export declare function readBoundedBytes(request: Request, maxBytes: number): Promise<BoundedBytesResult>;
|
|
9
20
|
export declare function readBoundedUtf8(request: Request, maxBytes: number): Promise<BoundedBodyResult>;
|
|
10
21
|
export declare function readBoundedJson(request: Request, maxBytes: number): Promise<{
|
|
11
22
|
ok: true;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/** Bounded request body read (bytes, streaming). */
|
|
2
|
-
|
|
2
|
+
/** Reads the raw body, streaming, and refuses once more than `maxBytes` have
|
|
3
|
+
* arrived — this holds with no Content-Length (chunked) too. The caller gets
|
|
4
|
+
* the exact bytes, which the webhook HMAC needs. */
|
|
5
|
+
export async function readBoundedBytes(request, maxBytes) {
|
|
3
6
|
const lengthHeader = request.headers.get("content-length");
|
|
4
7
|
if (lengthHeader !== null) {
|
|
5
8
|
const declared = Number(lengthHeader);
|
|
@@ -9,7 +12,7 @@ export async function readBoundedUtf8(request, maxBytes) {
|
|
|
9
12
|
}
|
|
10
13
|
const stream = request.body;
|
|
11
14
|
if (!stream)
|
|
12
|
-
return { ok: true,
|
|
15
|
+
return { ok: true, bytes: new Uint8Array(0) };
|
|
13
16
|
const reader = stream.getReader();
|
|
14
17
|
const chunks = [];
|
|
15
18
|
let total = 0;
|
|
@@ -31,15 +34,21 @@ export async function readBoundedUtf8(request, maxBytes) {
|
|
|
31
34
|
finally {
|
|
32
35
|
reader.releaseLock();
|
|
33
36
|
}
|
|
34
|
-
if (total === 0)
|
|
35
|
-
return { ok: true, text: "" };
|
|
36
37
|
const merged = new Uint8Array(total);
|
|
37
38
|
let offset = 0;
|
|
38
39
|
for (const chunk of chunks) {
|
|
39
40
|
merged.set(chunk, offset);
|
|
40
41
|
offset += chunk.length;
|
|
41
42
|
}
|
|
42
|
-
return { ok: true,
|
|
43
|
+
return { ok: true, bytes: merged };
|
|
44
|
+
}
|
|
45
|
+
export async function readBoundedUtf8(request, maxBytes) {
|
|
46
|
+
const body = await readBoundedBytes(request, maxBytes);
|
|
47
|
+
if (!body.ok)
|
|
48
|
+
return { ok: false, reason: "too_large" };
|
|
49
|
+
if (body.bytes.length === 0)
|
|
50
|
+
return { ok: true, text: "" };
|
|
51
|
+
return { ok: true, text: new TextDecoder().decode(body.bytes) };
|
|
43
52
|
}
|
|
44
53
|
export async function readBoundedJson(request, maxBytes) {
|
|
45
54
|
const body = await readBoundedUtf8(request, maxBytes);
|
package/dist/src/server/app.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* with a plain `Request`. */
|
|
3
3
|
import { VERSION } from "../version.js";
|
|
4
4
|
import { errorResponse } from "./errors.js";
|
|
5
|
+
import { readBoundedJson } from "../remote/server/body.js";
|
|
5
6
|
import { hasCsrfHeader, login, logout, readSessionToken, sessionCookieHeader, verifySession, } from "./auth.js";
|
|
6
7
|
import { memoryPasswordStore } from "./auth.js";
|
|
7
8
|
import { clientAddress, forwardedHttps } from "./proxy_headers.js";
|
|
@@ -43,13 +44,11 @@ async function handleLogin(request, deps, passwords, ip) {
|
|
|
43
44
|
if (deps.auth?.password === false) {
|
|
44
45
|
return errorResponse(403, "password_disabled", "password sign-in is disabled");
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return errorResponse(400, "bad_request", "expected a JSON body");
|
|
47
|
+
const parsed = await readBoundedJson(request, 64 * 1024);
|
|
48
|
+
if (!parsed.ok) {
|
|
49
|
+
return errorResponse(parsed.status, parsed.code, parsed.message);
|
|
52
50
|
}
|
|
51
|
+
const body = parsed.value;
|
|
53
52
|
const result = await login(String(body.password ?? ""), passwords, ip);
|
|
54
53
|
if (!result)
|
|
55
54
|
return errorResponse(401, "unauthorized", "wrong password");
|
package/dist/src/server/http.js
CHANGED
|
@@ -103,6 +103,11 @@ export function serveHttp(app, port) {
|
|
|
103
103
|
server.once("listening", () => resolve());
|
|
104
104
|
server.once("error", reject);
|
|
105
105
|
});
|
|
106
|
+
// Slow-loris defence: cap how long a client may take to send headers and
|
|
107
|
+
// the full request. Responses (SSE) are unaffected — those are measured on
|
|
108
|
+
// the response side, not here.
|
|
109
|
+
server.headersTimeout = 20_000;
|
|
110
|
+
server.requestTimeout = 120_000;
|
|
106
111
|
server.listen(port);
|
|
107
112
|
return {
|
|
108
113
|
port,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { clearOauthStateCookieHeader, clearSessionCookieHeader, createSession, login, logout, oauthStateCookieHeader, randomToken, readOauthState, readSessionToken, sessionCookieHeader, verifySession, } from "../auth.js";
|
|
2
2
|
import { githubAuthorizeUrl, githubLoginFromCode } from "../../github/oauth.js";
|
|
3
|
+
import { readBoundedUtf8 } from "../../remote/server/body.js";
|
|
3
4
|
import { handleClient, handleLogo, handleStyles } from "../assets.js";
|
|
4
5
|
import { activityFeed, listReposForHome, prDetail, repoKnowledge, RepoNotFound, repoOverview, repoPulls, repoRemoteReviews, runningJobs, skippedDeliveries, statsForRange, } from "../../services/dashboard.js";
|
|
5
6
|
import { escapeHtml, html, notFound } from "./layout.js";
|
|
@@ -331,8 +332,16 @@ async function sessionOf(request) {
|
|
|
331
332
|
return await verifySession(token);
|
|
332
333
|
}
|
|
333
334
|
function safeNext(value) {
|
|
335
|
+
// A path-only redirect. It must start with a single "/", and may not hold a
|
|
336
|
+
// backslash (browsers read "/\host" as "//host") or a control character (a
|
|
337
|
+
// tab or newline is stripped, turning "/\t/host" into "//host") — both would
|
|
338
|
+
// send the browser to another origin.
|
|
334
339
|
if (!value || !value.startsWith("/") || value.startsWith("//"))
|
|
335
340
|
return "/";
|
|
341
|
+
for (let i = 0; i < value.length; i++) {
|
|
342
|
+
if (value.charCodeAt(i) <= 0x1f || value[i] === "\\")
|
|
343
|
+
return "/";
|
|
344
|
+
}
|
|
336
345
|
return value;
|
|
337
346
|
}
|
|
338
347
|
/** The externally visible origin. Behind a trusted proxy the browser reached
|
|
@@ -426,7 +435,8 @@ async function finishAppManifest(request, url) {
|
|
|
426
435
|
return Response.redirect(installUrl, 303);
|
|
427
436
|
}
|
|
428
437
|
async function handleLoginForm(request, deps, ip, auth) {
|
|
429
|
-
const
|
|
438
|
+
const bounded = await readBoundedUtf8(request, 64 * 1024);
|
|
439
|
+
const form = new URLSearchParams(bounded.ok ? bounded.text : "");
|
|
430
440
|
const password = String(form.get("password") ?? "");
|
|
431
441
|
const next = safeNext(String(form.get("next") ?? "/"));
|
|
432
442
|
if (!auth.password) {
|
|
@@ -487,7 +497,7 @@ async function handleGithubCallback(request, url, githubOAuth, deps) {
|
|
|
487
497
|
return new Response(null, {
|
|
488
498
|
status: 303,
|
|
489
499
|
headers: {
|
|
490
|
-
location: saved.next,
|
|
500
|
+
location: safeNext(saved.next),
|
|
491
501
|
"set-cookie": sessionCookieHeader(result.token, Boolean(deps.secureCookie)),
|
|
492
502
|
},
|
|
493
503
|
});
|
|
@@ -225,7 +225,7 @@ function remoteCard(config) {
|
|
|
225
225
|
${skSlot()}
|
|
226
226
|
<div class="hd"><h2>Remote review tokens</h2></div>
|
|
227
227
|
<div class="bd">
|
|
228
|
-
<p class="muted" style="margin:0 0 16px">Bearer tokens for <code>co-maintainer review --remote</code>. The secret is shown once when created.</p>
|
|
228
|
+
<p class="muted" style="margin:0 0 16px">Bearer tokens for <code>co-maintainer review --remote</code>. The secret is shown once when created. Each token can review and read the guides of <strong>every active repository</strong> on this server, so treat a token as server-wide and revoke a leaked one.</p>
|
|
229
229
|
<div id="remote-token-secret" class="secret" hidden></div>
|
|
230
230
|
<div id="remote-token-list" class="muted">Loading…</div>
|
|
231
231
|
<div class="two" style="max-width:none;margin-top:16px">
|
|
@@ -2,17 +2,27 @@ import { readConfig } from "../../config.js";
|
|
|
2
2
|
import { errorResponse } from "../errors.js";
|
|
3
3
|
import { hasDelivery, recordDelivery } from "../../store/deliveries.js";
|
|
4
4
|
import { dispatchGithubEvent } from "../../services/webhook.js";
|
|
5
|
+
import { readBoundedBytes } from "../../remote/server/body.js";
|
|
5
6
|
import { verifySignature } from "./signature.js";
|
|
7
|
+
/** GitHub caps a webhook payload at 25 MB; nothing larger is genuine. */
|
|
8
|
+
const WEBHOOK_MAX_BODY_BYTES = 25 * 1024 * 1024;
|
|
6
9
|
function json(status, body) {
|
|
7
10
|
return Response.json(body, { status });
|
|
8
11
|
}
|
|
9
12
|
export async function handleWebhookRequest(request, secret) {
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const bounded = await readBoundedBytes(request, WEBHOOK_MAX_BODY_BYTES);
|
|
14
|
+
if (!bounded.ok) {
|
|
15
|
+
return errorResponse(413, "payload_too_large", "request body too large");
|
|
16
|
+
}
|
|
17
|
+
const raw = bounded.bytes;
|
|
18
|
+
// Fail closed: with no secret configured there is no way to tell a real
|
|
19
|
+
// delivery from a forged one, so reject rather than trust the payload.
|
|
20
|
+
if (!secret) {
|
|
21
|
+
return errorResponse(401, "unauthorized", "webhook secret is not configured, so deliveries cannot be verified");
|
|
22
|
+
}
|
|
23
|
+
const header = request.headers.get("x-hub-signature-256");
|
|
24
|
+
if (!(await verifySignature(secret, raw, header))) {
|
|
25
|
+
return errorResponse(401, "unauthorized", "bad webhook signature");
|
|
16
26
|
}
|
|
17
27
|
const deliveryId = request.headers.get("x-github-delivery");
|
|
18
28
|
const event = request.headers.get("x-github-event");
|
|
@@ -6,6 +6,10 @@ import { abortQueuedRemoteReviewRow } from "./remote_review_abort.js";
|
|
|
6
6
|
import { getReviewByJobId } from "../store/reviews.js";
|
|
7
7
|
import { withRateLimitJob } from "./rate_limit.js";
|
|
8
8
|
const handlers = new Map();
|
|
9
|
+
// Default caps so an unconfigured server is not a free-for-all. An operator can
|
|
10
|
+
// still set 0 in config to opt back into unlimited.
|
|
11
|
+
const DEFAULT_MAX_CONCURRENT_JOBS = 4;
|
|
12
|
+
const DEFAULT_MAX_REMOTE_REVIEWS_PER_TOKEN = 2;
|
|
9
13
|
export function registerHandler(type, handler) {
|
|
10
14
|
handlers.set(type, handler);
|
|
11
15
|
}
|
|
@@ -112,7 +116,8 @@ function runningRemoteReviewsPerToken() {
|
|
|
112
116
|
}
|
|
113
117
|
function claimNextEligible() {
|
|
114
118
|
const config = readConfig();
|
|
115
|
-
const perTokenLimit = config.maxConcurrentRemoteReviewsPerToken
|
|
119
|
+
const perTokenLimit = config.maxConcurrentRemoteReviewsPerToken ??
|
|
120
|
+
DEFAULT_MAX_REMOTE_REVIEWS_PER_TOKEN;
|
|
116
121
|
const remoteRunning = perTokenLimit
|
|
117
122
|
? runningRemoteReviewsPerToken()
|
|
118
123
|
: undefined;
|
|
@@ -145,7 +150,7 @@ function claimNextEligible() {
|
|
|
145
150
|
return undefined;
|
|
146
151
|
}
|
|
147
152
|
export async function claimAndRun() {
|
|
148
|
-
const limit = readConfig().maxConcurrentJobs;
|
|
153
|
+
const limit = readConfig().maxConcurrentJobs ?? DEFAULT_MAX_CONCURRENT_JOBS;
|
|
149
154
|
if (limit && inFlight.size >= limit)
|
|
150
155
|
return false;
|
|
151
156
|
const job = claimNextEligible();
|
|
@@ -159,7 +164,7 @@ export async function claimAndRun() {
|
|
|
159
164
|
const inFlight = new Set();
|
|
160
165
|
let workerTimer;
|
|
161
166
|
function tick() {
|
|
162
|
-
const limit = readConfig().maxConcurrentJobs;
|
|
167
|
+
const limit = readConfig().maxConcurrentJobs ?? DEFAULT_MAX_CONCURRENT_JOBS;
|
|
163
168
|
while (!limit || inFlight.size < limit) {
|
|
164
169
|
const job = claimNextEligible();
|
|
165
170
|
if (!job)
|
|
@@ -7,3 +7,6 @@ export declare function getSession(tokenHash: string): SessionRow | undefined;
|
|
|
7
7
|
export declare function deleteSession(tokenHash: string): void;
|
|
8
8
|
export declare function deleteExpiredSessions(): void;
|
|
9
9
|
export declare function deleteOtherSessions(keepTokenHash: string): void;
|
|
10
|
+
/** Drop every dashboard session. Used when a credential is reset from the CLI,
|
|
11
|
+
* so a leaked cookie cannot outlive the password it was issued under. */
|
|
12
|
+
export declare function deleteAllSessions(): void;
|
|
@@ -37,3 +37,8 @@ export function deleteOtherSessions(keepTokenHash) {
|
|
|
37
37
|
.prepare(`DELETE FROM sessions WHERE token_hash != ?`)
|
|
38
38
|
.run(keepTokenHash);
|
|
39
39
|
}
|
|
40
|
+
/** Drop every dashboard session. Used when a credential is reset from the CLI,
|
|
41
|
+
* so a leaked cookie cannot outlive the password it was issued under. */
|
|
42
|
+
export function deleteAllSessions() {
|
|
43
|
+
getAppDb().prepare(`DELETE FROM sessions`).run();
|
|
44
|
+
}
|
package/dist/src/util/runtime.js
CHANGED
|
@@ -14,6 +14,13 @@ import { join } from "node:path";
|
|
|
14
14
|
export function isWindows() {
|
|
15
15
|
return process.platform === "win32";
|
|
16
16
|
}
|
|
17
|
+
// Windows only: keep the current working directory out of the executable search
|
|
18
|
+
// path, so a `git.cmd` / `gh.exe` committed in a reviewed repository cannot run
|
|
19
|
+
// in place of the real tool. Set once at module load — before any child spawn —
|
|
20
|
+
// and inherited by every child process we start.
|
|
21
|
+
if (isWindows() && !process.env.NoDefaultCurrentDirectoryInExePath) {
|
|
22
|
+
process.env.NoDefaultCurrentDirectoryInExePath = "1";
|
|
23
|
+
}
|
|
17
24
|
/** The current OS in the vocabulary the config paths already used under Deno
|
|
18
25
|
* (`"windows"`, not Node's `"win32"`). */
|
|
19
26
|
export function currentPlatform() {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Strip C0/C1 control characters, keeping tab and newline. Run this over any
|
|
2
|
+
* string that came from the model or a remote server before it is printed to a
|
|
3
|
+
* terminal or a CI log, so it cannot inject ANSI/OSC escape sequences (cursor
|
|
4
|
+
* moves, screen clears, OSC 52 clipboard writes, OSC 8 disguised links) or a
|
|
5
|
+
* bare carriage return that overwrites the line. */
|
|
6
|
+
export declare function stripControlChars(value: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Strip C0/C1 control characters, keeping tab and newline. Run this over any
|
|
2
|
+
* string that came from the model or a remote server before it is printed to a
|
|
3
|
+
* terminal or a CI log, so it cannot inject ANSI/OSC escape sequences (cursor
|
|
4
|
+
* moves, screen clears, OSC 52 clipboard writes, OSC 8 disguised links) or a
|
|
5
|
+
* bare carriage return that overwrites the line. */
|
|
6
|
+
export function stripControlChars(value) {
|
|
7
|
+
// Dropped: 00-08, 0B-1F (so \r too), DEL 7F, and C1 80-9F. Kept: \t and \n.
|
|
8
|
+
// eslint-disable-next-line no-control-regex -- matching control chars is the point
|
|
9
|
+
return value.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, "");
|
|
10
|
+
}
|