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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/13585-a-stranger-with-no-token-follows-a-publi → main 2 commits fork

  • Merged. mason/13585-a-stranger-with-no-token-follows-a-publi was merged into main as b49124a.

Review

Sign in to review this change.
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.
55 1. **The door says it.** Every HTML page of a public app carries
66 `Link: </__forge/report>; rel="help"` and a `rel="alternate"` to the forge's
77 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).
911 2. **Report a problem, no token.**
1012 - Page: follow `rel=help`; `/__forge/report?from=/page` sends you to
1113 `/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.
1315 `{"title", "body"?, "page"?, "agent"?}` answers `202`.
1416 - MCP: call `report` on `/mcp` with `{repo, title, body?, page?, agent?}`.
1517 `/.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"`,
1722 with its page. A person who writes the repository accepts it as an issue
1823 (label `outside`, the stranger's words fenced, "Sent from: <page>") or dismisses it.
1924 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";
3535 import { scopeAllows, type TokenScope } from "../core/tokens.ts";
3636 import type { User } from "../core/users.ts";
3737 import { mayDirectCrew } from "../crew/direct.ts";
38 import { takesOffers } from "./offer.ts";
3839 import { originForRepo } from "../core/origins.ts";
3940 import { getPull } from "../core/pulls.ts";
4041 import { pullMayRun } from "../core/pull_trust.ts";
@@ -397,6 +398,13 @@ function repoActions(
397398 mcp: "report",
398399 ...tokenFree("report"),
399400 });
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 });
400408 // What creates or costs waits for a proven email (`requireVerified`).
401409 const unproven =
402410 viewer !== undefined && !emailVerified(db, viewer.id) ? { verify: true } : {};
src/apps/proxy.ts +8
@@ -27,6 +27,7 @@ import { holds, weakEtag } from "../http/etag.ts";
2727 import { holdOpen } from "../http/caller.ts";
2828 import { appHostSuffix } from "./host.ts";
2929 import { REPORT_LINK_TITLE } from "../actions/report_words.ts";
30 import { takesOffers } from "../actions/offer.ts";
3031 import { createHmac, timingSafeEqual } from "node:crypto";
3132 import type { App } from "../app.ts";
3233 import { getAppById, getAppBySlug, type AppRecord } from "../core/apps.ts";
@@ -964,6 +965,10 @@ const reportOf = (runtime: AppsRuntime, repo: Repo): URL =>
964965 const REPORT_LINK =
965966 `</__forge/report>; rel="help"; title="${REPORT_LINK_TITLE}"`;
966967
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
967972 /** Names the forge's manifest, so it is told apart from an app's own alternate. */
968973 export const REPO_LINK_TITLE = "this app's repository on its forge";
969974
@@ -978,9 +983,12 @@ export function discoveryLinks(runtime: AppsRuntime, target: AppTarget): string[
978983 if (repo === undefined) return [];
979984 const here = new URL("/api/v1/here", runtime.options.forgeUrl);
980985 here.search = `?path=${encodeURIComponent(`/${repo.ownerName}/${repo.name}`)}`;
986 const offers = new URL(`/api/v1/repos/${repo.ownerName}/${repo.name}/offers`, runtime.options.forgeUrl);
981987 return [
982988 REPORT_LINK,
983989 `<${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}"`] : []),
984992 ];
985993 }
986994
test/here-roles.test.ts +1 −1
@@ -99,7 +99,7 @@ test("each role gets its own list for one repository", async () => {
9999 });
100100
101101 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"]);
103103 for (const who of [undefined, "nina", "wes", "wren"])
104104 for (const a of await verbs(who)) {
105105 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;
2222 const OUTSIDER_MAY = new Set([
2323 "read",
2424 "report a problem",
25 "offer a patch",
2526 "open an issue",
2627 "comment",
2728 "offer a change",
@@ -84,6 +85,7 @@ test("a caller is offered only the tools its role may call", () => {
8485 expect(within(who["wes"], WRITER_MAY)).toEqual([]);
8586 expect(within(who["wren"], ADMIN_MAY)).toEqual([]);
8687 expect(verbs(undefined)).toContain("report a problem");
88 expect(verbs(undefined)).toContain("offer a patch");
8789 expect(verbs(undefined)).toContain("offer a change");
8890 expect(verbs(who["wes"])).toContain("merge a pull");
8991 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";
1616 import { OUTSIDE_LABEL } from "../src/core/reports.ts";
1717 import { createToken } from "../src/core/tokens.ts";
1818 import { createUser } from "../src/core/users.ts";
19 import { OFFER_REL } from "../src/apps/proxy.ts";
1920 import { serve, type Servers } from "../src/http/server.ts";
2021 import { quietLogs } from "./helpers/globals.ts";
2122
@@ -245,6 +246,47 @@ describe("the Muse test: a stranger agent needs no teaching", () => {
245246 expect(pending()).toBe(before + 5);
246247 });
247248
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
248290 test("a private app's door answers neither route and leaks no repository name", async () => {
249291 const res = await door("diary", "/");
250292 const seen = [res.headers.get("link") ?? "", await res.text()].join("\n");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs