Public: anyone can read this; the crew can change it.
Crash reports: a private app's owner makes a report key, and a build with it can file reports without a session #18277
Merged 6h 5m ago, live in production
scout/forge:scout/18224-crash-reports-a-private-app-s-owner-make → main 0 commits fork
8 files
changed +121
−2
docs/features/crash-reports.md +1 −1
| @@ -6,7 +6,7 @@ row: Crash reports | ||
| 6 | 6 | |
| 7 | 7 | A crash an app reports becomes an ordinary `bug` issue on the app's own repository. An app, or its tester, sends it with `POST /api/v1/repos/<owner>/<name>/crash-reports` (`/api/v1/apps/...` is the same handler, kept as an alias for builds already using it; use `repos`), no token for a public repository (a tester cannot always open an issue, so the forge files it for them). The repository need not be a hosted app: a native app's repository takes reports too. A private repository answers a signed-in person who can write to it, or a build that sends its report key as `X-Report-Key`; everyone else gets the same 404 as for a repository that does not exist, so the door never says which private ones there are. |
| 8 | 8 | |
| 9 | - **The report key.** The repository's admin makes it in the "Report key" card of the repository's settings page: "Make report key" shows it once, "Rotate report key" replaces it at once, "Revoke report key" removes it. In the terminal it is the same screen as "Crash groups of a repository": `n` makes or rotates, `x` revokes, after a confirm, as the page asks. The page's forms are `src/web/pages/report_key.ts`, the terminal's keys `src/tui/screens/crash_groups.ts`, both through `src/actions/report_key.ts`. Only its hash is kept. It files crash reports for that repository and does nothing else. | |
| 9 | - **The report key.** The repository's admin makes it in the "Report key" card of the repository's settings page: "Make report key" shows it once, "Rotate report key" replaces it at once, "Revoke report key" removes it. In the terminal it is the same screen as "Crash groups of a repository": `n` makes or rotates, `x` revokes, after a confirm, as the page asks. The page's forms are `src/web/pages/report_key.ts`, the terminal's keys `src/tui/screens/crash_groups.ts`, both through `src/actions/report_key.ts`. A script does the same with `POST` (make or rotate, answers 201 `{key}` once) and `DELETE` (revoke) on `/api/v1/repos/<owner>/<name>/report-key`, an `rw` token of the admin; anyone else gets 404. Only its hash is kept. It files crash reports for that repository and does nothing else. | |
| 10 | 10 | |
| 11 | 11 | - **The body.** The Apple app's own: `{"v":1,"kind":"crash","app":{"version":"0.1","build":"50"},"os":"iOS 26.2","device":"iPhone","at":"2026-12-04T00:00:00Z","previousRun":{"launchedAt":"2026-12-03T23:58:00Z","breadcrumbs":["12:00:01 tab repos"]},"findings":[{"kind":"crash","signal":"5","exception":"6","termination":"Namespace SIGNAL","version":"0.1","frames":["Forge +1445064","SwiftUI +7"]}]}`. Each finding (up to 20; `crash`, `hang`, `cpu` or `disk`, 1 to 12 frames) files or counts one group, with the previous run's breadcrumbs; with no finding the previous run is one group with no frames. `os` and `device` model go in the issue, nothing that names a person has a field. The first shape, `{"v":1,"build":"50","kind":"crash","frames":[...],"breadcrumbs":[...]}`, still works. Up to 200 breadcrumbs, each line cut at 200 characters. The app's other spellings work too: `app` as text (up to 64 characters) or `{version, build}`, `previousRun` as `true` or an object, `breadcrumbs` on a finding, and no build at all when it sends findings (such a report is counted but never reopens a closed group, and a build is never invented for it); `at` is checked and dropped, the forge stamping its own time; two findings of one group count once. A top-level `frames` and `findings` together file all of them. Any other field is a 422 in words; over 128 KB is a 413. The answer is 202 `{issue, count, opened, reopened, issues}`. The anonymous `/api/v1/telemetry/apple` door also takes a strict crash report into the owner's telemetry view, apart from these issues and with no key (#18006). |
| 12 | 12 | - **One issue per group.** Reports with the same kind and top three frames are one group. The first files the issue (title from the top frame and the build, body with the frames, breadcrumbs, count and builds); a later one raises the count on the issue's "Seen" line (nothing else in the body is rewritten) and adds a comment for the first 20 sightings. |
src/contract/openapi/routes/deleteApiV1ReposOwnerNameReportKey.ts added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "delete", | |
| 5 | path: "/api/v1/repos/{owner}/{name}/report-key", | |
| 6 | summary: "Revoke a repository's report key (rw scope, its admin); 404 when there is none", | |
| 7 | auth: true, | |
| 8 | role: "member", | |
| 9 | refuses: [401, 404], | |
| 10 | }; |
src/contract/openapi/routes/index.ts +2
| @@ -38,6 +38,7 @@ export { route as deleteApiV1ReposOwnerNameMilestonesNumberWatch } from "./delet | ||
| 38 | 38 | export { route as deleteApiV1ReposOwnerNamePromptsId } from "./deleteApiV1ReposOwnerNamePromptsId.ts"; |
| 39 | 39 | export { route as deleteApiV1ReposOwnerNamePullsNumberHold } from "./deleteApiV1ReposOwnerNamePullsNumberHold.ts"; |
| 40 | 40 | export { route as deleteApiV1ReposOwnerNamePullsNumberThreadsAnchorResolve } from "./deleteApiV1ReposOwnerNamePullsNumberThreadsAnchorResolve.ts"; |
| 41 | export { route as deleteApiV1ReposOwnerNameReportKey } from "./deleteApiV1ReposOwnerNameReportKey.ts"; | |
| 41 | 42 | export { route as deleteApiV1SecretsScopeName } from "./deleteApiV1SecretsScopeName.ts"; |
| 42 | 43 | export { route as deleteApiV1Sessions } from "./deleteApiV1Sessions.ts"; |
| 43 | 44 | export { route as deleteApiV1TimersKey } from "./deleteApiV1TimersKey.ts"; |
| @@ -505,6 +506,7 @@ export { route as postApiV1ReposOwnerNamePullsNumberSlices } from "./postApiV1Re | ||
| 505 | 506 | export { route as postApiV1ReposOwnerNamePullsNumberTakeBack } from "./postApiV1ReposOwnerNamePullsNumberTakeBack.ts"; |
| 506 | 507 | export { route as postApiV1ReposOwnerNamePullsNumberThreadsAnchorResolve } from "./postApiV1ReposOwnerNamePullsNumberThreadsAnchorResolve.ts"; |
| 507 | 508 | export { route as postApiV1ReposOwnerNamePullsNumberVariant } from "./postApiV1ReposOwnerNamePullsNumberVariant.ts"; |
| 509 | export { route as postApiV1ReposOwnerNameReportKey } from "./postApiV1ReposOwnerNameReportKey.ts"; | |
| 508 | 510 | export { route as postApiV1ReposOwnerNameReports } from "./postApiV1ReposOwnerNameReports.ts"; |
| 509 | 511 | export { route as postApiV1ReposOwnerNameReportsIdAccept } from "./postApiV1ReposOwnerNameReportsIdAccept.ts"; |
| 510 | 512 | export { route as postApiV1ReposOwnerNameReportsIdDismiss } from "./postApiV1ReposOwnerNameReportsIdDismiss.ts"; |
src/contract/openapi/routes/postApiV1ReposOwnerNameReportKey.ts added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "post", | |
| 5 | path: "/api/v1/repos/{owner}/{name}/report-key", | |
| 6 | summary: "Make or rotate a repository's report key; shown once (rw scope, the repository's admin)", | |
| 7 | detail: "The key lets a build file crash reports to a private repository without a session: send it as the `x-report-key` header of `POST /api/v1/repos/{owner}/{name}/crash-reports`. It opens that one door. Only its hash is kept; making another stops the old one. Answers 201 `{key, message}`.", | |
| 8 | auth: true, | |
| 9 | role: "member", | |
| 10 | status: 201, | |
| 11 | refusals: { not_found: "no such repository, or you do not administer it (404)" }, | |
| 12 | refuses: [401, 404], | |
| 13 | }; |
src/contract/tags.ts +1
src/http/api/crash_reports.ts +23 −1
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | |
| 15 | 15 | import type { App } from "../../app.ts"; |
| 16 | 16 | import { reportCrashes } from "../../actions/crash_reports.ts"; |
| 17 | import { makeKey, revokeKey } from "../../actions/report_key.ts"; | |
| 17 | 18 | import { parseReports, REPORT_ERRORS } from "../../core/crash_groups.ts"; |
| 18 | 19 | import { RateLimiter } from "../../core/ratelimit.ts"; |
| 19 | 20 | import { reportKeyMatches } from "../../core/report_key.ts"; |
| @@ -21,7 +22,7 @@ import { canWrite, getRepo } from "../../core/repos.ts"; | ||
| 21 | 22 | import type { Handler } from "../context.ts"; |
| 22 | 23 | import { BODY_CAPS, RATE_CAPS, readBounded } from "../limits.ts"; |
| 23 | 24 | import { clientBucket } from "../peer.ts"; |
| 24 | import { apiError, json, tryAgain } from "../respond.ts"; | |
| 25 | import { apiError, json, requireScope, tryAgain } from "../respond.ts"; | |
| 25 | 26 | import type { Router } from "../router.ts"; |
| 26 | 27 | |
| 27 | 28 | const limiter = (perMinute: number) => new RateLimiter({ perMinute, adminPerMinute: perMinute, enabled: true }); |
| @@ -30,6 +31,27 @@ const limits = new WeakMap<App, { client: RateLimiter; forge: RateLimiter }>(); | ||
| 30 | 31 | export function crashReportRoutes(router: Router<Handler>): void { |
| 31 | 32 | router.add("POST", "/api/v1/repos/:owner/:name/crash-reports", crashReport); |
| 32 | 33 | router.add("POST", "/api/v1/apps/:owner/:name/crash-reports", crashReport); |
| 34 | router.add("POST", "/api/v1/repos/:owner/:name/report-key", reportKeyWrite(true)); | |
| 35 | router.add("DELETE", "/api/v1/repos/:owner/:name/report-key", reportKeyWrite(false)); | |
| 36 | } | |
| 37 | ||
| 38 | /** | |
| 39 | * Make or rotate (POST) or revoke (DELETE) the report key (#18224): the same actions, and so the | |
| 40 | * same words, as the settings page. The key is shown once; 404 when the caller does not administer | |
| 41 | * the repository, or a revoke finds none. | |
| 42 | */ | |
| 43 | function reportKeyWrite(make: boolean) { | |
| 44 | return (ctx: Parameters<Handler>[0]): Response => { | |
| 45 | const denied = requireScope(ctx, "rw"); | |
| 46 | if (denied) return denied; | |
| 47 | const repo = getRepo(ctx.app.db, ctx.params.owner!, ctx.params.name!); | |
| 48 | const done = repo === undefined ? undefined : make ? makeKey(ctx.app, ctx.auth.user, repo) : revokeKey(ctx.app, ctx.auth.user, repo); | |
| 49 | if (done === undefined || !done.ok || done.value === false) return apiError("not_found", 404, "no repository by that name, or it has no report key"); | |
| 50 | const noStore = { "cache-control": "no-store" }; | |
| 51 | return make | |
| 52 | ? json({ key: done.value, message: "Shown once: put it in the build as X-Report-Key. Making another replaces it at once." }, 201, noStore) | |
| 53 | : json({ message: "Report key revoked: a build that sends it is refused." }, 200, noStore); | |
| 54 | }; | |
| 33 | 55 | } |
| 34 | 56 | |
| 35 | 57 | async function crashReport(ctx: Parameters<Handler>[0]): Promise<Response> { |
src/http/lazy_lists.ts +2
| @@ -1275,6 +1275,8 @@ export const API_ROUTES = [ | ||
| 1275 | 1275 | ["POST", "/api/v1/telemetry/apple"], |
| 1276 | 1276 | ["POST", "/api/v1/repos/:owner/:name/crash-reports"], |
| 1277 | 1277 | ["POST", "/api/v1/apps/:owner/:name/crash-reports"], |
| 1278 | ["POST", "/api/v1/repos/:owner/:name/report-key"], | |
| 1279 | ["DELETE", "/api/v1/repos/:owner/:name/report-key"], | |
| 1278 | 1280 | ["GET", "/api/v1/version"], |
| 1279 | 1281 | ["GET", "/api/v1/user/repos"], |
| 1280 | 1282 | ["GET", "/api/v1/admin/pinned"], |
test/report-key-api.test.ts added +69
| @@ -0,0 +1,69 @@ | ||
| 1 | /** | |
| 2 | * The report key's API (#18224): the admin's `rw` token makes it (shown once), a build files with | |
| 3 | * it, a read token or a stranger is the plain 404, revoking stops it, a wrong key's 404 body is the | |
| 4 | * one of a repository that does not exist. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createToken } from "../src/core/tokens.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 15 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 16 | ||
| 17 | let dir = ""; | |
| 18 | let app: App; | |
| 19 | let servers: Servers; | |
| 20 | let rw = ""; | |
| 21 | let ro = ""; | |
| 22 | let bobRw = ""; | |
| 23 | ||
| 24 | const report = { v: 1, build: "1", kind: "crash", frames: ["Forge +1"] }; | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dir = await mkdtemp(join(tmpdir(), "forge-report-key-api-")); | |
| 28 | app = createApp({ dataDir: dir, port: 0 }); | |
| 29 | servers = await serve(app); | |
| 30 | const alice = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" }); | |
| 31 | const bob = await createUser(app.db, { username: "bob", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true }); | |
| 32 | if (!alice.ok || !bob.ok) throw new Error("no users"); | |
| 33 | const made = await createRepo(app, alice.value, { name: "ios", visibility: "private" }); | |
| 34 | if (!made.ok) throw new Error(made.error); | |
| 35 | rw = createToken(app.db, alice.value.id, "rw", "rw").token; | |
| 36 | ro = createToken(app.db, alice.value.id, "ro", "ro").token; | |
| 37 | bobRw = createToken(app.db, bob.value.id, "rw", "rw").token; | |
| 38 | }); | |
| 39 | afterAll(async () => { | |
| 40 | servers.stop(); | |
| 41 | app.close(); | |
| 42 | await rm(dir, { recursive: true, force: true }); | |
| 43 | }); | |
| 44 | ||
| 45 | const keyUrl = () => `${servers.url}/api/v1/repos/alice/ios/report-key`; | |
| 46 | const as = (token: string, method: string) => fetch(keyUrl(), { method, headers: { authorization: `Bearer ${token}` } }); | |
| 47 | const file = (key: string, name = "ios") => | |
| 48 | fetch(`${servers.url}/api/v1/repos/alice/${name}/crash-reports`, { method: "POST", headers: { "x-report-key": key }, body: JSON.stringify(report) }); | |
| 49 | ||
| 50 | test("the admin makes a key, a build files with it, revoke stops it, a wrong key is the missing repository's 404", async () => { | |
| 51 | expect((await as(ro, "POST")).status).toBe(403); | |
| 52 | expect((await as(bobRw, "POST")).status).toBe(404); | |
| 53 | expect((await as(bobRw, "DELETE")).status).toBe(404); | |
| 54 | expect((await as(rw, "DELETE")).status).toBe(404); // none yet | |
| 55 | const made = await as(rw, "POST"); | |
| 56 | expect(made.status).toBe(201); | |
| 57 | const { key } = (await made.json()) as { key: string }; | |
| 58 | expect(key.length).toBeGreaterThan(20); | |
| 59 | expect((await file(key)).status).toBe(202); | |
| 60 | const missing = await file("x", "nope"); | |
| 61 | const wrong = await file("rk_wrong"); | |
| 62 | expect(wrong.status).toBe(404); | |
| 63 | expect(await wrong.text()).toBe(await missing.text()); | |
| 64 | const gone = await as(rw, "DELETE"); | |
| 65 | expect(gone.status).toBe(200); | |
| 66 | const refused = await file(key); | |
| 67 | expect(refused.status).toBe(404); | |
| 68 | expect(await refused.text()).toBe(await (await file("x", "nope")).text()); | |
| 69 | }); |
new above
offline