Public: anyone can read this; the crew can change it.
A child's parent.json cannot name an upstream or a minting identity the child was not given #14942
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14915-a-child-s-parent-json-cannot-name-an-ups → main 1 commit fork
2 files
changed +64
−8
src/spawn/app_links.ts +13 −8
| @@ -40,7 +40,7 @@ import { | ||
| 40 | 40 | renewFollowTokens, |
| 41 | 41 | revokeFollowTokens, |
| 42 | 42 | } from "../core/proposal_token.ts"; |
| 43 | import { canWrite, getRepo, getRepoById, listReposOwnedBy, type Repo } from "../core/repos.ts"; | |
| 43 | import { canRead, canWrite, getRepo, getRepoById, listReposOwnedBy, type Repo } from "../core/repos.ts"; | |
| 44 | 44 | import { |
| 45 | 45 | followAad, |
| 46 | 46 | getFollow, |
| @@ -244,8 +244,9 @@ export async function anchorsOf(app: App, parent: Repo): Promise<string[]> { | ||
| 244 | 244 | const ANCHORS_MAX = 8; |
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | * The person a follow token for `repo` is minted as: the spawner, when they may read it, else the | |
| 248 | * repository's owner when that is a person. | |
| 247 | * The person a follow token for `repo` is minted as: the spawner, and only while they may read it. | |
| 248 | * The repository's owner is never stood in: a child whose spawner left, or lost the repository, | |
| 249 | * stops being able to read it, and the fork page says so (`notOffered`). | |
| 249 | 250 | */ |
| 250 | 251 | function mintingUser( |
| 251 | 252 | app: App, |
| @@ -254,9 +255,9 @@ function mintingUser( | ||
| 254 | 255 | ): User | undefined { |
| 255 | 256 | const spawner = |
| 256 | 257 | ownerId === undefined ? undefined : getUserById(app.db, ownerId); |
| 257 | if (spawner !== undefined && spawner.kind === "user") return spawner; | |
| 258 | const owner = getUserById(app.db, parent.ownerId); | |
| 259 | return owner?.kind === "user" ? owner : undefined; | |
| 258 | return spawner !== undefined && spawner.kind === "user" && canRead(app.db, parent, spawner) | |
| 259 | ? spawner | |
| 260 | : undefined; | |
| 260 | 261 | } |
| 261 | 262 | |
| 262 | 263 | /** |
| @@ -370,7 +371,7 @@ export async function offerAppLinks(app: App, child: Child): Promise<Offered> { | ||
| 370 | 371 | } |
| 371 | 372 | const token = followToken(app, parent, { name: child.name, url: child.url, ownerId: child.ownerId }); |
| 372 | 373 | if (parent.visibility !== "public" && token === undefined) { |
| 373 | skip(ref, `${ref} is private and no person here can mint it a read credential`); | |
| 374 | skip(ref, `${ref} is private and the person who spawned this child is gone or can no longer read it, so no read credential is minted`); | |
| 374 | 375 | continue; |
| 375 | 376 | } |
| 376 | 377 | const entry: AppEntry = { |
| @@ -871,7 +872,8 @@ export function reportLines(app: App, forge: string, lines: readonly AppLinkLine | ||
| 871 | 872 | /** |
| 872 | 873 | * For the heartbeat's answer: the tip of each followed app on this forge's default branch, by the |
| 873 | 874 | * child's own repository, so a child in a cell of its own learns an app landed without waiting |
| 874 | * for its clock. Only apps it applied and did not sever; bounded. | |
| 875 | * for its clock. Only apps the ledger says it was given, that it applied and did not sever; | |
| 876 | * bounded. | |
| 875 | 877 | */ |
| 876 | 878 | export async function appTipsFor( |
| 877 | 879 | app: App, |
| @@ -880,11 +882,14 @@ export async function appTipsFor( | ||
| 880 | 882 | const child = await childNamed(app, name); |
| 881 | 883 | if (child === undefined) return {}; |
| 882 | 884 | const tips: Record<string, string> = {}; |
| 885 | // parent.json is the child's to write: only the apps the ledger says it was given are looked up. | |
| 886 | const given = new Set(child.apps); | |
| 883 | 887 | for (const e of entriesOf(await readDoc(childDirOf(app, child.bodyId))).slice( |
| 884 | 888 | 0, |
| 885 | 889 | 50, |
| 886 | 890 | )) { |
| 887 | 891 | if (e.appliedAt === undefined || e.severedAt !== undefined) continue; |
| 892 | if (!given.has(e.upstream)) continue; | |
| 888 | 893 | const [o, n] = e.upstream.split("/") as [string, string]; |
| 889 | 894 | const parent = getRepo(app.db, o, n); |
| 890 | 895 | if (parent === undefined) continue; |
test/spawn-app-links.test.ts +51
| @@ -847,5 +847,56 @@ describe("apps sent down by a spawn follow their parent", () => { | ||
| 847 | 847 | ); |
| 848 | 848 | expect(getFollow(own.child.db, repo.id)!.via).toBe(""); |
| 849 | 849 | }, 240_000); |
| 850 | ||
| 851 | /** Rewrite a child's ledger entry for who spawned it; undefined drops the field. */ | |
| 852 | async function setSpawner(name: string, ownerId: string | undefined) { | |
| 853 | const at = join(parent.config.dataDir, "spawn", `${name}.json`); | |
| 854 | const ledger = (await Bun.file(at).json()) as Record<string, unknown>; | |
| 855 | if (ownerId === undefined) delete ledger["ownerId"]; | |
| 856 | else ledger["ownerId"] = ownerId; | |
| 857 | await Bun.write(at, JSON.stringify(ledger)); | |
| 858 | } | |
| 859 | ||
| 860 | test("a follow token is minted only as the spawner, while they can read the parent: never as the owner in their place", async () => { | |
| 861 | await bare("orphan"); | |
| 862 | await setSpawner("orphan", undefined); | |
| 863 | const bob = await createUser(parent.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]" }); | |
| 864 | if (!bob.ok) throw new Error("user"); | |
| 865 | await bare("stranger"); | |
| 866 | await setSpawner("stranger", bob.value.id); | |
| 867 | const done = await reconcileAppLinks(parent, true); | |
| 868 | // The public app is still offered; the private one has no one to read it as. | |
| 869 | expect(done["orphan"]?.offered).toEqual(["alice/notes"]); | |
| 870 | expect(done["stranger"]?.offered).toEqual(["alice/notes"]); | |
| 871 | expect(followTokenCount(parent.db, vault.id, "orphan")).toBe(0); | |
| 872 | expect(followTokenCount(parent.db, vault.id, "stranger")).toBe(0); | |
| 873 | const { listChildren } = await import("../src/actions/spawn.ts"); | |
| 874 | const orphan = (await listChildren(parent)).find((c) => c.name === "orphan")!; | |
| 875 | const line = (await appLinkLines(parent, orphan)).find((l) => l.upstream === "alice/vault")!; | |
| 876 | expect(line.state).toBe("not-offered"); | |
| 877 | expect(line.why).toContain("spawned this child is gone or can no longer read it"); | |
| 878 | }, 240_000); | |
| 879 | ||
| 880 | test("the heartbeat's tips name only apps the ledger gave the child, whatever parent.json claims", async () => { | |
| 881 | const liar = await bare("liar"); | |
| 882 | await reconcileAppLinks(parent, true); | |
| 883 | await applyAppLinks(liar.child); | |
| 884 | const at = join(liar.dataDir, "parent.json"); | |
| 885 | const doc = (await Bun.file(at).json()) as Record<string, unknown>; | |
| 886 | const now = new Date().toISOString(); | |
| 887 | await Bun.write( | |
| 888 | at, | |
| 889 | JSON.stringify({ | |
| 890 | ...doc, | |
| 891 | apps: [ | |
| 892 | ...(doc["apps"] as unknown[]), | |
| 893 | { repo: "liar/other", upstream: "alice/other", url: "x", branch: "main", mode: "take-updates", anchor: "0".repeat(40), offeredAt: now, appliedAt: now }, | |
| 894 | ], | |
| 895 | }), | |
| 896 | ); | |
| 897 | const tips = await appTipsFor(parent, "liar"); | |
| 898 | expect(Object.keys(tips).sort()).toEqual(["liar/notes", "liar/vault"]); | |
| 899 | expect(Object.values(tips)).not.toContain(await tip(parentDir(other))); | |
| 900 | }, 240_000); | |
| 850 | 901 | }); |
| 851 | 902 | }); |
new above
offline