Skip to content

Commit 40d7704

Browse files
committed
fix(dashboard): hide exact-review server details
1 parent a22ff98 commit 40d7704

5 files changed

Lines changed: 155 additions & 107 deletions

File tree

‎dashboard/worker.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
githubAppJsonAsPlainError as githubAppJson,
2929
signGithubAppJwt,
3030
} from "./github-api.ts";
31-
import { sanitizedServerError } from "./error-safety.ts";
3231
import {
3332
HEALTH_HISTORY_RETENTION_DAYS,
3433
HEALTH_HISTORY_SAMPLE_MS,
@@ -4437,10 +4436,12 @@ async function exactReviewQueueRequest(env, path, request?: Request) {
44374436
JSON.parse(responseBody);
44384437
return response;
44394438
} catch {
4440-
return json({ error: sanitizedServerError(responseBody) }, response.status);
4439+
console.error("exact_review_queue_malformed_server_response");
4440+
return json({ error: "exact_review_queue_unavailable" }, response.status);
44414441
}
4442-
} catch (error) {
4443-
return json({ error: sanitizedServerError(error) }, 500);
4442+
} catch {
4443+
console.error("exact_review_queue_request_failed");
4444+
return json({ error: "exact_review_queue_unavailable" }, 500);
44444445
}
44454446
}
44464447

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
# Exact-review Worker sanitized JSON error proof
1+
# Exact-review Worker safe JSON error proof
22

33
This proof starts the actual local Wrangler Worker and its ExactReviewQueue
44
Durable Object, then drives the signed internal
55
`/internal/exact-review/publications/list` route through the real Workers
66
Durable Object boundary. A proof-only entry module re-exports the production
77
`ExactReviewQueue` with its real SQLite `storage.sql.exec` wrapped so one
88
marked request fails the `SELECT item_key, item_json` state read with an
9-
error message carrying a planted GitHub token. The production route code,
10-
worker forwarding, HMAC verification, storage initialization, and every other
11-
request run unmodified.
9+
stack-bearing rejection string carrying a planted GitHub token and a synthetic
10+
internal file path. The production route code, worker forwarding, HMAC
11+
verification, storage initialization, and every other request run unmodified.
1212

1313
The scenario sends three identical-shape signed requests: a baseline list
1414
(expect 200), the marked failing request, and a recovery list (expect 200).
1515
The script detects whether the checked-out tree contains the fix and asserts
1616
accordingly:
1717

18-
- before (base tree): the injected Durable Object failure escapes the Worker,
19-
and the client receives a non-JSON 500 with no sanitized error contract; in
20-
the local dev runtime the error page also exposes the planted token to the
21-
client.
18+
- before (base tree): the Worker returns the stack-bearing rejection text in
19+
its JSON 500, including the synthetic internal file path.
2220
- after (fixed tree): the Durable Object still rejects so its transaction
23-
remains fail closed, while the Worker converts that rejected stub call into
24-
HTTP 500 with
21+
remains fail closed, while the Worker returns HTTP 500 with
2522
`content-type: application/json` and body
26-
`{"error":"injected sqlite read failure exposing GH_TOKEN=[REDACTED]"}`;
27-
the planted token never reaches the client.
23+
`{"error":"exact_review_queue_unavailable"}`. The planted token and internal
24+
path never reach the client, and the Worker records the bounded
25+
`exact_review_queue_request_failed` diagnostic event.
2826

2927
Run from the repository root of the tree under test:
3028

