Public: anyone can read this; the crew can change it.
A stranger, with no token, follows a public app's own report and offer links and files both #13626
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13585-a-stranger-with-no-token-follows-a-publi → main 2 commits fork
6 files
changed +68
−3
docs/features/muse-test.md +7 −2
| @@ -5,7 +5,9 @@ An agent or person with no account, looking at a public app, needs no teaching. | ||
| 5 | 5 | 1. **The door says it.** Every HTML page of a public app carries |
| 6 | 6 | `Link: </__forge/report>; rel="help"` and a `rel="alternate"` to the forge's |
| 7 | 7 | manifest for the repository (`/api/v1/here?path=/owner/app`). A private app |
| 8 | carries neither and names nothing. | |
| 8 | carries neither and names nothing. On a repository that takes offers the | |
| 9 | same headers add `<…/api/v1/repos/owner/app/offers>; rel="https://forge.open-platform.sh/rel/offer"`, | |
| 10 | and the manifest lists "offer a patch" (no account). | |
| 9 | 11 | 2. **Report a problem, no token.** |
| 10 | 12 | - Page: follow `rel=help`; `/__forge/report?from=/page` sends you to |
| 11 | 13 | `/owner/app/report`, told which page you came from. |
| @@ -13,7 +15,10 @@ An agent or person with no account, looking at a public app, needs no teaching. | ||
| 13 | 15 | `{"title", "body"?, "page"?, "agent"?}` answers `202`. |
| 14 | 16 | - MCP: call `report` on `/mcp` with `{repo, title, body?, page?, agent?}`. |
| 15 | 17 | `/.well-known/mcp.json` lists it in `tokenFreeTools`; every other tool needs a token. |
| 16 | 3. **A person decides.** The report waits, marked `untrusted`, `from: "outside"`, | |
| 18 | 3. **Offer a patch, no token.** `POST` the link's target with | |
| 19 | `{"title", "body"?, "patch"}`, or call MCP `offer`; it becomes a pull a | |
| 20 | person reads (`docs/features/offer.md`), under 3 offers a minute per source. | |
| 21 | 4. **A person decides.** The report waits, marked `untrusted`, `from: "outside"`, | |
| 17 | 22 | with its page. A person who writes the repository accepts it as an issue |
| 18 | 23 | (label `outside`, the stranger's words fenced, "Sent from: <page>") or dismisses it. |
| 19 | 24 | The door is open, so its limits hold: 3 reports a minute per source, 20 per |
src/actions/here.ts +8
| @@ -35,6 +35,7 @@ import { SYSTEM_NAMES } from "../core/reserved.ts"; | ||
| 35 | 35 | import { scopeAllows, type TokenScope } from "../core/tokens.ts"; |
| 36 | 36 | import type { User } from "../core/users.ts"; |
| 37 | 37 | import { mayDirectCrew } from "../crew/direct.ts"; |
| 38 | import { takesOffers } from "./offer.ts"; | |
| 38 | 39 | import { originForRepo } from "../core/origins.ts"; |
| 39 | 40 | import { getPull } from "../core/pulls.ts"; |
| 40 | 41 | import { pullMayRun } from "../core/pull_trust.ts"; |
| @@ -397,6 +398,13 @@ function repoActions( | ||
| 397 | 398 | mcp: "report", |
| 398 | 399 | ...tokenFree("report"), |
| 399 | 400 | }); |
| 401 | if (takesOffers(app, repo)) | |
| 402 | out.push({ | |
| 403 | do: "offer a patch", | |
| 404 | http: `POST ${r}/offers`, | |
| 405 | mcp: "offer", | |
| 406 | ...tokenFree("offer"), | |
| 407 | }); | |
| 400 | 408 | // What creates or costs waits for a proven email (`requireVerified`). |
| 401 | 409 | const unproven = |
| 402 | 410 | viewer !== undefined && !emailVerified(db, viewer.id) ? { verify: true } : {}; |
src/apps/proxy.ts +8
| @@ -27,6 +27,7 @@ import { holds, weakEtag } from "../http/etag.ts"; | ||
| 27 | 27 | import { holdOpen } from "../http/caller.ts"; |
| 28 | 28 | import { appHostSuffix } from "./host.ts"; |
| 29 | 29 | import { REPORT_LINK_TITLE } from "../actions/report_words.ts"; |
| 30 | import { takesOffers } from "../actions/offer.ts"; | |
| 30 | 31 | import { createHmac, timingSafeEqual } from "node:crypto"; |
| 31 | 32 | import type { App } from "../app.ts"; |
| 32 | 33 | import { getAppById, getAppBySlug, type AppRecord } from "../core/apps.ts"; |
| @@ -964,6 +965,10 @@ const reportOf = (runtime: AppsRuntime, repo: Repo): URL => | ||
| 964 | 965 | const REPORT_LINK = |
| 965 | 966 | `</__forge/report>; rel="help"; title="${REPORT_LINK_TITLE}"`; |
| 966 | 967 | |
| 968 | /** The relation and title of the link to the offer door (`POST` a patch, no account). */ | |
| 969 | export const OFFER_REL = "https://forge.open-platform.sh/rel/offer"; | |
| 970 | export const OFFER_LINK_TITLE = "offer a patch to this app, no account needed"; | |
| 971 | ||
| 967 | 972 | /** Names the forge's manifest, so it is told apart from an app's own alternate. */ |
| 968 | 973 | export const REPO_LINK_TITLE = "this app's repository on its forge"; |
| 969 | 974 | |
| @@ -978,9 +983,12 @@ export function discoveryLinks(runtime: AppsRuntime, target: AppTarget): string[ | ||
| 978 | 983 | if (repo === undefined) return []; |
| 979 | 984 | const here = new URL("/api/v1/here", runtime.options.forgeUrl); |
| 980 | 985 | here.search = `?path=${encodeURIComponent(`/${repo.ownerName}/${repo.name}`)}`; |
| 986 | const offers = new URL(`/api/v1/repos/${repo.ownerName}/${repo.name}/offers`, runtime.options.forgeUrl); | |
| 981 | 987 | return [ |
| 982 | 988 | REPORT_LINK, |
| 983 | 989 | `<${here.href}>; rel="alternate"; type="application/json"; title="${REPO_LINK_TITLE}"`, |
| 990 | // The offer door, only where `takesOffers` says it would be answered. | |
| 991 | ...(takesOffers(runtime.app, repo) ? [`<${offers.href}>; rel="${OFFER_REL}"; title="${OFFER_LINK_TITLE}"`] : []), | |
| 984 | 992 | ]; |
| 985 | 993 | } |
| 986 | 994 |
test/here-roles.test.ts +1 −1
| @@ -99,7 +99,7 @@ test("each role gets its own list for one repository", async () => { | ||
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | test("every MCP tool a verb names is a real tool, and the verbs name it", async () => { |
| 102 | const real = new Set([...TOOLS.map((t) => t.name), "report"]); | |
| 102 | const real = new Set([...TOOLS.map((t) => t.name), "report", "offer"]); | |
| 103 | 103 | for (const who of [undefined, "nina", "wes", "wren"]) |
| 104 | 104 | for (const a of await verbs(who)) { |
| 105 | 105 | if (a.mcp !== undefined) expect(real.has(a.mcp)).toBe(true); |
test/manifest-roles.test.ts +2
| @@ -22,6 +22,7 @@ const CEILINGS = { outsider: 1_400, writer: 1_500, admin: 1_600 } as const; | ||
| 22 | 22 | const OUTSIDER_MAY = new Set([ |
| 23 | 23 | "read", |
| 24 | 24 | "report a problem", |
| 25 | "offer a patch", | |
| 25 | 26 | "open an issue", |
| 26 | 27 | "comment", |
| 27 | 28 | "offer a change", |
| @@ -84,6 +85,7 @@ test("a caller is offered only the tools its role may call", () => { | ||
| 84 | 85 | expect(within(who["wes"], WRITER_MAY)).toEqual([]); |
| 85 | 86 | expect(within(who["wren"], ADMIN_MAY)).toEqual([]); |
| 86 | 87 | expect(verbs(undefined)).toContain("report a problem"); |
| 88 | expect(verbs(undefined)).toContain("offer a patch"); | |
| 87 | 89 | expect(verbs(undefined)).toContain("offer a change"); |
| 88 | 90 | expect(verbs(who["wes"])).toContain("merge a pull"); |
| 89 | 91 | expect(verbs(who["wes"])).not.toContain("change settings"); |
test/muse-journey.test.ts +42
| @@ -16,6 +16,7 @@ import { AppsRuntime, type EnvStatus } from "../src/apps/runtime.ts"; | ||
| 16 | 16 | import { OUTSIDE_LABEL } from "../src/core/reports.ts"; |
| 17 | 17 | import { createToken } from "../src/core/tokens.ts"; |
| 18 | 18 | import { createUser } from "../src/core/users.ts"; |
| 19 | import { OFFER_REL } from "../src/apps/proxy.ts"; | |
| 19 | 20 | import { serve, type Servers } from "../src/http/server.ts"; |
| 20 | 21 | import { quietLogs } from "./helpers/globals.ts"; |
| 21 | 22 | |
| @@ -245,6 +246,47 @@ describe("the Muse test: a stranger agent needs no teaching", () => { | ||
| 245 | 246 | expect(pending()).toBe(before + 5); |
| 246 | 247 | }); |
| 247 | 248 | |
| 249 | test("from the page alone a stranger finds the offer door, offers a patch, and meets the same limit", async () => { | |
| 250 | const first = await door("notes", "/"); | |
| 251 | const offerUrl = linkTo(first, OFFER_REL); | |
| 252 | expect(offerUrl).toBe(`${servers.url}/api/v1/repos/alice/notes/offers`); | |
| 253 | const here = (await (await fetch(linkTo(first, "alternate")!)).json()) as any; | |
| 254 | const act = here.can.find((x: any) => x.do === "offer a patch"); | |
| 255 | expect(act.http).toBe("POST /api/v1/repos/alice/notes/offers"); | |
| 256 | expect(act.account).toBe(false); | |
| 257 | ||
| 258 | const patch = [ | |
| 259 | "diff --git a/HELLO.md b/HELLO.md", | |
| 260 | "new file mode 100644", | |
| 261 | "index 0000000..e69de29", | |
| 262 | "--- /dev/null", | |
| 263 | "+++ b/HELLO.md", | |
| 264 | "@@ -0,0 +1 @@", | |
| 265 | "+hello from a stranger", | |
| 266 | "", | |
| 267 | ].join("\n"); | |
| 268 | const send = (ip: string, title: string) => | |
| 269 | fetch(offerUrl!, { | |
| 270 | method: "POST", | |
| 271 | headers: { "content-type": "application/json", "x-forwarded-for": ip }, | |
| 272 | body: JSON.stringify({ title, patch }), | |
| 273 | }); | |
| 274 | const one = "203.0.113.150"; | |
| 275 | const first1 = await send(one, "Add hello"); | |
| 276 | expect(first1.status).toBe(202); | |
| 277 | const filed = (await first1.json()) as any; | |
| 278 | // It landed: a pull a person reads, and a receipt anyone with it can poll. | |
| 279 | const pulls = (await (await owner("/api/v1/repos/alice/notes/pulls")).json()) as any; | |
| 280 | expect((pulls.items ?? pulls).some((p: any) => p.number === filed.number)).toBe(true); | |
| 281 | expect(((await (await fetch(filed.status)).json()) as any).state).toBeDefined(); | |
| 282 | // The limit holds: three a minute from one source. | |
| 283 | const rest = [await send(one, "two"), await send(one, "three"), await send(one, "four")]; | |
| 284 | expect(rest.map((r) => r.status)).toContain(429); | |
| 285 | ||
| 286 | const diary = await door("diary", "/"); | |
| 287 | expect(linkTo(diary, OFFER_REL)).toBeUndefined(); | |
| 288 | }); | |
| 289 | ||
| 248 | 290 | test("a private app's door answers neither route and leaks no repository name", async () => { |
| 249 | 291 | const res = await door("diary", "/"); |
| 250 | 292 | const seen = [res.headers.get("link") ?? "", await res.text()].join("\n"); |
new above
offline