Public: anyone can read this; the crew can change it.
Access 5a: a visitor principal is minted only when a visitor creates something, signed, with a role in may() and per-visitor limits #18174
Merged 3h 47m ago, live in production
A visitor with no account now becomes a principal only when they make something. The one place a visitor makes something today is an app note sent from the forge button, and that is now wired to it. What changed New src/core/visitors.ts.
-
Reviews
Changes requested — before the latest pushNo high finding, but the pull is not whole yet. Changes, in one round:
- src/apps/feedback.ts
heldSender(used bylistandpicture) andsendpassloadKey(ask.app.config.dataDir)eagerly. That brings back the failure the second commit fixed inresolveAuth: every notes list read by a visitor with no cookie touches the key file, and it throws whensecret.keyhas the wrong mode. Pass the thunk() => loadKey(...)inheldSendertoo, and add a test that a list read with no cookie never reads the key. - src/core/visitors.ts:
VISITOR_MAKESlistsshared_appandgame_player, but nothing makes either. Thekindcolumn is written and never read. Either wire a second kind, or drop the unused kinds and the column until a route needs them. Do not ship speculative surface. - Box 1 is only partly met: only notes mint. The issue names an app made in the tab forge and shared, and a linked game player. If those are left out, open follow-up issues for them with the API, and say so in the pull.
- Per-forge cap as a lockout: a client that drops the cookie gets a fresh id each time, so the per-visitor cap never binds. Anyone can then use up the 5000 a day and refuse every other visitor. Tell the builders in the doc that the per-client rate limit is what bounds this. Count the per-forge cap by the socket address as well, or only count notes that were filed.
- Visitors who hold an old unsigned
forge_visitornote cookie lose sight of their own notes in the list. Say so in docs/features/notes.md, or accept the old cookie once for reads.
Checked and fine: HMAC with its own HKDF key and constant-time compare,
userOfis none for a visitor, a read mints nothing, DNT/GPC mint nothing, the cookie is HttpOnly, no README change, and no newbus.appendkind.ApprovedEarlier asks met. The per-connection cap now exists (
VISITOR_CAPS.perClient, keyed onclientBucket, the socket's address, not a client header) and a test covers it, so a client that drops its cookie can no longer spend the forge's 5000 alone. The key is read lazily, so a no-credential request never touches the key file. Only filed notes count against the caps. The cookie is signed with its own key, mints only on the 201 answer, and honours DNT/GPC. Docs are indocs/features/notes.mdanddocs/ROLES.md, not the README. Non-blocking:mintrepeatsmintIdandtablerepeats the lazy-table pattern; both are justified in the pull. - src/apps/feedback.ts
-
Checks
shipped production is serving it deploy 281fd2f
-
History
- Merge main into the visitor principal branch (#18112) 83c70ff
- Access 3b: MCP, pages, the terminal, games and infrastructure ask may(), one door per pull (#18186) 5a3de44
- Games: the forge-velocity pin's sha256 is the jar's whole digest (#18198) 7ede9b5
- Access 4b-2: an admin sees who can reach what, by person and by resource (#18179) a8d3bc8
- Full suite red: test/standards-sitemap.test.ts (#18193) 8072255
- Games: the forge pins forge-velocity bee2a65cf3f2 (/forge answers from a SQLite snapshot at once, one clean style) (#18163) b4fe556
- Games survival step 3c: a vein-miner mod in the quality set (#18177) bd6dc66
- Rewrap comments (#18112) 11a4270
- Visitor caps count by connection too; the key is read only when needed; unused kinds dropped (#18112) b13370e
- Bug and crash reports from an app become work: an issue on its repository, a triage, and a fix pull (#18097) 68dcbf7
- Games survival step 4: admin mods (luckperms fabric, ledger with fabric-language-kotlin) (#18148) 4fb3248
- Games: /forge reads are answered in the same sync, and the agent sends a request within a fifth of a second (#18149) e529fa8
- Traces 5a: compare two traces of one issue side by side, with the cost and time difference (#18164) e7394aa
- Access 3a: the /api/v1 repository routes ask may(), shadowed first, then their inline checks go (#18165) 7ba81ba
- Read the secret key only when a maker cookie is there, so a request with no credential never touches it (#18112) 8c362f0
- Spark's config is installed with the mod so a profile uploads to the forge and never elsewhere (#18173) 7de2fc0
- Games survival step 3b: a sleep (night-skip) mod in the quality set (#18172) 56e2b82
- Automate a review finding as a lint or test: One high finding, then smaller ones, all for one round. (#18167) f6eb779
- A spark profile decodes to a summary: call tree, slowest ticks, per-mod time, GC and memory (#18144) e30e2b6
- Access 4b: the 'Who may do what' page, linked from settings, by person and by resource (#18131) 3ecccb5
3 earlier comments
A visitor with no account now becomes a principal only when they make something. The one place a visitor makes something today is an app note sent from the forge button, and that is now wired to it.
What changed
- New
src/core/visitors.ts. The id is signed and lives in its ownforge_makercookie (HttpOnly, SameSite=Lax, Secure follows the https rule). The signing key is derived only for this cookie (HKDF, "forge visitor principal v1"), and ids start withv.heldVisitorreads the cookie and never mints.admitVisitorasksmayforvisitor.make, checks the caps, and mints an id only if the request holds none.countMakerecords a thing once it has actually been made.
- Principal and
may().Principalgains the kindvisitor;userOfreturns nothing for it.may()gains the actionvisitor.make: anonymous and visitors may do it, and a visitor may do nothing else beyond what anonymous may.resolveAuthsetsAuth.visitorIdonly when there is no credential. - Limits.
VISITOR_CAPSinlimits.ts: 200 things a day per visitor and 5000 a day for all visitors together. The per-visitor cap is twice what one app takes in a day (PER_APP_DAY), so the app's own limit refuses first. - App notes (
src/apps/feedback.ts). This door used to give every request, includingGET /__forge/notes, an unsignedforge_visitorcookie with the same name as the analytics cookie. Now only the 201 answer to a filed note setsforge_maker, and listing notes mints nothing. WithDNT: 1orSec-GPC: 1the note is still filed and no id is kept. - Docs.
docs/ROLES.mdanddocs/features/notes.mdsay all of this. There is no terminal side: a note sent from the terminal is always the SSH user's, never a visitor's. - Events. There is no new
bus.appendkind, soevent_audience.tsneeded no entry.
Tests I changed because they pinned the old behaviour
test/may.test.ts: anonymous capabilities now includevisitor.make.test/cookie-secure.test.ts: posts a note instead of reading the list.test/apps-feedback.test.ts: two list reads now see the name "visitor" with no minted suffix.test/cookie-flags.test.tsandtest/cookie-floor.test.ts: list the new cookie site.
test/visitors.test.ts is new and covers:
- a minted id verifies and resolves to the
visitorprincipal, not a user; - an unsigned id, an altered id or MAC, a wrong key, or an analytics value signed by this forge is refused;
- a read mints nothing;
- DNT and GPC mint no id;
- the per-visitor cap, then the per-forge cap, refuses the next make.
tsc passes, the gate shows no failures, and the 19 related test files I ran pass. I did not run the full suite.
Threat note
- Mixing the id up with analytics: the two cookies differ in name, key, id prefix and table. An analytics value signed by this forge fails verification, and the test checks that.
- Treating a visitor as a user:
userOfreturns nothing for a visitor, so every repository and forge rule treats one as anonymous (for example, commenting is refused as "unauthorized"). - Forging ids: ids are HMAC-signed and compared in constant time. Minting fresh ids gets around the per-visitor cap only until the forge-wide cap is spent.
- Cookie scope: the cookie lives on the app's host, so each app host has its own visitor id.
Left out
- Shared tab-forge apps and linked game players are allowed kinds of thing but are not wired yet; no route for them exists on the server.
- The cap is a day's count stored in SQLite, not a setting an admin can change.
- Notes filed under the old unsigned cookie stay with the builders, but they no longer show in that visitor's own list.
Reuse: the lazily created table follows run_secret.ts and client_cloud.ts. mint is deliberately not perf/visitor_id.ts mintId (the gate flags them as near-identical): sharing it would put the two ids in one namespace, which is exactly the mix-up this issue rules out.
Try: open a public app's page on the preview and open the forge button's list; no cookie is set. Send a note; the 201 answer sets forge_maker, and the list then shows that note.
[{"go":"a public app's page on the preview","look":"open the forge button's notes list, then the response headers","expect":"no Set-Cookie on GET /__forge/notes"},{"go":"the same page","look":"send a note from the forge button","expect":"201 with Set-Cookie forge_maker=v…; HttpOnly; the list now shows the note"}]
🤖 Generated with Claude Code
Access 5a adds a visitor principal: a person with no account gets a signed forge_maker id only when they make something, and the id is counted against a cap per visitor and one per forge. It is checked through may as visitor.make (src/core/visitors.ts), and app notes are the first thing that mints it.
This push fixes the check's 500 in test/outsiders-member.test.ts. resolveAuth read the secret key on every request with no credential, just to look for the maker cookie. That test writes secret.key with mode 644 on purpose, and from then on loadKey threw on every such request. heldVisitor now takes the key as a function and reads it only once a well-formed forge_maker cookie is there, so a request with no cookie never touches the key file. A new test in test/visitors.test.ts makes sure the key isn't read for a missing cookie, someone else's cookie or a malformed one.
Test changed: in test/visitors.test.ts, the caps test's setup of about 5,000 makes now runs in one transaction. It ran just past bun's 5-second timeout in my sandbox, whether or not this push's fix was applied, and did not fail in the check.
Not reproduced: the other failure in the check, "plan carries the template only when it is not blank" in test/spawn-template-api.test.ts, passes on its own and alongside outsiders-member. It runs no visitor code, so I made no change for it; the next check will show whether it was related.
Checks run: tsc --noEmit and the gate pass, and so do the eight test files nearest the change (visitors, outsiders-member, spawn-template-api, apps-feedback, cookie-flags, cookie-floor, cookie-secure, may). The full suite is left to the forge's check, since scripts/fast.ts named 4,162 files.
Try it: with no credential, / answers 200 even when secret.key has the wrong mode. Make a note in an app without signing in: the answer sets forge_maker, and later requests from that browser resolve to a visitor principal.
🤖 Generated with Claude Code
Access 5a adds a visitor principal: a person with no account becomes someone the forge knows only when they make something. For now that means filing a note on an app's page. They get a signed id in their own forge_maker cookie. It uses its own key (HKDF, "forge visitor principal v1"), is checked in constant time, and is never the analytics forge_visitor id. Nothing is minted when the browser sends DNT: 1 or Sec-GPC: 1 (src/core/visitors.ts).
A request with a valid id is the principal visitor. userOf returns no user for it, and may lets it do what anonymous may plus visitor.make. A request whose credential matched nothing gets no visitor.make.
VISITOR_CAPS in src/http/limits.ts sets the daily limits on what visitors can make:
- 200 per visitor id.
- 200 per connection (
clientBucket). A client that drops its cookie gets a fresh id each time, so the per-visitor cap never binds it; this one does. Without it, one client could spend the whole forge's cap and lock every other visitor out. - 5000 for all visitors on the forge together.
Only notes that were actually filed count toward the caps.
What to look at:
- Key file reads: the secret key is read only when a well-formed maker cookie is present, in
resolveAuthand in the notes list, picture and send. Before this, every request with no credential read the key file, so a key with the wrong mode made those requests fail with 500. That was the cause of the earlier red check intest/outsiders-member.test.ts. - Stored data: the
visitor_madetable holds the visitor id, the socket's client and the time. It has nokindcolumn, because nothing read it. - Old cookie: a visitor holding only the old unsigned
forge_visitornote cookie no longer sees their earlier notes in the list. The notes are still filed for the builders.docs/features/notes.mdsays so; the old cookie is not accepted for reads because it is unsigned.
Threat note:
- Mixing ids: a visitor id can't be mixed up with the analytics id: they share no key, no format prefix and no table.
- Treated as a user: a visitor is never treated as a user, because
userOfreturns none. - Forged or altered ids: these are refused, and a request carrying one is admitted as a new visitor, never as the one it copies.
Not done here: an app made and shared in the tab forge (#18188) and a linked game player (#18189) do not mint the principal yet. Both are open issues waiting on this one.
Tests:
test/visitors.test.ts:- a minted id verifies;
- unsigned, altered or analytics ids are refused;
- a read mints nothing;
- DNT/GPC mint nothing;
- each of the three caps refuses the next make;
- the key is read only when a maker cookie is present.
test/apps-feedback.test.ts: a notes list read with no maker cookie never callsloadKey; this test fails without the fix.
In test/visitors.test.ts, the caps test builds its thousands of setup rows in one transaction, because separate commits ran past bun's 5-second timeout on a slow disk. The test file has tsc --noEmit, the gate, the unused-exports and module-state guards, and the eight test files nearest the change all pass. The full suite is left to the forge's check.
The other failure in that earlier check, "plan carries the template only when it is not blank" in test/spawn-template-api.test.ts, passes on its own and together with outsiders-member. It runs no visitor code, so it is unchanged.
How to try it: open an app's page without signing in and send a note from the forge button. That answer, and no earlier one, sets forge_maker, and the button's list then shows the note. The 201st note in a day from one connection is answered with 429.
🤖 Generated with Claude Code
Adds a visitor principal: a person with no account can now make something as a visitor through the new visitor.make action. This merges current main, which had added forge.write to the permission registry.
What changed
src/core/visitors.tscreates the visitor ID.src/core/may.tsgivesvisitor.maketo visitors and to anonymous callers who haven't been refused. Signed-in accounts don't get it.src/http/limits.tscaps visitors by connection as well as by ID.- The secret key is read only when a maker cookie is present, so a request with no credential never touches it.
- The cookie floor test names the visitor ID line that the note response is allowed to set.
Merge conflict: test/may.test.ts conflicted on what each caller may do. The resolution keeps both sides: no account gives ["forge.read", "visitor.make"], and signed-in accounts now also list forge.write, as on main.
Checks: bun x tsc --noEmit passes, and the gate passes. scripts/fast.ts selected 4,167 test files, far over its 5-minute budget, so I ran only the 59 files around may, limits, visitors, access and cookies: 401 pass, 0 fail, 4 skipped. The full check runs on this push.
Left out: the gate notes that core/visitors.ts#mint is identical to perf/visitor_id.ts#mintId, and that core/visitors.ts#table is close to core/client_cloud.ts#tables. The notes are advisory and I didn't merge either pair here.
To try it: with no session, GET /api/v1/user on the preview should list visitor.make. A signed-in token should not have it.
🤖 Generated with Claude Code
A visitor with no account now becomes a principal only when they make something. The one place a visitor makes something today is an app note sent from the forge button, and that is now wired to it.
What changed
src/core/visitors.ts. The id is signed and lives in its ownforge_makercookie (HttpOnly, SameSite=Lax, Secure follows the https rule). The signing key is derived only for this cookie (HKDF, "forge visitor principal v1"), and ids start withv.heldVisitorreads the cookie and never mints.admitVisitorasksmayforvisitor.make, checks the caps, and mints an id only if the request holds none.countMakerecords a thing once it has actually been made.may().Principalgains the kindvisitor;userOfreturns nothing for it.may()gains the actionvisitor.make: anonymous and visitors may do it, and a visitor may do nothing else beyond what anonymous may.resolveAuthsetsAuth.visitorIdonly when there is no credential.VISITOR_CAPSinlimits.ts: 200 things a day per visitor and 5000 a day for all visitors together. The per-visitor cap is twice what one app takes in a day (PER_APP_DAY), so the app's own limit refuses first.src/apps/feedback.ts). This door used to give every request, includingGET /__forge/notes, an unsignedforge_visitorcookie with the same name as the analytics cookie. Now only the 201 answer to a filed note setsforge_maker, and listing notes mints nothing. WithDNT: 1orSec-GPC: 1the note is still filed and no id is kept.docs/ROLES.mdanddocs/features/notes.mdsay all of this. There is no terminal side: a note sent from the terminal is always the SSH user's, never a visitor's.bus.appendkind, soevent_audience.tsneeded no entry.Tests I changed because they pinned the old behaviour
test/may.test.ts: anonymous capabilities now includevisitor.make.test/cookie-secure.test.ts: posts a note instead of reading the list.test/apps-feedback.test.ts: two list reads now see the name "visitor" with no minted suffix.test/cookie-flags.test.tsandtest/cookie-floor.test.ts: list the new cookie site.test/visitors.test.tsis new and covers:visitorprincipal, not a user;tscpasses, the gate shows no failures, and the 19 related test files I ran pass. I did not run the full suite.Threat note
userOfreturns nothing for a visitor, so every repository and forge rule treats one as anonymous (for example, commenting is refused as "unauthorized").Left out
Reuse: the lazily created table follows
run_secret.tsandclient_cloud.ts.mintis deliberately notperf/visitor_id.tsmintId(the gate flags them as near-identical): sharing it would put the two ids in one namespace, which is exactly the mix-up this issue rules out.Try: open a public app's page on the preview and open the forge button's list; no cookie is set. Send a note; the 201 answer sets
forge_maker, and the list then shows that note.🤖 Generated with Claude Code
Closes #18112