@@ -39,8 +37,6 @@ crabbox run \
3937
--artifact-glob '.artifacts/exact-review-do-json-errors/**'
4038
```
4139

42-
Limits: the before-mode HTML error page is the local dev runtime's rendering
43-
of the escaped exception; deployed workerd returns its generic internal-error
44-
response instead. The invariant proven is the Worker-facing failure contract:
45-
an escaped Durable Object rejection becomes a sanitized JSON 500 without
46-
changing the Durable Object transaction boundary.
40+
The invariant proven is the Worker-facing failure contract: a stack-bearing
41+
Durable Object rejection becomes a fixed JSON 500 without changing the Durable
42+
Object transaction boundary or losing the internal failure event.

‎docs/proof/exact-review-do-json-errors/run-proof.sh‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if [ -e "$output_dir" ]; then
3434
fi
3535
mkdir -p "$output_dir"
3636

37-
if grep -q 'sanitizedServerError(responseBody)' dashboard/worker.ts; then
37+
if grep -q 'exact_review_queue_request_failed' dashboard/worker.ts; then
3838
proof_mode=after
3939
else
4040
proof_mode=before
@@ -61,7 +61,11 @@ import baseWorker, {
6161
} from "./worker.ts";
6262
6363
const PROOF_FAILURE_MESSAGE =
64-
"injected sqlite read failure exposing GH_TOKEN=ghp_examplesecrettoken0123456789abcd";
64+
"injected sqlite read failure exposing private-marker-0123456789abcdef";
65+
const PROOF_FAILURE_STACK = [
66+
`Error: ${PROOF_FAILURE_MESSAGE}`,
67+
"at readQueue (file:///srv/clawsweeper-internal/exact-review-queue.ts:91:4)",
68+
].join("\n");
6569
6670
function bindingProxy(target: any, overrides: Record<PropertyKey, unknown>) {
6771
return new Proxy(target, {
@@ -81,7 +85,7 @@ export class ExactReviewQueue extends BaseExactReviewQueue {
8185
exec: (query: string, ...args: unknown[]) => {
8286
if (armedPattern && armedPattern.test(String(query))) {
8387
armedPattern = null;
84-
throw new Error(PROOF_FAILURE_MESSAGE);
88+
throw PROOF_FAILURE_STACK;
8589
}
8690
return realStorage.sql.exec(query, ...args);
8791
},
@@ -138,7 +142,8 @@ const mode = process.env.EXACT_REVIEW_DO_PROOF_MODE === "before" ? "before" : "a
138142
const headSha = String(process.env.EXACT_REVIEW_DO_PROOF_HEAD || "unknown");
139143
if (!origin || !secret) throw new Error("proof origin and secret are required");
140144
141-
const plantedToken = "ghp_examplesecrettoken0123456789abcd";
145+
const plantedMarker = "private-marker-0123456789abcdef";
146+
const stackMarker = "file:///srv/clawsweeper-internal/exact-review-queue.ts:91:4";
142147
const routePath = "/internal/exact-review/publications/list";
143148
const assertions = [];
144149
const transcript = [];
@@ -149,7 +154,7 @@ function assertProof(name, condition, details = {}) {
149154
}
150155
151156
function redact(value) {
152-
return String(value).split(plantedToken).join("ghp_[PLANTED_TOKEN_REDACTED]");
157+
return String(value).split(plantedMarker).join("[PLANTED_MARKER_REDACTED]");
153158
}
154159
155160
async function signedPost(label, value) {
@@ -197,19 +202,28 @@ const jsonContract =
197202
failing.contentType.includes("application/json") &&
198203
parsedFailing !== null &&
199204
typeof parsedFailing.error === "string";
200-
const tokenLeaked = failing.text.includes(plantedToken);
205+
const markerLeaked = failing.text.includes(plantedMarker);
206+
const stackLeaked = failing.text.includes(stackMarker);
201207
202208
assertProof("failure_status_500", failing.status === 500, { http_status: failing.status });
203209
if (mode === "before") {
204-
assertProof("broken_failure_contract_on_base", !jsonContract || tokenLeaked, {
210+
assertProof("stack_exposed_on_base", stackLeaked, {
205211
json_contract: jsonContract,
206-
token_leaked: tokenLeaked,
212+
marker_leaked: markerLeaked,
213+
stack_leaked: stackLeaked,
207214
});
208215
} else {
209-
assertProof("worker_sanitized_json_contract", jsonContract, {
216+
assertProof("worker_safe_json_contract", jsonContract, {
210217
content_type: failing.contentType,
211218
});
212-
assertProof("planted_token_redacted", !tokenLeaked && failing.text.includes("[REDACTED"), {
219+
assertProof(
220+
"fixed_public_error",
221+
parsedFailing.error === "exact_review_queue_unavailable",
222+
{
223+
response_body: redact(failing.text).slice(0, 300),
224+
},
225+
);
226+
assertProof("internal_details_not_exposed", !markerLeaked && !stackLeaked, {
213227
response_body: redact(failing.text).slice(0, 300),
214228
});
215229
}
@@ -218,13 +232,14 @@ const summary = {
218232
mode,
219233
head_sha: headSha,
220234
route: routePath,
221-
planted_token: "ghp_[PLANTED_TOKEN_REDACTED]",
235+
planted_marker: "[PLANTED_MARKER_REDACTED]",
222236
failure_response: {
223237
status: failing.status,
224238
content_type: failing.contentType,
225239
body: redact(failing.text).slice(0, 2000),
226240
json_contract: jsonContract,
227-
token_leaked: tokenLeaked,
241+
marker_leaked: markerLeaked,
242+
stack_leaked: stackLeaked,
228243
},
229244
assertions,
230245
};
@@ -282,3 +297,5 @@ EXACT_REVIEW_DO_PROOF_ORIGIN="http://127.0.0.1:${port}" \
282297
node "$driver"
283298

284299
test -s "$output_dir/proof-summary.json"
300+
grep -q 'exact_review_queue_request_failed' "$wrangler_log"
301+
printf '%s\n' 'exact_review_queue_request_failed' >"$output_dir/internal-diagnostics.txt"

‎test/dashboard-worker-durable-object-error.test.ts‎

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,73 @@ test("exact-review Durable Object rejects storage failures directly", async () =
4646
assert.equal((await queue.fetch(publicationsListRequest(100))).status, 200);
4747
});
4848

49-
test("exact-review Worker sanitizes rejected Durable Object calls", async () => {
50-
const storage = new MemoryDurableStorage();
51-
const queue = newQueue(storage);
52-
assert.equal((await queue.fetch(publicationsListRequest(100))).status, 200);
53-
54-
storage.failNextSql(
55-
/SELECT item_key, item_json/,
56-
new Error(
57-
"injected sqlite read failure exposing GH_TOKEN=ghp_examplesecrettoken0123456789abcd",
58-
),
59-
);
49+
test("exact-review Worker projects rejected Durable Object calls to a fixed public error", async () => {
50+
const internalStack = [
51+
"Error: database pool internals",
52+
"at readQueue (file:///srv/clawsweeper-private/exact-review-queue.ts:91:4)",
53+
].join("\n");
6054
const secret = "test-webhook-secret";
6155
const requestBody = JSON.stringify({ limit: 100 });
62-
const response = await worker.fetch(signedPublicationsListRequest(requestBody, secret), {
63-
CLAWSWEEPER_WEBHOOK_SECRET: secret,
64-
EXACT_REVIEW_QUEUE: new MemoryDurableNamespace(queue),
65-
});
56+
const originalError = console.error;
57+
const errors: unknown[][] = [];
58+
console.error = (...values: unknown[]) => errors.push(values);
59+
try {
60+
const response = await worker.fetch(signedPublicationsListRequest(requestBody, secret), {
61+
CLAWSWEEPER_WEBHOOK_SECRET: secret,
62+
EXACT_REVIEW_QUEUE: new MemoryDurableNamespace({
63+
async fetch() {
64+
throw internalStack;
65+
},
66+
}),
67+
});
68+
69+
assert.equal(response.status, 500);
70+
assert.equal(response.headers.get("content-type"), "application/json; charset=utf-8");
71+
assert.deepEqual(await response.json(), { error: "exact_review_queue_unavailable" });
72+
assert.deepEqual(errors, [["exact_review_queue_request_failed"]]);
73+
} finally {
74+
console.error = originalError;
75+
}
76+
});
77+
78+
test("exact-review Worker projects malformed Durable Object 5xx responses to a fixed public error", async () => {
79+
const plantedMarker = "private-marker-0123456789abcdef";
80+
const secret = "test-webhook-secret";
81+
const body = JSON.stringify({ limit: 100 });
82+
const originalError = console.error;
83+
const errors: unknown[][] = [];
84+
console.error = (...values: unknown[]) => errors.push(values);
85+
try {
86+
const response = await worker.fetch(signedPublicationsListRequest(body, secret), {
87+
CLAWSWEEPER_WEBHOOK_SECRET: secret,
88+
EXACT_REVIEW_QUEUE: new MemoryDurableNamespace({
89+
async fetch() {
90+
return new Response(`upstream failure marker=${plantedMarker}`, {
91+
status: 503,
92+
headers: { "content-type": "application/json" },
93+
});
94+
},
95+
}),
96+
});
6697

67-
assert.equal(response.status, 500);
68-
assert.equal(response.headers.get("content-type"), "application/json; charset=utf-8");
69-
const responseBody = (await response.json()) as { error?: unknown };
70-
assert.equal(typeof responseBody.error, "string");
71-
assert.equal(JSON.stringify(responseBody).includes("ghp_examplesecrettoken"), false);
98+
assert.equal(response.status, 503);
99+
assert.equal(response.headers.get("content-type"), "application/json; charset=utf-8");
100+
assert.deepEqual(await response.json(), { error: "exact_review_queue_unavailable" });
101+
assert.deepEqual(errors, [["exact_review_queue_malformed_server_response"]]);
102+
} finally {
103+
console.error = originalError;
104+
}
72105
});
73106

74-
test("exact-review Worker normalizes malformed Durable Object 5xx responses", async () => {
75-
const plantedToken = "ghp_examplesecrettoken0123456789abcd";
107+
test("exact-review Worker preserves structured Durable Object 5xx responses", async () => {
76108
const secret = "test-webhook-secret";
77109
const body = JSON.stringify({ limit: 100 });
110+
const responseBody = { error: "lease_decision_unavailable", retryable: true };
78111
const response = await worker.fetch(signedPublicationsListRequest(body, secret), {
79112
CLAWSWEEPER_WEBHOOK_SECRET: secret,
80113
EXACT_REVIEW_QUEUE: new MemoryDurableNamespace({
81114
async fetch() {
82-
return new Response(`upstream failure GH_TOKEN=${plantedToken}`, {
115+
return new Response(JSON.stringify(responseBody), {
83116
status: 503,
84117
headers: { "content-type": "application/json" },
85118
});
@@ -88,11 +121,8 @@ test("exact-review Worker normalizes malformed Durable Object 5xx responses", as
88121
});
89122

90123
assert.equal(response.status, 503);
91-
assert.equal(response.headers.get("content-type"), "application/json; charset=utf-8");
92-
const responseBody = (await response.json()) as { error?: unknown };
93-
assert.equal(typeof responseBody.error, "string");
94-
assert.equal(JSON.stringify(responseBody).includes(plantedToken), false);
95-
assert.match(String(responseBody.error), /\[REDACTED\]/);
124+
assert.equal(response.headers.get("content-type"), "application/json");
125+
assert.deepEqual(await response.json(), responseBody);
96126
});
97127

98128
test("exact-review Worker preserves intentional non-JSON 4xx responses", async () => {

‎test/record-export-bounds.test.ts‎

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -455,54 +455,58 @@ test("signed record export returns one oversized serialized record and advances"
455455
assert.equal(second.nextCursor, null);
456456
});
457457

458-
test("signed record export returns sanitized 500 for missing and invalid logical byte metadata", async () => {
459-
const missingHarness = await exportHarness();
460-
const missing = fixtureRecord({
461-
source: "canonical",
462-
section: "items",
463-
id: "1",
464-
content: "missing-metadata",
465-
storeRevision: 1,
466-
});
467-
seedFixtureRecord(missingHarness.storage, missing);
468-
missingHarness.storage.sql.exec(
469-
`DELETE FROM ${EXACT_REVIEW_CANONICAL_RECORD_TABLE}
458+
test("signed record export hides missing and invalid logical byte metadata", async () => {
459+
const originalError = console.error;
460+
const errors: unknown[][] = [];
461+
console.error = (...values: unknown[]) => errors.push(values);
462+
try {
463+
const missingHarness = await exportHarness();
464+
const missing = fixtureRecord({
465+
source: "canonical",
466+
section: "items",
467+
id: "1",
468+
content: "missing-metadata",
469+
storeRevision: 1,
470+
});
471+
seedFixtureRecord(missingHarness.storage, missing);
472+
missingHarness.storage.sql.exec(
473+
`DELETE FROM ${EXACT_REVIEW_CANONICAL_RECORD_TABLE}
470474
WHERE repo_slug = ? AND section = ? AND item_id = ?`,
471-
REPO_SLUG,
472-
missing.section,
473-
Number(missing.id),
474-
);
475-
const missingResponse = await exportResponse(missingHarness.env, 0);
476-
assert.equal(missingResponse.status, 500);
477-
assert.equal(missingResponse.headers.get("content-type"), "application/json; charset=utf-8");
478-
const missingBody = (await missingResponse.json()) as { error?: unknown };
479-
assert.equal(typeof missingBody.error, "string");
480-
assert.match(String(missingBody.error), /invalid record export byte metadata.*items\/1/);
475+
REPO_SLUG,
476+
missing.section,
477+
Number(missing.id),
478+
);
479+
const missingResponse = await exportResponse(missingHarness.env, 0);
480+
assert.equal(missingResponse.status, 500);
481+
assert.equal(missingResponse.headers.get("content-type"), "application/json; charset=utf-8");
482+
assert.deepEqual(await missingResponse.json(), { error: "exact_review_queue_unavailable" });
481483

482-
const invalidHarness = await exportHarness();
483-
const invalid = fixtureRecord({
484-
source: "backfill",
485-
section: "commits",
486-
id: "b".repeat(40),
487-
content: "invalid-metadata",
488-
storeRevision: 1,
489-
});
490-
seedFixtureRecord(invalidHarness.storage, invalid);
491-
invalidHarness.storage.sql.exec(
492-
`UPDATE ${EXACT_REVIEW_RECORD_BACKFILL_TABLE}
484+
const invalidHarness = await exportHarness();
485+
const invalid = fixtureRecord({
486+
source: "backfill",
487+
section: "commits",
488+
id: "b".repeat(40),
489+
content: "invalid-metadata",
490+
storeRevision: 1,
491+
});
492+
seedFixtureRecord(invalidHarness.storage, invalid);
493+
invalidHarness.storage.sql.exec(
494+
`UPDATE ${EXACT_REVIEW_RECORD_BACKFILL_TABLE}
493495
SET byte_length = 9007199254740992
494496
WHERE repo_slug = ? AND section = ? AND record_id = ?`,
495-
REPO_SLUG,
496-
invalid.section,
497-
invalid.id,
498-
);
499-
const invalidResponse = await exportResponse(invalidHarness.env, 0);
500-
assert.equal(invalidResponse.status, 500);
501-
assert.equal(invalidResponse.headers.get("content-type"), "application/json; charset=utf-8");
502-
const invalidBody = (await invalidResponse.json()) as { error?: unknown };
503-
assert.equal(typeof invalidBody.error, "string");
504-
assert.match(
505-
String(invalidBody.error),
506-
new RegExp(`invalid record export byte metadata.*commits/${invalid.id}`),
507-
);
497+
REPO_SLUG,
498+
invalid.section,
499+
invalid.id,
500+
);
501+
const invalidResponse = await exportResponse(invalidHarness.env, 0);
502+
assert.equal(invalidResponse.status, 500);
503+
assert.equal(invalidResponse.headers.get("content-type"), "application/json; charset=utf-8");
504+
assert.deepEqual(await invalidResponse.json(), { error: "exact_review_queue_unavailable" });
505+
assert.deepEqual(errors, [
506+
["exact_review_queue_request_failed"],
507+
["exact_review_queue_request_failed"],
508+
]);
509+
} finally {
510+
console.error = originalError;
511+
}
508512
});

0 commit comments

Comments
 (0)