upstream into main
upstream adds 4 commits to main.
main has moved since upstream last had it. To merge: merge main into upstream, and push.
Sign in to open a pull.
Commits
6b92e4bcore/ of iterate/private at 3a43222d, as its public copy has it Misha Kaletsky, 2026-11-26 09:51 UTC816a6f4core/ of iterate/private at 20e3895e, as its public copy has it Misha Kaletsky, 2026-11-26 08:38 UTC23c8ccfcore/ of iterate/private at b0f5689c, as its public copy has it Misha Kaletsky, 2026-11-25 23:58 UTC0575be7core/ of iterate/private at 3de3de7d, as its public copy has it Misha Kaletsky, 2026-11-25 15:14 UTC
Files
265 files changed
- M core/alchemy/README.md
- M core/alchemy/src/config.test.ts
- M core/alchemy/src/config.ts
- M core/alchemy/src/mind-made-telemetry-tables.ts
- M core/alchemy/src/stack-bindings.test.ts
- M core/alchemy/src/stack.ts
- M core/alchemy/src/telemetry-token.ts
- M core/auth-worker/src/asking-app.test.ts
- M core/auth-worker/src/asking-app.ts
- M core/auth-worker/src/authorize.ts
- M core/auth-worker/src/config.test.ts
- M core/auth-worker/src/config.ts
- M core/auth-worker/src/cookies.ts
- M core/auth-worker/src/device/page.test.ts
- M core/auth-worker/src/device/page.ts
- M core/auth-worker/src/email-sign-in.ts
- M core/auth-worker/src/enrolment.test.ts
- M core/auth-worker/src/http.ts
- M core/auth-worker/src/members.test.ts
- M core/auth-worker/src/members.ts
- A core/auth-worker/src/mind-mark.test.ts
- A core/auth-worker/src/mind-mark.ts
- M core/auth-worker/src/mind-sign-in.test.ts
- M core/auth-worker/src/mind-sign-in.ts
- M core/auth-worker/src/oauth.test.ts
- M core/auth-worker/src/oauth.ts
- A core/auth-worker/src/owner-email-patterns.test.ts
- M core/auth-worker/src/page-tag.test.ts
- M core/auth-worker/src/pages.test.ts
- M core/auth-worker/src/pages.ts
- M core/auth-worker/src/stack-key.ts
- M core/auth-worker/src/test-support.ts
- M core/auth-worker/src/working-key.test.ts
- M core/boundary-worker/src/env.ts
- M core/boundary-worker/src/http.ts
- M core/boundary-worker/src/mail.test.ts
- M core/boundary-worker/src/mail.ts
- M core/boundary-worker/src/mind-transport.ts
- M core/boundary-worker/src/provided-mind.test.ts
- M core/boundary-worker/src/provided-mind.ts
- M core/boundary-worker/src/session-mind.ts
- M core/boundary-worker/src/stamp.ts
- M core/boundary-worker/src/worker.ts
- M core/configs/default/AGENTS.md
- M core/configs/default/agent-kinds.md
- M core/configs/default/agent-tests/processor.test.mjs
- M core/configs/default/agent/llm-apis/openai-responses.ts
- M core/configs/default/api.ts
- M core/configs/default/apps.md
- A core/configs/default/apps/dash/agent-catalog.ts
- A core/configs/default/apps/dash/framed-sign-in.ts
- M core/configs/default/apps/dash/index.html
- M core/configs/default/apps/dash/public/app.css
- M core/configs/default/apps/dash/public/app.js
- M core/configs/default/apps/dash/public/mcp-page.js
- M core/configs/default/apps/docs/index.html
- M core/configs/default/apps/docs/processors/merge.ts
- M core/configs/default/apps/docs/public/app.css
- M core/configs/default/apps/docs/public/app.js
- M core/configs/default/apps/guestbook/app.ts
- M core/configs/default/apps/guestbook/index.html
- M core/configs/default/apps/guestbook/mcp.ts
- D core/configs/default/apps/mcp/app.ts
- D core/configs/default/apps/mcp/server.ts
- M core/configs/default/apps/meet/index.html
- M core/configs/default/apps/meet/public/app.js
- M core/configs/default/apps/onboarding/app.ts
- M core/configs/default/apps/onboarding/launch.ts
- M core/configs/default/apps/onboarding/steps/connect-iterate-cloud.ts
- M core/configs/default/apps/tasks/app.ts
- A core/configs/default/apps/tasks/askers.js
- A core/configs/default/apps/tasks/askers.test.mjs
- A core/configs/default/apps/tasks/asks.js
- A core/configs/default/apps/tasks/asks.test.mjs
- A core/configs/default/apps/tasks/board.js
- A core/configs/default/apps/tasks/board.test.mjs
- A core/configs/default/apps/tasks/cards.js
- A core/configs/default/apps/tasks/cards.test.mjs
- A core/configs/default/apps/tasks/feed.js
- A core/configs/default/apps/tasks/feed.test.mjs
- M core/configs/default/apps/tasks/index.html
- M core/configs/default/apps/tasks/public/app.css
- M core/configs/default/apps/tasks/public/app.js
- M core/configs/default/apps/tasks/public/tasks-model.js
- M core/configs/default/apps/tasks/tasks-model.test.mjs
- M core/configs/default/apps/telemetry/crashes.test.mjs
- M core/configs/default/apps/telemetry/crashes.ts
- M core/configs/default/apps/telemetry/exceptions.ts
- M core/configs/default/cloud-handover.ts
- M core/configs/default/cloudflare.md
- M core/configs/default/cloudflare.ts
- M core/configs/default/context-descriptions.ts
- M core/configs/default/errors.md
- M core/configs/default/every-event.ts
- M core/configs/default/init.ts
- A core/configs/default/iterate.md
- M core/configs/default/mail-replies.md
- A core/configs/default/mcp.ts
- M core/configs/default/page-events.md
- M core/configs/default/people.md
- M core/configs/default/profile.ts
- M core/configs/default/sandboxes.md
- A core/configs/default/skills/README.md
- A core/configs/default/skills/mind-skills/SKILL.md
- A core/configs/default/tasks.md
- A core/configs/default/telemetry-query-rule.ts
- D core/configs/default/telemetry.ts
- M core/configs/default/template-updates.md
- M core/configs/default/worker.ts
- M core/configs/minimal/AGENTS.md
- M core/configs/minimal/worker.ts
- M core/home-lab/README.md
- M core/home-lab/src/link/relay.ts
- M core/home-lab/src/main.ts
- A core/home-lab/src/seed-repos.test.ts
- A core/home-lab/src/seed-repos.ts
- M core/itx/src/caller.test.ts
- M core/itx/src/caller.ts
- M core/itx/src/context/awake.ts
- M core/itx/src/context/built-ins.ts
- A core/itx/src/context/context-activity-stack.test.ts
- A core/itx/src/context/context-activity-stack.ts
- M core/itx/src/context/context-catalog.ts
- M core/itx/src/context/facet-host.ts
- M core/itx/src/context/itx-expression-rewriting.ts
- M core/itx/src/context/stateless-context.ts
- D core/itx/src/context/telemetry-query-rule.test.ts
- A core/itx/src/context/workers-mcp-call.test.ts
- D core/itx/src/context/workers-root-email.test.ts
- M core/itx/src/index.ts
- M core/itx/src/iterate-context-durable-object.ts
- M core/itx/src/iterate-context.ts
- M core/itx/src/serve-host.ts
- M core/itx/src/stream/core-events.ts
- M core/itx/src/stream/core-processor.ts
- A core/itx/src/stream/facet-push-catch-up.test.ts
- M core/itx/src/stream/stream-versions.test.ts
- M core/itx/src/stream/stream.ts
- M core/itx/src/stream/subscription-delivery.ts
- M core/lib/README.md
- M core/lib/src/agents/README.md
- M core/lib/src/agents/api.ts
- M core/lib/src/agents/catalog.test.ts
- M core/lib/src/agents/catalog.ts
- M core/lib/src/agents/collection.test.ts
- M core/lib/src/agents/collection.ts
- M core/lib/src/api.ts
- M core/lib/src/app-description.test.ts
- M core/lib/src/app-description.ts
- M core/lib/src/cause.ts
- M core/lib/src/cli/README.md
- M core/lib/src/cli/chatgpt.test.ts
- M core/lib/src/cli/chatgpt.ts
- M core/lib/src/cli/cli.ts
- M core/lib/src/cli/cloudflare-access.test.ts
- M core/lib/src/cli/cloudflare-access.ts
- M core/lib/src/cli/deploy.test.ts
- M core/lib/src/cli/deploy.ts
- M core/lib/src/cli/device-login/index.ts
- A core/lib/src/cli/mcp-clients.test.ts
- A core/lib/src/cli/mcp-clients.ts
- A core/lib/src/cli/oauth.test.ts
- M core/lib/src/cli/oauth.ts
- M core/lib/src/cli/recover.test.ts
- M core/lib/src/cli/recover.ts
- M core/lib/src/client/event-log.test.ts
- M core/lib/src/client/event-log.ts
- M core/lib/src/client/live-state.test.ts
- M core/lib/src/client/live-state.ts
- A core/lib/src/client/new-version.test.ts
- M core/lib/src/client/new-version.ts
- M core/lib/src/config-default-dash.test.ts
- M core/lib/src/config-default-docs.test.ts
- M core/lib/src/config-default-guestbook.test.ts
- M core/lib/src/config-default-handover.test.ts
- M core/lib/src/config-default-mail-replies.test.ts
- D core/lib/src/config-default-mcp.test.ts
- A core/lib/src/config-default-mind-mcp.test.ts
- M core/lib/src/config-default-mirror.test.ts
- M core/lib/src/config-default-onboarding.test.ts
- M core/lib/src/config-default-publish-hook.test.ts
- M core/lib/src/config-default-tasks.test.ts
- M core/lib/src/config-default-telemetry-query-rule.test.ts
- M core/lib/src/config-default-telemetry.test.ts
- M core/lib/src/email.ts
- M core/lib/src/integrations.ts
- M core/lib/src/lib.ts
- M core/lib/src/mind-config.test.ts
- M core/lib/src/mind-config.ts
- M core/lib/src/mind-ingress.ts
- M core/lib/src/node-renewal.test.ts
- M core/lib/src/node.ts
- M core/lib/src/sdk/auth.ts
- M core/lib/src/sdk/index.test.ts
- M core/lib/src/sdk/index.ts
- M core/lib/src/sdk/itx-scope.test.ts
- M core/lib/src/sdk/itx-scope.ts
- A core/lib/src/sdk/mcp.ts
- M core/lib/src/standalone-page.ts
- M core/lib/src/workers.ts
- A core/mind-worker/src/context/egress-upgrade.test.ts
- A core/mind-worker/src/context/fixtures/egress-upgrade.ts
- M core/mind-worker/src/context/telemetry.ts
- M core/mind-worker/src/http.ts
- D core/mind-worker/src/integrations/email-hook.test.ts
- D core/mind-worker/src/integrations/email-hook.ts
- A core/mind-worker/src/integrations/email-receive.test.ts
- M core/mind-worker/src/integrations/email.ts
- M core/mind-worker/src/library.ts
- A core/mind-worker/src/library/mcp.test.ts
- M core/mind-worker/src/library/mcp.ts
- A core/mind-worker/src/mcp-config.test.ts
- A core/mind-worker/src/mcp-skill-frontmatter.ts
- A core/mind-worker/src/mcp-skills.test.ts
- A core/mind-worker/src/mcp-skills.ts
- M core/mind-worker/src/mcp.ts
- M core/mind-worker/src/mind/contract.ts
- M core/mind-worker/src/mind/processor.test.ts
- M core/mind-worker/src/mind/processor.ts
- M core/mind-worker/src/mind/publication.ts
- M core/mind-worker/src/rpc.ts
- M core/repos/onboarding/index.html
- M core/repos/onboarding/onboarding.md
- M core/repos/onboarding/onboarding/approvals.md
- M core/repos/onboarding/onboarding/apps.md
- M core/repos/onboarding/onboarding/connect.md
- M core/repos/onboarding/onboarding/finish.md
- M core/repos/onboarding/onboarding/follow-up.md
- M core/repos/onboarding/onboarding/github.md
- M core/repos/onboarding/onboarding/instructions.md
- M core/repos/onboarding/onboarding/let-iterate-in.md
- M core/repos/onboarding/onboarding/links.md
- M core/repos/onboarding/onboarding/look.md
- M core/repos/onboarding/onboarding/mail.md
- M core/repos/onboarding/onboarding/mcp.md
- M core/repos/onboarding/onboarding/pays.md
- M core/repos/onboarding/onboarding/people.md
- M core/repos/onboarding/onboarding/reach.md
- M core/repos/onboarding/onboarding/research.md
- M core/repos/onboarding/onboarding/sandbox.md
- M core/repos/onboarding/onboarding/signed-requests.md
- M core/repos/onboarding/onboarding/speak.md
- M core/repos/onboarding/onboarding/subagents.md
- M core/repos/onboarding/onboarding/telemetry.md
- M core/repos/onboarding/onboarding/voice.md
- M core/repos/onboarding/onboarding/website.md
- M core/repos/onboarding/public/app.js
- M core/repos/onboarding/tasks/onboarding-build-an-app.md
- M core/repos/onboarding/tasks/onboarding-connect-iterate-cloud.md
- M core/repos/onboarding/tasks/onboarding-connect-mcp.md
- M core/repos/onboarding/tasks/onboarding-connect-tools.md
- M core/repos/onboarding/tasks/onboarding-devices-and-character.md
- M core/repos/onboarding/tasks/onboarding-invite-people.md
- M core/repos/onboarding/tasks/onboarding-look.md
- M core/repos/onboarding/tasks/onboarding-mail.md
- M core/repos/onboarding/tasks/onboarding-remove-onboarding-app.md
- M core/repos/onboarding/tasks/onboarding-research.md
- M core/repos/onboarding/tasks/onboarding-sandbox.md
- M core/repos/onboarding/tasks/onboarding-secrets-and-approvals.md
- M core/repos/onboarding/tasks/onboarding-telemetry.md
- M core/repos/onboarding/tasks/onboarding-voice-call.md
- M core/repos/onboarding/tasks/onboarding-website.md
- M core/repos/onboarding/worker.ts
- M core/telemetry-worker/src/rpc.ts
- M core/telemetry-worker/src/store-query.test.ts
M core/alchemy/README.md
@@ -81,48 +81,62 @@ A mind takes each of its zones whole: nothing else may use them. +`"mcpTarget": "mcp"` points the mind's own MCP server (`iterate.<zone>/mcp`) at a method of the +config worker's class: that method answers a class which gives the server its instructions, its +description of `run`, more tools and the mind's skills (`mcp.ts` of the default config). Absent, +the platform's defaults answer; and they answer too whenever the method fails, so the field +cannot break the server. `iterate deploy --mcp-target mcp` sets it, and `--mcp-target none` takes +it away. A stack built before this field refuses it. + +`"ownerEmailPatterns": ["*@company.example"]` names more owners by pattern: every address at +exactly that domain (no sub-domain) is an owner, with all that an owner may do. Such a person +proves the address through Cloudflare Access, whose policy then names the whole domain, and adds a +passkey. So whoever holds a mailbox at the domain, or runs its mail, can become an owner: name a +domain only when its mail is the company's own, and never a zone of the mind. Each person who +proves an address takes a seat of the account's Zero Trust team. A person who left keeps the +passkey that they added, whatever their mail provider does: an owner blocks that address on +`/members`, which ends that one person (no member, no session, no way back in) while the block is +there. `iterate deploy --owner-email-patterns none` takes the pattern away for everyone. A mail or a Slack message from a verified address +at the domain counts as a member's. Absent: the owners are `ownerEmails` alone. + Every Worker of the stack keeps every log line and, by default, every trace in Cloudflare's own Workers Logs. `"telemetry": { "traceSampling": 0.1 }` keeps the trace of one request in ten (from 0 to 1; Cloudflare's head sampling rate). `iterate deploy --trace-sampling 0.1` writes it, and `--trace-sampling default` goes back to every trace. On iterate.com on 21 Nov 2026, spans were about 86 % of what the store took in. -Each mail to an address at a zone reaches the mind: the boundary stores its files under the mind's -`/email/`, and a failure there fails the delivery, so Cloudflare delivers again. Then the mind's -config gets it while the delivery is live, in its `email` method (iterate/sdk -`IterateConfigEntrypoint`). There `save()` records it on `/integrations/email` (`email/received`); -a save that the mind does not take fails the delivery too. A mail is off the log only when the -config's `email` returns without saving it; when the hook throws, runs out of time or is missing, -or the mind cannot be reached for it, the boundary records the mail itself, with an -`email/hook-failed` fact beside it. `forward(to)` sends the original on, as it arrived, with Email Routing's -own forward: its From is the sender's, so a reply goes to the sender. +Each mail to an address at a zone reaches the mind: the boundary has the mind store its files +under `/email/` and append `events.iterate.com/email/received` on `/integrations/email`. A failure +there fails the delivery, so Cloudflare delivers again. No code of the mind's config runs in the +delivery: the config gets the mail as that event, in `processEvent`. To send the original on, as +it arrived, the config appends `events.iterate.com/email/forward-requested` (`{ raw, to }`) there. +The boundary's handler stays open for such requests for 10 s after the receipt, and forwards +with Email Routing's own forward: its From is the sender's, so a reply goes to the sender. - The address must be a verified destination address of the account's Email Routing: add it in the dashboard (Email Routing, Destination addresses) and confirm the link Cloudflare mails to it. -- Cloudflare forwards only a mail whose sender is proven. `forward` throws a coded error instead of - forwarding: NOT_FORWARDABLE, FORWARDED_BEFORE (a mail goes to one address once, and never to an - address that its `X-Forwarded-To` names, so an address that leads back makes no loop), REFUSED - (Cloudflare's words) or EXPIRED (after the delivery, or after the hook's time). -- Each forward is an `events.iterate.com/email/forwarded` fact. The boundary gives the hook 15 s - of its own time: the clock stops while Cloudflare answers a forward, which took 3 to 10 s on - 19 Nov 2026. A forward whose answer does not come within 20 s more is the same fact with - `answered: false`. A hook that throws, that runs past its own time, or that the mind could not - be reached for, and a config with no `email` (one fact for each config commit), are - `events.iterate.com/email/hook-failed` facts, and the boundary records the mail: the delivery - stands, unless the mind does not take that record. +- Cloudflare forwards only a mail whose sender is proven. A forward that does not happen is an + `events.iterate.com/email/forward-failed` fact with why: Cloudflare's words, or the boundary's + own, which start "not forwarded:" (a mail never goes to an address that its `X-Forwarded-To` + names, so an address that leads back makes no loop; a request that no code at the root wrote). +- Each forward is an `events.iterate.com/email/forwarded` fact, one for each mail and address. + Cloudflare answered a forward after 3 to 10 s on 19 Nov 2026. A forward whose answer does not + come within 20 s after the requests' time is the same fact with `answered: false`. +- When the 10 s are up, the mind appends `events.iterate.com/email/forward-requests-closed` for + the mail. A request on the log before that fact is served; one after it gets no answer: the + message is gone. Nothing + that the config does or fails to do fails a delivery. **The older way, which goes:** with `"mail": { "forwardTo": "team@example.org" }` the boundary -forwards each mail there itself, before the config's hook and through the same forward, so the -hook cannot forward the same mail there again. Such a stack records every mail on the log before -its forward, whatever its config's hook does: a record after the forward could fail the delivery -after the copy went, and the redelivery would forward a second copy; and a refused forward fails -the delivery before the hook runs, which must not cost the mail its place on the log. The config refuses an address at a zone of the +forwards each mail there itself, before the mind's requests and through the same forward, so a +request for that address forwards nothing more. A refused forward fails the delivery after the +mail is on the log. The config refuses an address at a zone of the mind: its mail would come back. Each forward that fails is an `events.iterate.com/email/forward-failed` fact, with Cloudflare's words; a mail whose sender is not proven stays in the mind alone, and the delivery stands. **The cost of a forward address that does not work:** while the address is not verified, is removed from the account, or refuses mail, every mail to the mind fails for its sender: the mind keeps the mail, the delivery fails, the sender gets -it back, and the config's hook does not run. A mind's config forwards in its own `email` instead. +it back. A mind's config asks for its forwards by event instead. `mindId` is the SHA-256 of the mind's signed genesis record (`iterate/mind-identity`). The stack signs and checks nothing with it: every Worker gets it as config, and the auth Worker accepts the @@ -161,10 +175,11 @@ - **`given`:** the state holds `TelemetryToken`, an owner-created token: the stack keeps using it. **Do not delete or roll it:** the sinks keep the token they were made with. - **`off`:** neither. The stack makes the telemetry bucket, the three streams and the OTLP - destinations, and no catalog, sink, pipeline or token. The mind makes and reads its tables - itself, with a token kept as its secret `/secrets/cloudflare-telemetry` - (core/configs/default/telemetry.ts); the streams keep what they are sent until then. A - destroy removes what the mind made (`src/mind-made-telemetry-tables.ts`). + destinations, and no catalog, sink, pipeline or token. The stack has no `events`, `logs` or + `spans` table: its mind reads Cloudflare's own datasets and `metrics` through + `itx.telemetry.query`, with no token. Until 25 Nov 2026 a mind could turn its tables on with + a member's token: a destroy removes what such a mind made + (`src/mind-made-telemetry-tables.ts`). - The deploy makes a Realtime SFU app and a TURN key (`src/realtime.ts`), which need the permission to make Realtime (Calls) resources: "Calls Write" (`calls.write`), which the deploy asks for, or "Realtime" or "Realtime Admin". A credential without it is no failure either: the deploy makes neither,
M core/alchemy/src/config.test.ts
@@ -125,6 +125,29 @@ ]); }); +void test("owner email patterns are optional, each *@<domain>, and at no zone of the mind", () => { + assert.equal(MindConfig.parse(config()).ownerEmailPatterns, undefined); + assert.deepEqual( + MindConfig.parse({ ...config(), ownerEmailPatterns: ["*@company.example"] }).ownerEmailPatterns, + ["*@company.example"], + ); + for (const pattern of [ + "*@*", + "company.example", + "ada@company.example", + "*@Company.example", + // the mind's own zones, and a name under one + "*@example.com", + "*@mail.sub.example.net", + ]) + assert.deepEqual( + MindConfig.safeParse({ ...config(), ownerEmailPatterns: [pattern] }).error?.issues[0] + ?.path[0], + "ownerEmailPatterns", + pattern, + ); +}); + function config() { return { mindId: "a".repeat(64),
M core/alchemy/src/config.ts
@@ -2,6 +2,7 @@ // the person and from Cloudflare. A JSON file, named in ITERATE_MIND_CONFIG. No field is optional // for a reason of history, and no variable of the environment changes what it means. import { readFileSync } from "node:fs"; +import { domainOfOwnerEmailPattern, OwnerEmailPattern } from "iterate/mind-config"; import { z } from "zod"; const hostname = z @@ -22,6 +23,18 @@ * with a code mailed to that address and then adds a passkey. An owner may remove another * member's passkeys. Members added later are in the mind, not here. */ ownerEmails: z.array(z.email().toLowerCase()).min(1), + /** MORE OWNERS, BY PATTERN: each `*@<domain>` makes every address at exactly that domain an + * owner, with all that an owner may do (iterate/mind-config `isOwnerEmail`). Such a person + * proves the address through Cloudflare Access, as any owner does, and then adds a passkey: + * so whoever holds a mailbox at the domain, or runs its mail, can become an owner. Name a + * domain only when its mail is the company's own. A person who left keeps the passkey they + * added: an owner's block of that address on `/members` ends that one person + * (core/auth-worker/src/members.ts `isMember`). Absent: no pattern. */ + ownerEmailPatterns: z.array(OwnerEmailPattern).optional(), + /** The method of the config worker's class that answers the mind's part of its own MCP + * server (iterate/mind-config `mcpTarget`): "mcp" in the default config. Absent: the + * platform's defaults answer. */ + mcpTarget: z.string().optional(), /** Where the mind Worker runs: in the stack, or elsewhere, connecting in through the * boundary. */ topology: z.enum(["full-cloudflare", "external-mind-connects-into-cloudflare-boundary"]), @@ -52,10 +65,10 @@ * Absent: no binding, and the platform's fetch sends. */ egressGatewayWorker: z.string().min(1).optional(), }), - /** A FORWARD BY THE STACK, beside the config's own `email` method (iterate/sdk), where a - * mind's config forwards. Absent: the config's `email` alone decides where a mail goes. `forwardTo`: - * each mail is also forwarded there as it arrived (a team's mailbox or group), before the - * config's `email` runs. The address must be a verified destination address of the + /** A FORWARD BY THE STACK, beside the forwards that the mind's config asks for by event + * (iterate/email `email/forward-requested`). Absent: the config's requests alone decide + * where a mail goes. `forwardTo`: each mail is also forwarded there as it arrived (a team's + * mailbox or group), before the config's requests. The address must be a verified destination address of the * account's Email Routing, which a person confirms once by the link Cloudflare mails to it. */ mail: z.strictObject({ forwardTo: z.email() }).optional(), /** THE MIND'S TELEMETRY in Cloudflare's own store. `traceSampling` is the share of requests @@ -87,6 +100,18 @@ { path: ["ownerEmails"], error: "no address at a zone of the mind: the mind takes that mail", + }, + ) + .refine( + ({ ownerEmailPatterns, cloudflare }) => + (ownerEmailPatterns || []).every((pattern) => + cloudflare.zones.every( + (zone) => !`.${domainOfOwnerEmailPattern(pattern)}`.endsWith(`.${zone}`), + ), + ), + { + path: ["ownerEmailPatterns"], + error: "no pattern at a zone of the mind: the mind takes that mail", }, ) .refine(
M core/alchemy/src/mind-made-telemetry-tables.ts
@@ -1,9 +1,10 @@ // mind-made-telemetry-tables.ts — THE TELEMETRY TABLES THAT A MIND MADE ITSELF, AS A RESOURCE. A -// stack with no telemetry token makes the bucket and the streams, and the mind's own code makes -// the catalog, the sinks and the pipelines (core/configs/default/telemetry.ts). This resource makes -// nothing. Its delete removes what the mind made, with the deploy's own credential: the pipelines, -// then the sinks, then the catalog with its tables. It reads the bucket's and the streams' names -// from their resources, so a destroy runs it before they go. +// stack with no telemetry token makes the bucket and the streams. The mind's own code, with a +// token of the account that a member gave it, may have made the catalog, the sinks and the +// pipelines on them; the default config has no code that makes them. This resource makes +// nothing. Its delete removes what the mind made, with the deploy's own credential: the +// pipelines, then the sinks, then the catalog with its tables. It reads the bucket's and the +// streams' names from their resources, so a destroy runs it before they go. import type * as Cloudflare from "@alchemy.run/cloudflare"; import * as pipelines from "@distilled.cloud/cloudflare/pipelines"; import * as catalog from "@distilled.cloud/cloudflare/r2-data-catalog";
M core/alchemy/src/stack-bindings.test.ts
@@ -102,6 +102,8 @@ observability: Record<string, any>; /** each Access application's name, by its logical id */ accessNames: Record<string, string>; + /** whom each Access application's policies include, by its logical id */ + accessIncludes: Record<string, unknown[]>; }; /** Each Worker's bindings and declared resources, as the program declares them for one config. */ @@ -158,7 +160,15 @@ .filter((r) => r.Type === "Cloudflare.Access.Application") .map((r) => [r.LogicalId, r.Props.name]), ); - return { workers, resources, texts, observability, accessNames }; + const accessIncludes = Object.fromEntries( + Object.values(stack.resources) + .filter((r) => r.Type === "Cloudflare.Access.Application") + .map((r) => [ + r.LogicalId, + (r.Props.policies as { include: unknown[] }[]).flatMap((policy) => policy.include), + ]), + ); + return { workers, resources, texts, observability, accessNames, accessIncludes }; }); void test("each Worker of the stack holds what stack-bindings.snapshot.json says", async () => { @@ -200,6 +210,34 @@ assert.deepEqual(accessNames, { OwnerEmailProof: "iterate.example.com" }); }); +// Cloudflare mails a code to an owner alone. An owner email pattern adds its whole domain to +// that policy, and each Worker's config; a stack with no pattern, or an empty list, has neither. +void test("an owner email pattern adds its domain to the Access policy and to each Worker's config, and a stack with none is as it was", async () => { + const config = CASES["full-cloudflare, no mail forward"]; + const owner = { email: "owner@owner.example" }; + for (const ownerEmailPatterns of [undefined, []]) { + const { accessIncludes, texts } = await declared({ ...config, ownerEmailPatterns }); + assert.deepEqual(accessIncludes, { OwnerEmailProof: [owner] }); + assert.doesNotMatch(texts.Boundary!.ITERATE!, /ownerEmailPatterns/); + } + const { accessIncludes, texts } = await declared({ + ...config, + ownerEmailPatterns: ["*@company.example", "*@second.example"], + }); + assert.deepEqual(accessIncludes, { + OwnerEmailProof: [ + owner, + { emailDomain: { domain: "company.example" } }, + { emailDomain: { domain: "second.example" } }, + ], + }); + for (const worker of ["Secrets", "Boundary"]) + assert.deepEqual(JSON.parse(texts[worker]!.ITERATE!).ownerEmailPatterns, [ + "*@company.example", + "*@second.example", + ]); +}); + // A STACK THAT NAMES NO GATEWAY IS AS IT WAS BEFORE THE GATEWAY'S FIELD EXISTED. Its config // variables are written out here character by character: a marker or a new key there would // change every mind. Its bindings are read from the declaration and never from the snapshot @@ -340,7 +378,7 @@ assert.equal(minted.resources.TelemetryTablesOfTheMind, undefined); // Off mode binds the three streams and declares the bucket, the streams and the destinations, - // and no token, catalog, sink or pipeline: the mind can make those itself + // and no token, catalog, sink or pipeline assert.deepEqual(off.workers.Telemetry, [ "ANALYTICS:analytics", "EVENTS:Cloudflare.Pipelines.Stream Telemetry_events_stream",
M core/alchemy/src/stack.ts
@@ -18,8 +18,8 @@ // // The stack generates four keys (three with an external mind) and keeps one owner-created // telemetry API token in state, when it is given one. With a token it makes the telemetry -// tables; with none it makes their bucket and streams, and the mind can make the tables itself -// with a secret of its own (core/configs/default/telemetry.ts). It makes no OAuth client: a +// tables; with none it makes their bucket and streams and no tables, and the mind reads +// Cloudflare's own datasets and `metrics` through `itx.telemetry.query`. It makes no OAuth client: a // member connects the mind to the account through Cloudflare's MCP server, for which the mind is // its own client (core/configs/default/cloudflare.ts). // An owner signs in first with a code mailed to their address, by the mind or by Cloudflare @@ -28,12 +28,14 @@ import { relative, resolve } from "node:path"; import * as Cloudflare from "@alchemy.run/cloudflare"; import * as Alchemy from "alchemy"; +import { adopt } from "alchemy/AdoptPolicy"; import * as Output from "alchemy/Output"; import * as Config from "effect/Config"; import * as ConfigProvider from "effect/ConfigProvider"; import * as Effect from "effect/Effect"; import * as Redacted from "effect/Redacted"; import { COMPATIBILITY_DATE } from "iterate/compatibility-date"; +import { domainOfOwnerEmailPattern } from "iterate/mind-config"; import { z } from "zod"; import { AccessTeam } from "./access-team.ts"; import { ArtifactsNamespace } from "./artifacts-namespace.ts"; @@ -67,6 +69,10 @@ controlPlaneHostname: config.controlPlaneHostname, zones: config.cloudflare.zones, ownerEmails: config.ownerEmails, + // absent with no pattern: JSON leaves it out, so such a mind's variable is as it was + ownerEmailPatterns: config.ownerEmailPatterns?.length ? config.ownerEmailPatterns : undefined, + // absent when the deploy names none: the platform's own MCP defaults answer + mcpTarget: config.mcpTarget || undefined, topology: config.topology, }); /** A stream's fields, as a file of core/telemetry-worker/schemas lists them. */ @@ -100,8 +106,8 @@ // - "given": one owner-created TelemetryToken kept in state. // A deploy takes no new token, so a stack's mode never changes from "off". // - "off": no token. The bucket, the streams and the OTLP destinations are made, and no - // catalog, sink or pipeline: the mind can make those itself, with a secret of its own - // (core/configs/default/telemetry.ts). A stream with no pipeline keeps what it is sent, + // catalog, sink or pipeline. A destroy removes the ones that the mind's own code made + // (./mind-made-telemetry-tables.ts). A stream with no pipeline keeps what it is sent, // and a pipeline made later writes it into the table (measured on 20 Nov 2026). const telemetryBucket = yield* Cloudflare.R2.Bucket("TelemetryBucket", { name: names.telemetryBucket, @@ -300,8 +306,9 @@ // ── Cloudflare Access proves an owner's address: one application, at one path ── // An owner with no passkey yet opens that path. Cloudflare mails a code to the address, from // its own domain, and then signs a token that names the address. The auth Worker checks the - // token itself (core/auth-worker/src/access-sign-in.ts). The policy names the owners alone: - // nobody else gets a code, so no other person ever takes a seat of the account's team. + // token itself (core/auth-worker/src/access-sign-in.ts). The policy names the owners alone, + // each by address, and every address at the domain of an owner email pattern: nobody else + // gets a code, so no other person ever takes a seat of the account's team. // Its name is the control plane's hostname: Cloudflare's code page says "Log in to <name>" // to the owner. A new name changes the application in place, and its `aud` stays. const accessTeam = yield* AccessTeam("AccessTeam"); @@ -321,7 +328,12 @@ { name: "owners", decision: "allow", - include: config.ownerEmails.map((email) => ({ email })), + include: [ + ...config.ownerEmails.map((email) => ({ email })), + ...(config.ownerEmailPatterns || []).map((pattern) => ({ + emailDomain: { domain: domainOfOwnerEmailPattern(pattern) }, + })), + ], require: [{ loginMethod: accessTeam.pinLoginId }], }, ], @@ -575,17 +587,25 @@ script: boundary.workerName, }); } - const routing = yield* Cloudflare.Email.Routing(`EmailRouting-${zoneName}`, { + // The catch-all first, and Email Routing after it (it takes the zone from the catch-all, + // so Alchemy waits): Cloudflare publishes the zone's MX records when routing is turned + // on, and the boundary must be the handler by then. A zone that leaves goes the other way + // round: routing off, then the catch-all back as it was. Cloudflare takes a catch-all + // rule while routing is off (measured on a dev zone, 25 Nov 2026). + const catchAll = yield* Cloudflare.Email.CatchAll(`EmailCatchAll-${zoneName}`, { zone: zone.id, - }); - yield* Cloudflare.Email.CatchAll(`EmailCatchAll-${zoneName}`, { - zone: routing.zoneId, actions: [{ type: "worker", value: [boundary.workerName] }], }); + yield* Cloudflare.Email.Routing(`EmailRouting-${zoneName}`, { zone: catchAll.zoneId }); + // A mind takes each of its zones whole. So a sending domain that the zone has already + // (its owner turned Email Sending on in the dashboard) is taken over as it is, with its + // DKIM key and its return-path records, and it is the stack's from then on: it is + // deleted when the zone leaves the config, and at a destroy. Without `adopt`, Alchemy + // refuses a sending domain that it did not make, and the plan fails. const sending = yield* Cloudflare.Email.SendingSubdomain(`EmailSending-${zoneName}`, { zoneId: zone.id, name: zoneName, - }); + }).pipe(adopt(true)); // What became of a sent mail that did not arrive. Cloudflare refuses the subscription // until the zone is a sending domain, so its source waits for Email Sending, and a zone // whose DNS checks did not pass in time stops the deploy here, by its name.
M core/alchemy/src/telemetry-token.ts
@@ -1,7 +1,8 @@ // telemetry-token.ts — THE TELEMETRY TOKEN THAT A STACK ALREADY KEEPS IN STATE. A stack whose // tables an earlier deploy made with a token keeps that token: its Pipelines catalog sinks keep -// the token they were made with. A deploy takes no new token: a mind turns its tables on itself -// (core/configs/default/telemetry.ts). The mode is read from the stack's state alone. +// the token they were made with. A deploy takes no new token, so a stack with none has no +// telemetry tables: its mind reads Cloudflare's own datasets and `metrics` through +// `itx.telemetry.query`. The mode is read from the stack's state alone. // // `AccountApiTokenDeleteFallbackProvider` wraps Alchemy's `AccountApiTokenProvider` so deleting // an `AccountApiToken` resource succeeds even with a deploy sign-in that lacks API-token write @@ -45,7 +46,8 @@ * analytics token, which nothing reads since 22 Nov 2026, is not declared: a deploy deletes it. * - `"given"`: state holds `TelemetryToken` — use that one owner-created token. * - `"off"`: neither — the bucket and the streams are made, and no token, catalog, sink or - * pipeline: the mind can make those itself (./mind-made-telemetry-tables.ts). */ + * pipeline. A destroy removes the ones that the mind's own code made + * (./mind-made-telemetry-tables.ts). */ export type TelemetryMode = "minted" | "given" | "off"; const isLiveResource = (persisted: PersistedState | undefined): persisted is ResourceState => @@ -92,7 +94,7 @@ output ? Effect.succeed({ value: output.value }) : Effect.die( - "This stack holds no telemetry token in its state, and a deploy takes no new one: a mind turns its telemetry tables on itself (onboarding/telemetry.md of /repos/onboarding).", + "This stack holds no telemetry token in its state, and a deploy takes no new one: the stack has no telemetry tables, and its mind reads Cloudflare's own datasets and metrics through itx.telemetry.query (onboarding/telemetry.md of /repos/onboarding).", ), // The token was created by the person in Cloudflare's dashboard, not by the deploy. delete: () => Effect.void,
M core/auth-worker/src/asking-app.test.ts
@@ -2,7 +2,17 @@ // and what the sign-in pages then show. import type { SignInMethod } from "iterate/principal"; import { expect, test, vi } from "vitest"; -import { appOf, appTile, askingAppOf, saidIn, signInOf } from "./asking-app.ts"; +import { isOwnerEmail } from "iterate/mind-config"; +import { + allowedEmailsWords, + appOf, + appTakes, + appTile, + askingAppOf, + saidIn, + signInOf, + takesAddress, +} from "./asking-app.ts"; import { emailSignInResponse } from "./email-sign-in.ts"; import type { Env } from "./env.ts"; import { hostCallbackOf, hostClientOf, oauthHelpers } from "./oauth.ts"; @@ -41,6 +51,7 @@ icon: `${ORIGIN}/icon.svg`, members: false, signIn: FOR_ANYONE, + allowedEmails: null, }); // a path on the host is the host, as the authorization endpoint reads it expect(await askingAppOf(stack.env, next({ resource: `${ORIGIN}/mcp` }))).toMatchObject({ @@ -65,7 +76,13 @@ expect(await askingAppOf(stack.env, forged)).toBeNull(); }); -const NOTHING = { name: null, icon: null, members: false, signIn: FOR_ANYONE }; +const NOTHING = { + name: null, + icon: null, + members: false, + signIn: FOR_ANYONE, + allowedEmails: null, +}; test.for([ { @@ -115,37 +132,99 @@ said: { name: "Guestbook", signIn: ["email"] }, }, { + name: "the addresses and the patterns that a mailed code signs in, each once and in lowercase", + description: { + name: "Shop", + allowedEmails: ["Eve@Elsewhere.test", "eve@elsewhere.test"], + allowedEmailPatterns: ["*@example.com", "*@second.example", "*@example.com"], + }, + said: { + name: "Shop", + allowedEmails: { + emails: ["eve@elsewhere.test"], + patterns: ["*@example.com", "*@second.example"], + }, + }, + }, + { + name: "addresses alone, and patterns alone", + description: { name: "Shop", allowedEmails: ["eve@elsewhere.test"] }, + said: { name: "Shop", allowedEmails: { emails: ["eve@elsewhere.test"], patterns: [] } }, + }, + { + name: "patterns alone", + description: { name: "Shop", allowedEmailPatterns: ["*@example.com"] }, + said: { name: "Shop", allowedEmails: { emails: [], patterns: ["*@example.com"] } }, + }, + { name: "what a browser's manifest would say is passed over", description: { name: "Guestbook", short_name: "Book", icons: [{ src: "/other.svg" }] }, said: { name: "Guestbook" }, }, - // a text that is no description says nothing at all: the app is its host, for anyone + // a JSON object that is no description is wrong, and is not the app's word (null): the issuer + // keeps what the app last said { name: "a method that this issuer does not know", description: { name: "G", signIn: ["email", "google"] }, - said: {}, + said: null, }, - { name: "an empty list of methods", description: { name: "G", signIn: [] }, said: {} }, - { name: "methods that are no list", description: { name: "G", signIn: "email" }, said: {} }, { + // a restriction that this issuer does not read is never dropped: the last policy stays + name: "a list of domains, which this issuer does not read", + description: { name: "G", emailDomains: ["example.com"] }, + said: null, + }, + { + name: "an empty list of patterns", + description: { name: "G", allowedEmailPatterns: [] }, + said: null, + }, + { name: "an empty list of addresses", description: { name: "G", allowedEmails: [] }, said: null }, + { + name: "an address that is none", + description: { name: "G", allowedEmails: ["example.com"] }, + said: null, + }, + // a pattern is `*@<domain>` in lowercase and nothing else, as an owner email pattern + ...["example.com", "@example.com", "*@*.example.com", "*@Example.com", "a*@example.com"].map( + (pattern) => ({ + name: `a pattern that is none: ${pattern}`, + description: { name: "G", allowedEmailPatterns: [pattern] }, + said: null, + }), + ), + { name: "an empty list of methods", description: { name: "G", signIn: [] }, said: null }, + { name: "methods that are no list", description: { name: "G", signIn: "email" }, said: null }, + { name: "any other word than 'members'", description: { name: "Dash", for: "everyone" }, - said: {}, + said: null, }, { name: "an icon that is no path", description: { name: "G", icon: "https://elsewhere.test/logo.png" }, - said: {}, + said: null, }, - { name: "no name", description: { icon: "/icon.svg", signIn: ["passkey"] }, said: {} }, - { name: "a name that is no text", description: { name: 7 }, said: {} }, + { name: "no name", description: { icon: "/icon.svg", signIn: ["passkey"] }, said: null }, + { name: "a name that is no text", description: { name: 7 }, said: null }, + // a text that is no JSON object says nothing at all: the app is its host, for anyone { name: "not an object", description: ["Guestbook"], said: {} }, ])("what an app's description says: $name", ({ description, said }) => { - expect(saidIn(JSON.stringify(description), DESCRIPTION)).toEqual({ ...NOTHING, ...said }); + expect(saidIn(JSON.stringify(description), DESCRIPTION)).toEqual(said && { ...NOTHING, ...said }); }); -test("a description that is no JSON, is empty or is too long says nothing", () => { - for (const text of ["", "<!doctype html>", `{"name":"${"x".repeat(20_000)}"}`]) +test("a JSON object that broke off, or that is too long to read, is no word of the app", () => { + const long = JSON.stringify({ + name: "Shop", + allowedEmailPatterns: Array.from({ length: 2000 }, (_, n) => `*@shop-${n}.example.com`), + }); + expect(long.length).toBeGreaterThan(20_000); + for (const text of ['{"name":"Shop","allowedEmailPatterns":["*@exam', " {", "{<", long]) + expect(saidIn(text, DESCRIPTION), text.slice(0, 40)).toBeNull(); +}); + +test("a text that is no JSON object, of any length, or that is empty says nothing", () => { + for (const text of ["", "<!doctype html>", `<!doctype html>${"x".repeat(20_000)}`]) expect(saidIn(text, DESCRIPTION)).toEqual(NOTHING); }); @@ -162,6 +241,7 @@ icon: `${ORIGIN}/icon.svg`, members: false, signIn: ["passkey"], + allowedEmails: null, }); expect(await appOf(stack.env, ORIGIN)).toEqual(app); // the one address that is asked: no web app manifest is read @@ -212,6 +292,7 @@ icon: `${ORIGIN}/icon.svg`, members: true, signIn: FOR_MEMBERS, + allowedEmails: null, }); expect(stack.askedAgainIn(HOST, before)).toBe("1 minute"); // and the client that the list of sign-ins reads still names the app @@ -222,6 +303,103 @@ }, ); +test("a row that an issuer kept with a list of domains is read as the patterns of those domains, and never as any address, also while the app does not answer", async () => { + const stack = stackWith({}); + const key = `iterate-app-description:${HOST}`; + const row = (askAfter: number) => + JSON.stringify({ + name: "Shop", + icon: null, + members: false, + signIn: FOR_ANYONE, + emailDomains: ["example.com"], + askAfter, + }); + const patterns = { emails: [], patterns: ["*@example.com"] }; + // not due yet: the row is read as it is, and the app is not asked + await stack.env.OAUTH_KV.put(key, row(Date.now() + 60_000)); + { + using web = answers({ name: "Shop" }); + const app = (await appOf(stack.env, ORIGIN))!; + expect(app).toMatchObject({ allowedEmails: patterns }); + expect(takesAddress(app, "eve@example.com")).toBe(true); + expect(takesAddress(app, "eve@elsewhere.test")).toBe(false); + expect(web).toMatchObject({ asked: [] }); + } + // due, and the app does not answer: it is what the row said, in this issuer's shape + await stack.env.OAUTH_KV.put(key, row(0)); + { + const spy = vi + .spyOn(globalThis, "fetch") + .mockImplementation(async () => new Response("down", { status: 503 })); + using _down = { [Symbol.dispose]: () => spy.mockRestore() }; + expect(await appOf(stack.env, ORIGIN)).toMatchObject({ allowedEmails: patterns }); + expect(JSON.parse((await stack.env.OAUTH_KV.get(key))!)).toMatchObject({ + allowedEmails: patterns, + }); + } + // due, and the app still answers with its list of domains: the row's restriction stays + stack.due(HOST); + { + using _web = answers({ name: "Shop", emailDomains: ["example.com"] }); + const before = Date.now(); + expect(await appOf(stack.env, ORIGIN)).toMatchObject({ allowedEmails: patterns }); + expect(stack.askedAgainIn(HOST, before)).toBe("1 minute"); + } + // due, and the app answers with its list in this issuer's fields: that is what it is + stack.due(HOST); + using _web = answers({ name: "Shop", allowedEmails: ["eve@elsewhere.test"] }); + expect(await appOf(stack.env, ORIGIN)).toMatchObject({ + allowedEmails: { emails: ["eve@elsewhere.test"], patterns: [] }, + }); +}); + +test("an app whose description is wrong is still what it last said, and is asked again after a minute; one that the issuer never heard takes the passkey alone until it says", async () => { + const stack = stackWith({}); + { + using _web = answers({ name: "Shop", allowedEmailPatterns: ["*@example.com"] }); + await appOf(stack.env, ORIGIN); + } + stack.due(HOST); + const policyOf = async (origin: string) => { + const app = (await appOf(stack.env, origin))!; + return { signIn: app.signIn, allowedEmails: app.allowedEmails }; + }; + { + // a list that is not whole, in a description that is otherwise right + using _web = answers({ name: "Shop", for: "members", allowedEmailPatterns: ["@example.com"] }); + const before = Date.now(); + expect(await policyOf(ORIGIN)).toEqual({ + signIn: FOR_ANYONE, + allowedEmails: { emails: [], patterns: ["*@example.com"] }, + }); + expect(stack.askedAgainIn(HOST, before)).toBe("1 minute"); + } + // NOTHING IS KEPT OF THESE: the app's first answer is wrong, or it does not answer. The issuer + // mails no code and takes no mailed code's session for an app that it has not heard. + for (const [n, answer] of [ + () => Response.json({ name: "Shop", allowedEmailPatterns: ["@example.com"] }), + () => new Response("down", { status: 503 }), + () => new Response("too many requests", { status: 429 }), + () => new Response('{"name":"Shop","allowedEmailPatterns":["*@exam'), + () => Promise.reject(new Error("no answer")), + ].entries()) { + const spy = vi.spyOn(globalThis, "fetch").mockImplementation(async () => answer()); + using _down = { [Symbol.dispose]: () => spy.mockRestore() }; + const origin = `https://shop-${n}.${DOMAIN}`; + expect(await policyOf(origin), String(n)).toEqual({ signIn: ["passkey"], allowedEmails: null }); + // and once it answers, it is what it says + spy.mockImplementation(async () => + Response.json({ name: "Shop", allowedEmails: ["eve@a.example"] }), + ); + stack.due(`shop-${n}.${DOMAIN}`); + expect(await policyOf(origin), String(n)).toEqual({ + signIn: FOR_ANYONE, + allowedEmails: { emails: ["eve@a.example"], patterns: [] }, + }); + } +}); + test("an app that answers with no description any more has said so: it is its host again, for anyone", async () => { const stack = stackWith({}); const client = await hostClientOf(stack.env, HOST); @@ -238,6 +416,7 @@ icon: null, members: false, signIn: FOR_ANYONE, + allowedEmails: null, }); expect(await oauthHelpers(stack.env, ORIGIN).lookupClient(client)).toMatchObject({ clientName: HOST, @@ -255,6 +434,7 @@ icon: null, members: false, signIn: FOR_ANYONE, + allowedEmails: null, }); expect(appTile(app)).toBe(`<div class="tile" data-app-mark="initials">GU</div>`); await appOf(stack.env, ORIGIN); @@ -287,7 +467,12 @@ }); // an MCP client that signs a person in to the app: its own client and callback, the app's server const mcp = `/oauth2/auth?${new URLSearchParams({ client_id: "an-mcp-client", redirect_uri: "http://127.0.0.1:4100/callback", resource: `${ORIGIN}/mcp` })}`; - expect(await signInOf(stack.env, mcp)).toEqual({ app: null, methods: ["passkey"] }); + expect(await signInOf(stack.env, mcp)).toEqual({ + app: null, + methods: ["passkey"], + // a row that was kept before the issuer read `allowedEmails` names none + mailedCode: expect.objectContaining({ name: "Guestbook", allowedEmails: null }), + }); // the control plane's own sign-in, and one for the mind's API or its MCP server for (const next of [ "/", @@ -295,9 +480,91 @@ `/oauth2/auth?resource=https://${MIND}/mcp`, "https://elsewhere.test/", ]) - expect(await signInOf(stack.env, next), next).toEqual({ app: null, methods: FOR_MEMBERS }); + expect(await signInOf(stack.env, next), next).toEqual({ + app: null, + methods: FOR_MEMBERS, + mailedCode: null, + }); }); +test("an app that names addresses and patterns takes a mailed code's session for an address that one of them names alone, by the rule that says who owns a mind; a passkey's session counts whatever its address", () => { + const shop = { + signIn: FOR_ANYONE as SignInMethod[], + allowedEmails: { + emails: ["guest@elsewhere.test"], + patterns: ["*@example.com", "*@second.example"], + }, + }; + const takes = (method: SignInMethod, email: string) => appTakes(shop, { method, email }); + expect({ + atAPattern: takes("email", "eve@example.com"), + atTheOther: takes("email", "eve@second.example"), + inCapitals: takes("email", "Eve@EXAMPLE.com"), + named: takes("email", "guest@elsewhere.test"), + namedInCapitals: takes("email", "Guest@Elsewhere.test"), + // a subdomain is another domain, and so is a name that ends as the domain does + atASubdomain: takes("email", "eve@mail.example.com"), + atALookalike: takes("email", "eve@notexample.com"), + twoAts: takes("email", "eve@elsewhere.test@example.com"), + quotedLocalPart: takes("email", '"eve@example.com"@elsewhere.test'), + // another address at the domain of a named address is not named + besideTheNamed: takes("email", "eve@elsewhere.test"), + passkeyElsewhere: takes("passkey", "ada@elsewhere.test"), + }).toEqual({ + atAPattern: true, + atTheOther: true, + inCapitals: true, + named: true, + namedInCapitals: true, + atASubdomain: false, + atALookalike: false, + twoAts: false, + quotedLocalPart: false, + besideTheNamed: false, + passkeyElsewhere: true, + }); + // THE SAME ANSWER AS THE MIND CONFIG'S OWN MATCHER, for every address above + for (const email of [ + "eve@example.com", + "Guest@Elsewhere.test", + "eve@mail.example.com", + "x@y@example.com", + ]) + expect(takesAddress(shop, email), email).toBe( + isOwnerEmail( + { ownerEmails: shop.allowedEmails.emails, ownerEmailPatterns: shop.allowedEmails.patterns }, + email, + ), + ); + // the list binds the mailed code alone: a method that the app does not name is still refused, + // and an app that names nobody takes any address + expect( + appTakes( + { signIn: ["passkey"], allowedEmails: { emails: [], patterns: ["*@example.com"] } }, + { method: "email", email: "eve@example.com" }, + ), + ).toBe(false); + expect(takesAddress({ allowedEmails: null }, "eve@elsewhere.test")).toBe(true); + // the pages' words name the domains of the patterns, and no address that the app names + expect([ + allowedEmailsWords({ name: "Shop", ...shop }), + allowedEmailsWords({ + name: "Shop", + allowedEmails: { emails: [], patterns: ["*@example.com"] }, + }), + allowedEmailsWords({ + name: "Shop", + allowedEmails: { emails: ["guest@elsewhere.test"], patterns: [] }, + }), + allowedEmailsWords({ name: "Shop", allowedEmails: null }), + ]).toEqual([ + "Shop takes an address at example.com or second.example, and the addresses that it names, only.", + "Shop takes an address at example.com only.", + "Shop takes only the addresses that it names.", + "", + ]); +}); + test("the mailed code's page for an app's sign-in names the host it signs in to, under the app's own icon", async () => { const stack = stackWith({ [HOST]: { name: "Guestbook", icon: `${ORIGIN}/icon.svg` } }); const client = await hostClientOf(stack.env, HOST); @@ -339,6 +606,7 @@ name: "Guestbook", icon: `${ORIGIN}/icon.svg`, members: false, + allowedEmails: null, signIn: ["email", "passkey"] as SignInMethod[], }; stack.challenge.next = next; @@ -411,6 +679,7 @@ name: "Dash", icon: null, members: true, + allowedEmails: null, signIn: ["passkey"] as SignInMethod[], }; expect(appSignIn(dash)).toMatchObject({ @@ -449,6 +718,7 @@ name: HOST, icon: null, members: false, + allowedEmails: null, signIn: ["email", "passkey"] as SignInMethod[], }; const passkey = await signInPage({ @@ -514,6 +784,7 @@ keyOf(host), JSON.stringify({ members: false, + allowedEmails: null, signIn: FOR_ANYONE, ...value, askAfter: Date.now() + 5 * 60_000,
M core/auth-worker/src/asking-app.ts
@@ -20,7 +20,9 @@ // no redirect, and asks again after five minutes. An icon counts only from the app's own origin, // so the page's policy allows that one origin. An app that says nothing is shown by its host and // its initials. An app that DOES NOT ANSWER (no answer in two seconds, or a 5xx) has said nothing -// new: it is still what it last said, and it is asked again after a minute. +// new: it is still what it last said, and it is asked again after a minute. So is an app whose +// description is a JSON object that is wrong. With nothing kept of such an app, the issuer takes +// the passkey alone for it until it says (`UNHEARD`): it never opens an app that it has not heard. // // "For members" changes the page's words and the default of `signIn`, and nothing else: who may // come is the guard in the app's own code (the mind's worker.ts), which this Worker does not @@ -32,11 +34,20 @@ // methods alone, in the app's order (`signInOf`). It is read from the app, never from the // request, so an MCP client that signs a person in to the app gets the same list. // +// WHOSE ADDRESS A MAILED CODE SIGNS IN (`allowedEmails`, `allowedEmailPatterns`) is enforced +// with it, by the rule that says who owns a mind (iterate/mind-config `isOwnerEmail`): addresses, +// each whole, and patterns `*@<domain>`. For an app that names either, no code is mailed to an +// address that neither names (./email-sign-in.ts), and a session that a mailed code opened for +// such an address gets no code for the app's host (`appTakes`). So the list holds at the sign-up, +// and not only at the app's own guard. It binds the method "email" alone; a list that changes +// binds the grants made after it. +// // AN APP IS AN OAUTH CLIENT, as Codex is: the host's client holds the app's name and icon (its // `clientName` and `logoUri`), written here whenever the description is read and says something // else. So the list of a person's sign-ins by client (./oauth.ts `sessionsByClientOf`) names the // app as the sign-in pages do, and asks no app for it. import { APP_DESCRIPTION_PATH, AppDescription } from "iterate/app-description"; +import { domainOfOwnerEmailPattern, isOwnerEmail } from "iterate/mind-config"; import type { SignInMethod } from "iterate/principal"; import { admitted } from "./device/limits.ts"; import { configOf, type Env, issuerOf } from "./env.ts"; @@ -62,6 +73,8 @@ /** How the app's people sign in, in the app's order: what it names, or the default for whom it * is for (`saidIn`). The sign-in page opens on the first. */ signIn: SignInMethod[]; + /** Whose address a mailed code signs in to the app (`takesAddress`), or null: any address. */ + allowedEmails: AllowedEmails | null; }; const text = (value: string) => @@ -81,12 +94,22 @@ export async function signInOf( env: Env, next: string, -): Promise<{ app: AskingApp | null; methods: SignInMethod[] } | null> { +): Promise<{ + app: AskingApp | null; + methods: SignInMethod[]; + /** For a mind hostname's sign-in: the app's name, and whose address a mailed code signs in to + * it (`takesAddress`). The pages' refusal names the app by it, whichever client asks. */ + mailedCode: Pick<AskingApp, "name" | "allowedEmails"> | null; +} | null> { const authorization = hostAuthorizationIn(env, next); - if (!authorization) return { app: null, methods: CONTROL_PLANE_SIGN_IN }; + if (!authorization) return { app: null, methods: CONTROL_PLANE_SIGN_IN, mailedCode: null }; const app = await appOf(env, authorization.origin); if (!app) return null; - return { app: (await isOwnSignIn(env, authorization)) ? app : null, methods: app.signIn }; + return { + app: (await isOwnSignIn(env, authorization)) ? app : null, + methods: app.signIn, + mailedCode: app, + }; } /** The app whose own sign-in `next` goes on to (a path of this issuer), or null: for any other @@ -97,11 +120,30 @@ return appOf(env, authorization.origin); } -/** WHETHER AN APP TAKES A SESSION THAT `method` OPENED, for a code for the app's host: a - * passkey's counts at every app, and any other when the app names its method. */ -export const appTakes = (app: Pick<AskingApp, "signIn">, method: SignInMethod) => - method === "passkey" || app.signIn.includes(method); +/** WHETHER AN APP TAKES A SESSION, for a code for the app's host: a passkey's counts at every + * app, and any other when the app names its method. A mailed code's counts only for an address + * that the app takes (`takesAddress`). */ +export const appTakes = ( + app: Pick<AskingApp, "signIn" | "allowedEmails">, + session: { method: SignInMethod; email: string }, +) => + session.method === "passkey" || + (app.signIn.includes(session.method) && + (session.method !== "email" || takesAddress(app, session.email))); +/** The addresses and the patterns (`*@<domain>`) that an app names for the mailed code. */ +export type AllowedEmails = { emails: string[]; patterns: string[] }; + +/** WHETHER A MAILED CODE SIGNS `email` IN TO THE APP: the app names nobody, or the address is one + * that it names, by the one rule that says who owns a mind (iterate/mind-config + * `isOwnerEmail`). */ +export const takesAddress = (app: Pick<AskingApp, "allowedEmails">, email: string) => + !app.allowedEmails || + isOwnerEmail( + { ownerEmails: app.allowedEmails.emails, ownerEmailPatterns: app.allowedEmails.patterns }, + email, + ); + /** `next` as an authorization request of this issuer for a mind hostname: the hostname's origin, * and the request's parameters. Null for anything else. */ function hostAuthorizationIn(env: Env, next: string) { @@ -132,7 +174,7 @@ export async function appOf(env: Env, origin: string): Promise<AskingApp | null> { const { host } = new URL(origin); const key = `iterate-app-description:${host}`; - let kept = await env.OAUTH_KV.get<Kept>(key, "json"); + let kept = inThisShape(await env.OAUTH_KV.get<Kept & DomainsRow>(key, "json")); if ( !kept && !(await keptHostClientOf(env, host)) && @@ -146,19 +188,21 @@ redirect: "manual", signal: AbortSignal.timeout(2000), }) - // an answer of the app: its description's text, which is empty for an app that has none - // (a 404, a sign-in). Null: the app did not answer, or its answer broke off. + // What the app says: its description's text is empty for an app that has none (a 404, a + // sign-in). Null: the app did not answer, its answer broke off, or its description is + // wrong (`saidIn`). None of those is the app's word. .then(async (answer) => { - if (answer.status >= 500) return null; - return { description: answer.status === 200 ? await answer.text() : "" }; + // a 5xx, and a 4xx that says "not now" (408, 425, 429), are no answer + if (answer.status >= 500 || [408, 425, 429].includes(answer.status)) return null; + return saidIn(answer.status === 200 ? await answer.text() : "", document); }) .catch(() => null); - const last = kept || NOTHING; kept = heard ? // "nothing" is kept too: an app with no description is not asked at each page - { ...saidIn(heard.description, document), askAfter: Date.now() + 5 * 60_000 } - : // it did not answer: it is what it last said, and is asked again after a minute - { ...last, askAfter: Date.now() + 60_000 }; + { ...heard, askAfter: Date.now() + 5 * 60_000 } + : // no word of the app: it is what it last said, or `UNHEARD`, and is asked again after a + // minute + { ...(kept || UNHEARD), askAfter: Date.now() + 60_000 }; // The row goes a day after it was last written: an app that is asked about is written again // within five minutes, and a hostname that nobody asks about any more leaves no row. await env.OAUTH_KV.put(key, JSON.stringify(kept), { expirationTtl: 24 * 3600 }); @@ -171,11 +215,30 @@ icon: kept.icon, members: kept.members, signIn: kept.signIn, + allowedEmails: kept.allowedEmails, }; } +/** A ROW OF AN ISSUER THAT READ A LIST OF DOMAINS (`emailDomains`) where this one reads + * `allowedEmails`. The mind's KV outlives a deploy, so this issuer may read such a row for the + * five minutes until the app is asked again. */ +type DomainsRow = { emailDomains?: string[] | null; allowedEmails?: AllowedEmails | null }; + +/** Such a row as this issuer keeps it: a domain is the pattern `*@<domain>`, which names the same + * addresses. So a row that held a list never reads as "any address". */ +function inThisShape(row: (Kept & DomainsRow) | null): Kept | null { + if (!row) return null; + const { emailDomains, ...kept } = row; + if (kept.allowedEmails || !emailDomains) + return { ...kept, allowedEmails: kept.allowedEmails || null }; + return { + ...kept, + allowedEmails: { emails: [], patterns: emailDomains.map((domain) => `*@${domain}`) }, + }; +} + /** What an app said of itself (`saidIn`), and when to ask it again. */ -type Kept = ReturnType<typeof saidIn> & { askAfter: number }; +type Kept = typeof NOTHING & { askAfter: number }; /** The host's own client says what the app says: written when it says something else. */ async function keepOnClient(env: Env, origin: string, said: { name: string; icon: string | null }) { @@ -195,25 +258,43 @@ icon: string | null; members: boolean; signIn: SignInMethod[]; -} = { name: null, icon: null, members: false, signIn: ["email", "passkey"] }; + allowedEmails: AllowedEmails | null; +} = { name: null, icon: null, members: false, signIn: ["email", "passkey"], allowedEmails: null }; +/** AN APP THAT THE ISSUER HAS NO WORD OF YET: it did not answer, or its description is wrong, and + * nothing that it said before is kept. The issuer does not know whom the app takes, so it takes + * the passkey alone until the app says: a code that is mailed meanwhile, or a grant for an + * address, could be one that the app's own list refuses (`signIn`, `allowedEmails`). */ +const UNHEARD: typeof NOTHING = { ...NOTHING, signIn: ["passkey"] }; + /** WHAT THE TEXT OF AN APP'S DESCRIPTION SAYS (iterate/app-description `AppDescription`): a name * of at most sixty characters, its icon when that is on the description's own origin, over * https, whether the app is for members, and how its people sign in: the list it names, as it is * written, or the passkey alone for an app for members (a member signs in with nothing else), - * and email then passkey for any other. A text that is no `AppDescription` says nothing: one - * that names a method this issuer does not know is such a text, so no app is held to a list that - * it did not write. */ -export function saidIn(descriptionText: string, descriptionUrl: string): typeof NOTHING { - if (!descriptionText || descriptionText.length > 20_000) return NOTHING; + * and email then passkey for any other, and whose address a mailed code signs in. A text that is + * no JSON object says nothing: an app with no description answers with a page, or with none. + * NULL: A JSON OBJECT THAT IS NO `AppDescription`, such as one that names a method this issuer + * does not know, or a pattern that is none, and one that broke off or is over 20,000 characters. The app wrote a description and it is wrong, so it is + * held to no list that it did not write, and it is not opened to anyone either: the caller keeps + * what the app last said (`appOf`). */ +export function saidIn(descriptionText: string, descriptionUrl: string): typeof NOTHING | null { + // An object that is too long to read, or that broke off, is a description that did not arrive + // whole. Any other text (a page, of any length) is none. + const unread = descriptionText.trimStart().startsWith("{") ? null : NOTHING; + if (!descriptionText) return NOTHING; + if (descriptionText.length > 20_000) return unread; let json: unknown; try { json = JSON.parse(descriptionText); } catch { - return NOTHING; + return unread; } + if (typeof json !== "object" || !json || Array.isArray(json)) return NOTHING; + // A list of domains (`emailDomains`) is a restriction that this issuer does not read. The parse + // would drop it and leave the app for any address, so such a description is wrong. + if ("emailDomains" in json) return null; const parsed = AppDescription.safeParse(json); - if (!parsed.success) return NOTHING; + if (!parsed.success) return null; const name = parsed.data.name // a name is one line of text .replace(/[\p{Cc}\p{Cf}]/gu, " ") @@ -222,6 +303,7 @@ const { origin } = new URL(descriptionUrl); const icon = parsed.data.icon ? new URL(parsed.data.icon, descriptionUrl) : null; const members = parsed.data.for === "members"; + const { allowedEmails, allowedEmailPatterns } = parsed.data; return { name: name || null, // a path that begins `//` names another host: an icon is the app's own origin's alone @@ -230,7 +312,29 @@ signIn: [ ...new Set<SignInMethod>(parsed.data.signIn || (members ? ["passkey"] : NOTHING.signIn)), ], + allowedEmails: + allowedEmails || allowedEmailPatterns + ? { + emails: [...new Set(allowedEmails || [])], + patterns: [...new Set(allowedEmailPatterns || [])], + } + : null, }; +} + +/** WHOM AN APP'S MAILED CODE IS FOR, IN WORDS, or "" for an app that takes any address. The + * pages name the domains of the patterns, and never an address that the app names: the page is + * for anyone. */ +export function allowedEmailsWords(app: Pick<AskingApp, "name" | "allowedEmails">): string { + if (!app.allowedEmails) return ""; + const { emails, patterns } = app.allowedEmails; + const domains = new Intl.ListFormat("en", { type: "disjunction" }).format( + patterns.map(domainOfOwnerEmailPattern), + ); + if (!patterns.length) return `${app.name} takes only the addresses that it names.`; + return emails.length + ? `${app.name} takes an address at ${domains}, and the addresses that it names, only.` + : `${app.name} takes an address at ${domains} only.`; } /** The app's tile (plain-page.css `.tile`): its icon, or its initials. Never a built-in mark of
M core/auth-worker/src/authorize.ts
@@ -10,6 +10,7 @@ import { appOf, appTakes, askingAppOf } from "./asking-app.ts"; import { clearGuestCookie, + clearMindChoiceCookie, clearMindCookie, clearMindFreshCookie, clearSessionCookie, @@ -17,13 +18,17 @@ guestCookie, guestOf, MIND_FRESH_COOKIE, + mindChoiceCookie, + mindChoiceOf, mindFreshOf, mindSessionOf, type PersonSession, + requestHashOf, personSessionOf, } from "./cookies.ts"; import { configOf, type Env, issuerOf } from "./env.ts"; import { + AUTHORIZE_ENDPOINT, type GrantProps, grantedScopes, hostCallbackOf, @@ -32,7 +37,8 @@ mindHostResourceOf, } from "./oauth.ts"; import { isMemberSession } from "./members.ts"; -import { chooserPage, consentPage, errorPage, notMemberPage } from "./pages.ts"; +import { mindMarkOf } from "./mind-mark.ts"; +import { CHOICE_FIELD, chooserPage, consentPage, errorPage, notMemberPage } from "./pages.ts"; import { signInHref } from "./sign-in.ts"; import { admitted, TOO_MANY } from "./device/limits.ts"; import { GUEST_SESSIONS_PER_TEN_MINUTES, guestRefusal } from "./guest-sign-in.ts"; @@ -44,6 +50,13 @@ const answer = await authorizeAnswer(env, request); // a mind sign-in's fresh mark answers this authorization or none (./cookies.ts `mindFreshCookie`) if (!cookieValueOf(request.headers.get("cookie"), MIND_FRESH_COOKIE)) return answer; + // a mark that was begun for another request stays for that one (`freshAnswers`) + const fresh = await mindFreshOf(env, request); + if ( + fresh?.request && + fresh.request !== (await requestHashOf(promptOf(new URL(request.url)).here)) + ) + return answer; const headers = new Headers(answer.headers); headers.append("set-cookie", clearMindFreshCookie); return new Response(answer.body, { @@ -70,7 +83,13 @@ } } -async function describe(env: Env, request: Request) { +/** `choice`: whom the chooser's own POST chose for this request (`chosen`), of the two people + * that its page named: the person signed in here (`person`, their user id) or the mind's person + * (`user`). The request is then answered for that one alone, or not at all. Nothing else passes + * it. */ +type Choice = { as: "mind" | "person"; person: string; user: string; app: string }; + +async function describe(env: Env, request: Request, choice?: Choice) { const config = configOf(env); const hostResource = mindHostResourceOf( config, @@ -101,34 +120,68 @@ const { prompt, here } = promptOf(new URL(request.url)); // a hostname's own sign-in: the code goes to ingress on that host alone, and is not a consent const hostSignIn = hostResource && authRequest.redirectUri === hostCallbackOf(hostResource); - // Anyone signed in: a mind hostname takes a person who is no member (`grantRefusal`). A guest's - // cookie counts only where nobody is signed in, for a host's own sign-in whose app names guests - // (`guestAt`). - const session: SignedIn | null = - (await personSessionOf(env, request)) || - (hostSignIn - ? (await guestAt(env, hostResource, request)) || - (await mindPersonAt(env, hostResource, request)) - : null); + // Anyone signed in: a mind hostname takes a person who is no member (`grantRefusal`). + const person = await personSessionOf(env, request); + // AN APP NAMES HOW ITS PEOPLE SIGN IN, and this endpoint holds every code for the app's host to + // it, whichever client asks. A session that the app does not take is no session here: the + // person goes to the sign-in for this request, which offers the app's methods alone, unless + // their mind vouched for them and the app names "mind". + const takesPerson = !person || !hostResource || (await hostTakes(env, hostResource, person)); + if (takesPerson === null) return errorPage(TOO_MANY, 429); + // A guest's cookie counts only where nobody is signed in, for a host's own sign-in whose app + // names guests (`guestAt`), and a mind's cookie too (`mindPersonAt`). BESIDE A PERSON'S SESSION + // a mind's cookie counts in two cases alone. The app does not take that session, and the mind + // sign-in that was begun for THIS REQUEST just completed (a fresh mark that names it): the + // person was sent to the sign-in for this request, and that was their answer. A sign-in that + // an app's page began names no request, and answers nothing here: the sign-in page comes. Or the app takes the session, and the person chose + // the mind's person on the chooser's page (`choice`). + let session: SignedIn | null = null; + // whether this request spent the fresh mark, which answers a `select_account` too + let fresh = false; + if (choice) { + if (!hostSignIn || new URL(hostResource).host !== choice.app) return choiceEnded(); + if (choice.as === "person") { + // the person whom the page named, still signed in and still taken: no other, and never + // the mind's person in their place + if (person?.userId !== choice.person || !takesPerson) return choiceEnded(); + session = person; + } else { + const mind = await mindPersonAt(env, hostResource, request); + if (mind?.userId !== choice.user) return choiceEnded(); + session = mind; + } + } else if (person && takesPerson) session = person; + else if (hostSignIn && person) { + const mind = await mindPersonAt(env, hostResource, request); + fresh = Boolean( + mind && + (await freshAnswers(env, request, mind.userId, new URL(hostResource).host, here, true)), + ); + if (fresh) session = mind; + } else if (hostSignIn) + session = + (await guestAt(env, hostResource, request)) || + (await mindPersonAt(env, hostResource, request)); const guest = session?.method === "guest"; // a member of another mind, as a guest: a cookie of their own, with no session row const cookieOnly = guest || session?.method === "mind"; const signIn = `${issuerOf(env)}${signInHref(here)}`; if (!session) return Response.redirect(signIn, 302); - // AN APP NAMES HOW ITS PEOPLE SIGN IN, and this endpoint holds every code for the app's host to - // it, whichever client asks. A session that the app does not take is no session here: the - // person goes to the sign-in for this request, which offers the app's methods alone. - const taken = hostResource ? await hostTakes(env, hostResource, session) : true; - if (taken === null) return errorPage(TOO_MANY, 429); - if (!taken) return Response.redirect(signIn, 302); // A MIND SIGN-IN THAT JUST COMPLETED for this host is the answer to its `select_account`, once: // the person signed out here, then signed in with their mind (./cookies.ts `mindFreshCookie`). const answered = prompt === "select_account" && hostSignIn && session.method === "mind" && - (await freshAnswers(env, request, session.userId, new URL(hostResource).host)); + (fresh || (await freshAnswers(env, request, session.userId, new URL(hostResource).host, here))); const asked = answered ? null : prompt; + // BESIDE A PERSON'S SESSION the same mind sign-in answers nothing by itself: the chooser offers + // both people, and the person's press decides (`chosen`). So a mind sign-in that another site + // ran in this browser replaces nobody. + const offer = + asked === "select_account" && hostSignIn && !cookieOnly + ? await mindOffer(env, request, hostResource, here, session.userId) + : null; // OpenID Connect's `prompt`. `login`: sign in again, whoever is signed in. `select_account`: say // who is signed in and offer another account. Either comes back here without it. A guest's // cookie ends for either: the name form is the page that says who they are, and its answer is @@ -154,12 +207,17 @@ if (asked === "select_account") return chooserPage({ mind: config.controlPlaneHostname, + mindMark: await mindMarkOf(env), email: session.email, here, // an app's own sign-in says which app, to a person who is no member: a member's page is // the mind's own app: (await isMemberSession(env, session)) ? null : await askingAppOf(env, here), signedOutOf: hostSignIn ? new URL(hostResource).host : undefined, + mindHostname: offer?.hostname, + headers: offer + ? new Headers({ "set-cookie": offer.cookie, "cache-control": "no-store" }) + : undefined, }); const refused = await grantRefusal(env, session, hostResource, here); if (refused) return refused; @@ -205,6 +263,7 @@ handle: consent.handle, email: session.email, mind: config.controlPlaneHostname, + mindMark: await mindMarkOf(env), resource: resourceInWords(env, authRequest.resource), host: hostResource ? new URL(hostResource).host : undefined, here, @@ -233,6 +292,7 @@ if (request.headers.get("origin") !== issuerOf(env)) return errorPage("Approve this from its own page.", 403); const form = await request.formData().catch(() => null); + if (form?.has(CHOICE_FIELD)) return chosen(env, request, form); const handle = form?.get("handle"); if (typeof handle !== "string") return errorPage("This form is incomplete. Start again.", 400); const session = await personSessionOf(env, request); @@ -300,24 +360,114 @@ /** Whether this browser's fresh mind sign-in (./cookies.ts `mindFreshCookie`) is the one of * `userId` for the app at `host`, taken now for the first time. */ -async function freshAnswers(env: Env, request: Request, userId: string, host: string) { +async function freshAnswers( + env: Env, + request: Request, + userId: string, + host: string, + here: string, + boundOnly = false, +) { const fresh = await mindFreshOf(env, request); if (!fresh || fresh.user !== userId || fresh.app !== host) return false; - // once: a repeat cannot insert (the statements' table, as ./mind-sign-in.ts takes a vouch) + // `boundOnly`: only a sign-in that was begun for this very request answers + if (boundOnly && !fresh.request) return false; + // a sign-in that was begun for one request answers that request alone: another request for + // the same host does not spend its mark + if (fresh.request && fresh.request !== (await requestHashOf(here))) return false; + return once(env, `mind-fresh:${fresh.jti}`, fresh.exp * 1000); +} + +/** Whether `mark` is taken now for the first time: a repeat cannot insert (the statements' + * table, as ./mind-sign-in.ts takes a vouch). */ +async function once(env: Env, mark: string, expires: number) { const [, inserted] = await env.DB.batch([ env.DB.prepare(`delete from statements where expires <= ?1`).bind(Date.now()), env.DB.prepare( `insert into statements (hash, expires) values (?1, ?2) on conflict do nothing`, - ).bind(`mind-fresh:${fresh.jti}`, fresh.exp * 1000), + ).bind(mark, expires), ]); return Boolean(inserted?.meta.changes); } +/** THE MIND PERSON THAT THE CHOOSER OFFERS beside a person's session, for the request `here` of + * the host's own sign-in, or null: this browser's mind sign-in for that host just completed + * (the fresh mark, spent here), and the app names "mind". The cookie is the choice that the + * page's POST takes (./cookies.ts `mindChoiceCookie`): for that person, that host and that + * request alone. */ +async function mindOffer( + env: Env, + request: Request, + hostResource: string, + here: string, + person: string, +) { + const mind = await mindPersonAt(env, hostResource, request); + const { host } = new URL(hostResource); + if (!mind?.mind || !(await freshAnswers(env, request, mind.userId, host, here))) return null; + return { + hostname: mind.mind.hostname, + cookie: await mindChoiceCookie( + env, + { person, user: mind.userId, app: host, request: await requestHashOf(here) }, + AUTHORIZE_ENDPOINT, + ), + }; +} + +/** THE CHOOSER'S PRESS, when it offered a mind person too (`mindOffer`): a POST from the page + * (`decide` checked its origin) with the request it showed, `here`, and "mind" or "person". The + * choice is this browser's, for that request, and is taken once: so one page makes one code, + * for one of the two, and a second request for the same host needs a page of its own. Then the + * request is answered as a GET of it is, with every check of `describe`: for "mind", as the + * mind person, whose cookie and whose app's "mind" are read again. */ +async function chosen(env: Env, request: Request, form: FormData) { + const here = form.get("here"); + const as = form.get(CHOICE_FIELD); + if (typeof here !== "string" || (as !== "mind" && as !== "person")) return choiceEnded(); + const issuer = issuerOf(env); + const url = URL.parse(here, issuer); + if (!url || url.origin !== issuer || url.pathname !== AUTHORIZE_ENDPOINT) return choiceEnded(); + // the choice of this request's own page: a chooser for another request has another cookie, + // which this press neither reads nor ends + const hash = await requestHashOf(here); + const choice = await mindChoiceOf(env, request, hash); + if (!choice) return choiceEnded(); + if (!(await once(env, `mind-choice:${choice.jti}`, choice.exp * 1000))) return choiceEnded(hash); + const headers = new Headers(request.headers); + headers.delete("content-type"); + headers.delete("content-length"); + const answer = await describe(env, new Request(url, { headers }), { + as, + person: choice.person, + user: choice.user, + app: choice.app, + }); + console.info({ event: "auth.chooser-chose", as, host: choice.app, status: answer.status }); + const answered = new Headers(answer.headers); + answered.append("set-cookie", clearMindChoiceCookie(hash, AUTHORIZE_ENDPOINT)); + answered.set("cache-control", "no-store"); + return new Response(answer.body, { + status: answer.status, + statusText: answer.statusText, + headers: answered, + }); +} + +/** A choice that is gone: used, timed out, or for another request or another person. With + * `requestHash`, that request's own cookie ends with it. */ +function choiceEnded(requestHash?: string) { + const headers = new Headers({ "cache-control": "no-store" }); + if (requestHash) + headers.set("set-cookie", clearMindChoiceCookie(requestHash, AUTHORIZE_ENDPOINT)); + return errorPage("This choice ended. Go back to the app and sign in again.", 403, headers, []); +} + /** Whether the app at `hostResource` takes `session` (./asking-app.ts `appTakes`). Null: the * app could not be asked, since too many new hostnames were asked about just now. */ async function hostTakes(env: Env, hostResource: string, session: SignedIn) { const app = await appOf(env, hostResource); - return app && appTakes(app, session.method); + return app && appTakes(app, session); } /** WHY A SESSION GETS NO GRANT, or null. A mind hostname takes the identity of anyone signed in,
M core/auth-worker/src/config.test.ts
@@ -92,3 +92,41 @@ "https://iterate.example.com/api/provide-connect", ]); }); + +test("an owner is also an address at the exact domain of an owner email pattern", () => { + const config = { ownerEmails: ["owner@example.net"], ownerEmailPatterns: ["*@company.example"] }; + expect([ + isOwner(config, "owner@example.net"), + isOwner(config, " Bo@Company.example"), + isOwner(config, "bo@sub.company.example"), + isOwner(config, "bo@company.example.evil.example"), + isOwner(config, "bo@example.net"), + ]).toEqual([true, true, false, false, false]); +}); + +test.for([ + ["at a zone", "*@example.com"], + ["under a zone", "*@mail.example.com"], + ["at the second zone", "*@second.example"], +])( + "an owner email pattern %s of the mind is refused: the mind receives its mail", + ([, pattern]) => { + const vars = configVars({ + zones: ["example.com", "second.example"], + ownerEmailPatterns: [pattern!], + }); + expect(() => authConfigOf(vars)).toThrow( + /ITERATE__OWNER_EMAIL_PATTERNS.*names a zone of the mind/, + ); + }, +); + +test("a config whose owner email pattern is no pattern is refused, and one with a pattern elsewhere is taken", () => { + expect(() => authConfigOf(configVars({ ownerEmailPatterns: ["*@*"] }))).toThrow( + "ownerEmailPatterns", + ); + expect(authConfigOf(configVars({ ownerEmailPatterns: ["*@company.example"] }))).toMatchObject({ + ownerEmailPatterns: ["*@company.example"], + }); + expect(authConfigOf(configVars())).not.toHaveProperty("ownerEmailPatterns"); +});
M core/auth-worker/src/config.ts
@@ -4,7 +4,15 @@ // is the mind's own. Pure: ./env.ts reads it out of the Worker's variables. import { fieldNameOf, redacted } from "iterate/app-config"; import { mindApiUrlOf, mindMcpUrlOf, mindProvideConnectResourceOf } from "iterate/mind-api"; -import { Hostname, type MindConfig, mindConfigOf, zoneOfMailAddress } from "iterate/mind-config"; +import { + domainOfOwnerEmailPattern, + Hostname, + isOwnerEmail, + type MindConfig, + mindConfigOf, + zoneOf, + zoneOfMailAddress, +} from "iterate/mind-config"; import { z } from "zod"; const ownFields = { @@ -30,6 +38,14 @@ throw new Error( `${fieldNameOf(["ownerEmails"], { prefix: "ITERATE" })}: ${own} is at a zone of the mind, which receives that address's mail, so the mind could sign in as that owner`, ); + // the same for a pattern: every address that it names is one the mind receives the mail of + const ownPattern = (config.ownerEmailPatterns || []).find((pattern) => + zoneOf(config, domainOfOwnerEmailPattern(pattern)), + ); + if (ownPattern) + throw new Error( + `${fieldNameOf(["ownerEmailPatterns"], { prefix: "ITERATE" })}: ${ownPattern} names a zone of the mind, which receives that domain's mail, so the mind could sign in as an owner`, + ); return config; } @@ -38,10 +54,21 @@ export const atMindsZone = (config: Pick<MindConfig, "zones">, email: string) => zoneOfMailAddress(config, email.trim()) !== null; -/** An owner is a member the config names: the people a deploy lets in, so the only ones who let - * another member in again. */ -export const isOwner = (config: Pick<MindConfig, "ownerEmails">, email: string) => - config.ownerEmails.includes(email.trim().toLowerCase()); +/** An owner is a member the config names, by address (`ownerEmails`) or by an owner email + * pattern (`ownerEmailPatterns`, `*@<domain>`): the people a deploy lets in, so the only ones + * who let another member in again. */ +export const isOwner = ( + config: Pick<MindConfig, "ownerEmails" | "ownerEmailPatterns">, + email: string, +) => isOwnerEmail(config, email); + +/** AN OWNER BY A PATTERN ALONE: at the domain of an owner email pattern, and not named by + * address. Such a person's standing is the one that an owner can end for one address: by a + * block (./members.ts `isMember`, `block`). An owner by address is ended by a deploy alone. */ +export const isOwnerByPattern = ( + config: Pick<MindConfig, "ownerEmails" | "ownerEmailPatterns">, + email: string, +) => !config.ownerEmails.includes(email.trim().toLowerCase()) && isOwnerEmail(config, email); /** THE AUDIENCES OF THE TOKENS THIS WORKER ISSUES TO MEMBERS (RFC 8707 resources), each a * canonical URI: the mind's API and its MCP server, and the address an external mind connects in
M core/auth-worker/src/cookies.ts
@@ -489,12 +489,20 @@ // the authorization endpoint at once. There it answers that host's `prompt=select_account` once // (./authorize.ts): a host that the person signed out of asks who they are, and they just said. // Any authorization clears it, and its `jti` is taken once (`statements`), so it answers one -// prompt at most. +// prompt at most. `request`: when the sign-in was begun for one authorization request (the +// sign-in page's `next`), a hash of that request (`requestHashOf`), and the mark answers no +// other. A sign-in that an app's page began (iterate/sdk `auth.mindSignIn`) has none: its +// request does not exist yet. export const MIND_FRESH_COOKIE = "__Host-iterate-auth-mind-fresh"; const MIND_FRESH_SECONDS = 30; -export async function mindFreshCookie(env: Env, fresh: { user: string; app: string }) { - const token = await signed(env, "mind-fresh", fresh) +export async function mindFreshCookie( + env: Env, + fresh: { user: string; app: string; request: string | null }, +) { + const claims: Record<string, string> = { user: fresh.user, app: fresh.app }; + if (fresh.request) claims.request = fresh.request; + const token = await signed(env, "mind-fresh", claims) .setJti(crypto.randomUUID()) .setExpirationTime(`${MIND_FRESH_SECONDS}s`) .sign(keyOf(env)); @@ -506,6 +514,7 @@ .object({ user: z.string().min(1), app: z.string().min(1), + request: z.string().min(1).optional(), jti: z.string().min(1), exp: z.number(), }) @@ -514,6 +523,63 @@ } export const clearMindFreshCookie = cookie(MIND_FRESH_COOKIE, "", 0); + +/** A hash of an authorization request, as its path and query without `prompt` (./authorize.ts + * `promptOf`, `here`): what a fresh mark and a chooser's choice are bound to. */ +export async function requestHashOf(here: string) { + const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(here)); + return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join(""); +} + +// THE CHOICE THAT THE CHOOSER OFFERS between a person's session here and a mind sign-in that just +// completed (./authorize.ts `chosen`): set with the chooser's page, for the two people that the +// page names (`person`, `user`), the app's host and that one authorization request (`request`, a +// hash of it), for two minutes. The chooser's POST takes it once (`jti`, `statements`), so one +// page makes one code. `SameSite=Strict` and the authorization endpoint's path: only that page's +// own form sends it. The cookie's name ends with the start of the request's hash, so a chooser +// for another request, in another tab, has a choice of its own. +const MIND_CHOICE_SECONDS = 120; + +const mindChoiceNameOf = (requestHash: string) => + `__Secure-iterate-auth-mind-choice-${requestHash.slice(0, 16)}`; + +export async function mindChoiceCookie( + env: Env, + choice: { person: string; user: string; app: string; request: string }, + path: string, +) { + const token = await signed(env, "mind-choice", choice) + .setJti(crypto.randomUUID()) + .setExpirationTime(`${MIND_CHOICE_SECONDS}s`) + .sign(keyOf(env)); + return mindChoiceCookieOf(choice.request, token, MIND_CHOICE_SECONDS, path); +} + +/** The choice that this browser holds for the request with the hash `requestHash`. */ +export async function mindChoiceOf(env: Env, request: Request, requestHash: string) { + const choice = z + .object({ + person: z.string().min(1), + user: z.string().min(1), + app: z.string().min(1), + request: z.literal(requestHash), + jti: z.string().min(1), + exp: z.number(), + }) + .safeParse(await claimsOf(env, request, mindChoiceNameOf(requestHash), "mind-choice")); + return choice.success ? choice.data : null; +} + +const mindChoiceCookieOf = ( + requestHash: string, + value: string, + maxAgeSeconds: number, + path: string, +) => + `${mindChoiceNameOf(requestHash)}=${value}; HttpOnly; Secure; SameSite=Strict; Path=${path}; Max-Age=${maxAgeSeconds}`; + +export const clearMindChoiceCookie = (requestHash: string, path: string) => + mindChoiceCookieOf(requestHash, "", 0, path); const signed = (env: Env, audience: string, claims: Record<string, string>) => new SignJWT(claims)
M core/auth-worker/src/device/page.test.ts
@@ -280,7 +280,12 @@ statements.map((statement) => statement.counted()), }, OAUTH_KV: { - get: async (key: string) => kept.get(key) ?? null, + // a mind with no logo of its own, read just now (../mind-mark.ts): no page here asks the + // mind's website, which would be a request to the real internet + get: async (key: string) => + key === "iterate-mind-mark" + ? { icon: null, askAfter: Number.MAX_SAFE_INTEGER } + : (kept.get(key) ?? null), put: async (key: string, value: string) => void kept.set(key, value), }, // the cast: the device page reads these bindings and no other
M core/auth-worker/src/device/page.ts
@@ -7,6 +7,7 @@ import { clientTile } from "../client-mark.ts"; import { errorPage, factsTable, notMemberPage, otherAccountForm, page, text } from "../pages.ts"; import { signedChangeBy, signerOf, signScript } from "../signed-change.ts"; +import { mindMarkOf } from "../mind-mark.ts"; import { signInHref } from "../sign-in.ts"; import { CALLBACK_PATH, normalizeUserCode, VERIFICATION_PATH } from "./protocol.ts"; import { type DeviceRequest, deviceStore } from "./store.ts"; @@ -85,7 +86,7 @@ (device.status === "confirmed" && device.confirmedBy === session.userId)); if (!found || !waits) return enter(mind, userCode, "No device is waiting for this code. It may have expired."); - if (request.method === "GET") return confirm(env, userCode, device, session.email); + if (request.method === "GET") return await confirm(env, userCode, device, session.email); // Only Decline declines: Continue with no signature (a page whose script did not run) says // what it takes, and the request waits on. @@ -108,7 +109,13 @@ ? null : "the signed statement is for another request."; if (refused || "refused" in press) - return confirm(env, userCode, device, session.email, `The device is not signed in: ${refused}`); + return await confirm( + env, + userCode, + device, + session.email, + `The device is not signed in: ${refused}`, + ); const facts = new AccountFacts(); facts.add(session.userId, { type: DEVICE_CONFIRMED, @@ -150,7 +157,13 @@ * name is the device's own claim. */ export const deviceTile = (name: string) => clientTile({ name, redirectUri: "", redirectHost: "" }); -function confirm(env: Env, userCode: string, device: DeviceRequest, email: string, error?: string) { +async function confirm( + env: Env, + userCode: string, + device: DeviceRequest, + email: string, + error?: string, +) { const mind = configOf(env).controlPlaneHostname; const where = [device.requestedFrom.city, device.requestedFrom.country] .filter(Boolean) @@ -168,6 +181,7 @@ <p id="status" class="muted" role="status">Your passkey signs this request.</p> <div class="muted">Signed in as ${text(email)}. Not you? ${otherAccountForm(`${VERIFICATION_PATH}?${new URLSearchParams({ user_code: userCode })}`)}</div>`; const shown = { + mindMark: await mindMarkOf(env), status: error ? 403 : 200, script: `${signScript(mind)}${PRESS_SCRIPT}`, };
M core/auth-worker/src/email-sign-in.ts
@@ -12,6 +12,12 @@ // or with none (`memberRefusal`): the passkey, Cloudflare Access for an owner // (./access-sign-in.ts), an owner's sign-in link for an added member // +// AN APP MAY NAME WHOSE ADDRESS A CODE SIGNS IN (`allowedEmails`, `allowedEmailPatterns`, +// ./asking-app.ts). For such an app the address page says so, and an address that the app does +// not name is refused there with that reason, for every such address alike, a member's too: no +// challenge is made and nothing is mailed, so it spends none of the limits below. The words name +// the domains of the app's patterns and never an address that it names. +// // A SIGN-IN THAT DOES NOT NAME "email" HAS NO SUCH PAGE: an app says how its people sign in // (./asking-app.ts `signInOf`), and for one that names the passkey alone, as for the control // plane's own sign-in, the address page leads back to the sign-in page, and no code is mailed in @@ -26,7 +32,13 @@ import { zoneOf } from "iterate/mind-config"; import { z } from "zod"; import { AccountFacts } from "./account-facts.ts"; -import { type AskingApp, askingAppOf, signInOf } from "./asking-app.ts"; +import { + allowedEmailsWords, + type AskingApp, + askingAppOf, + signInOf, + takesAddress, +} from "./asking-app.ts"; import { isBlocked } from "./blocked.ts"; import { isOwner } from "./config.ts"; import { emailSessionCookie, MIND_FORM_PATH, sessionsOverRemoved } from "./cookies.ts"; @@ -170,7 +182,7 @@ imageOrigin: asking?.imageOrigin, status: error ? 400 : 200, body: `${asking?.heading || `<h1>Sign in to ${text(mind)}</h1>`} - <p class="muted">Enter your email. We send you a code to sign in with.</p> + <p class="muted">Enter your email. We send you a code to sign in with.${onlyAt(signIn)}</p> ${ruleAbove(env, asking)} ${error ? `<p role="alert">${text(error)}</p>` : ""} <form method="post" action="${EMAIL_SIGN_IN_PATH}" class="stack"> @@ -183,6 +195,12 @@ }); } +/** One more sentence on the address page of an app that names whose address it takes. */ +const onlyAt = ({ mailedCode }: SignIn) => { + const words = mailedCode && allowedEmailsWords(mailedCode); + return words ? ` ${text(words)}` : ""; +}; + /** The way to "sign in with your mind" (./mind-sign-in.ts), for an app that names it. */ const mindWay = (next: string) => `<form method="get" action="${MIND_FORM_PATH}" class="stack"> <input type="hidden" name="next" value="${text(next)}"> @@ -202,6 +220,11 @@ const email = typed.trim().toLowerCase(); const again = (error: string) => emailAddressPage(env, next, signIn, error, typed); if (!z.email().safeParse(email).success) return again("Enter an email address."); + // an app that names whose address it takes: no code for any other, and no challenge + if (signIn.mailedCode && !takesAddress(signIn.mailedCode, email)) { + console.info({ event: "auth.sign-in-refused", method: "email", reason: "not-allowed" }); + return again(`${allowedEmailsWords(signIn.mailedCode)} Use such an address.`); + } const id = crypto.randomUUID(); const code = String(crypto.getRandomValues(new Uint32Array(1))[0]! % 1_000_000).padStart(6, "0"); // both are read for every address alike, so the answer's time says nothing
M core/auth-worker/src/enrolment.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/http.ts
@@ -51,6 +51,7 @@ import { passkeySignInResponse } from "./passkey-sign-in.ts"; import { selfTestResponse } from "./self-test.ts"; import { SESSIONS_PATH, sessionsResponse } from "./sessions-page.ts"; +import { mindMarkOf } from "./mind-mark.ts"; import { AFTER_SIGN_OUT, SIGN_IN_PATH, signOutResponse } from "./sign-in.ts"; import { statementDraftsResponse } from "./statement-drafts.ts"; import { statementsResponse } from "./statements.ts"; @@ -147,6 +148,8 @@ if (methods[0] === "email") return emailAddressPage(env, next, signIn); return signInPage({ mind: configOf(env).controlPlaneHostname, + // an app's own sign-in shows the app's icon + mindMark: signIn.app ? null : await mindMarkOf(env), next, app: signIn.app, offersEmail: methods.includes("email"),
M core/auth-worker/src/members.test.ts
@@ -7,6 +7,7 @@ import { configVars, keyRows, stackKeyPair } from "./test-support.ts"; const LINK = "events.iterate.com/account/member-link-made"; +const REMOVE_KEYS = "events.iterate.com/account/member-keys-removed"; test.for([ ["a sign-in link for a member", "link"], @@ -33,9 +34,11 @@ ).toContain("This takes a press of your passkey"); expect(stack).toMatchObject({ changed: [] }); const signed = await stack.owner.signed(LINK, { email: "member@example.org" }); - expect(await stack.post({ action: "link", email: "member@example.org", signed })).toContain( - "Give this link to member@example.org", - ); + const linkPage = await stack.post({ action: "link", email: "member@example.org", signed }); + expect(linkPage).toContain("Sign-in link for member@example.org"); + expect(linkPage).toContain("Give this link to member@example.org"); + expect(linkPage).toContain('data-copy="https://iterate.example.com/keys/first#'); + expect(linkPage).toContain(">Copy link</button>"); expect(stack).toMatchObject({ changed: ["a link for member@example.org"] }); }); @@ -52,6 +55,107 @@ expect(stack).toMatchObject({ changed: [] }); }); +test("removing a lost passkey with make-link removes keys, ends access, and immediately makes a sign-in link with a copy button", async () => { + const stack = await stackOf({ + withPasskey: ["member@example.org"], + kept: [ + "grant:user_member:g1", + "token:user_member:g1:t1", + "grant:user_other:g9", + "token:user_other:g9:t1", + ], + }); + const signed = await stack.owner.signed(REMOVE_KEYS, { + email: "member@example.org", + makeLink: true, + }); + const page = await stack.post({ + action: "remove-keys", + email: "member@example.org", + "make-link": "1", + signed, + }); + expect(page).toContain("Sign-in link for member@example.org"); + expect(page).toContain( + "member@example.org has no keys now, and is signed out of every app and device.", + ); + expect(page).toContain('data-copy="https://iterate.example.com/keys/first#'); + expect(page).toContain(">Copy link</button>"); + expect(page).toContain("Give this link to member@example.org"); + expect(stack).toMatchObject({ + changed: ["keys removed of member@example.org", "a link for member@example.org"], + kept: ["grant:user_other:g9", "token:user_other:g9:t1"], + }); +}); + +test("removing a lost passkey without make-link removes keys and makes no sign-in link", async () => { + const stack = await stackOf({ withPasskey: ["member@example.org"] }); + const signed = await stack.owner.signed(REMOVE_KEYS, { email: "member@example.org" }); + const page = await stack.post({ + action: "remove-keys", + email: "member@example.org", + signed, + }); + expect(page).toContain( + "member@example.org has no keys now, and is signed out of every app and device.", + ); + expect(page).toContain("Make a sign-in link for this member below when you are ready"); + expect(page).not.toContain('class="link-callout"'); + expect(stack).toMatchObject({ changed: ["keys removed of member@example.org"] }); +}); + +test("a remove-keys signature must match whether a sign-in link is requested", async () => { + const stack = await stackOf({ withPasskey: ["member@example.org"] }); + const withoutLink = await stack.owner.signed(REMOVE_KEYS, { email: "member@example.org" }); + expect( + await stack.post({ + action: "remove-keys", + email: "member@example.org", + "make-link": "1", + signed: withoutLink, + }), + ).toContain("the signed statement does not match this request"); + const withLink = await stack.owner.signed(REMOVE_KEYS, { + email: "member@example.org", + makeLink: true, + }); + expect( + await stack.post({ + action: "remove-keys", + email: "member@example.org", + signed: withLink, + }), + ).toContain("the signed statement does not match this request"); + expect(stack).toMatchObject({ changed: [] }); +}); + +test("removing keys of a former member with make-link removes keys but makes no sign-in link", async () => { + const stack = await stackOf({ + members: ["member@example.org"], + withPasskey: ["former@example.org"], + }); + const signed = await stack.owner.signed(REMOVE_KEYS, { + email: "former@example.org", + makeLink: true, + }); + const page = await stack.post({ + action: "remove-keys", + email: "former@example.org", + "make-link": "1", + signed, + }); + expect(page).toContain("No sign-in link was made because former@example.org is not a member."); + expect(page).not.toContain('class="link-callout"'); + expect(stack).toMatchObject({ changed: ["keys removed of former@example.org"] }); +}); + +test("GET /members offers making a sign-in link by default when removing a lost passkey", async () => { + const stack = await stackOf(); + const page = await stack.get(); + expect(page).toContain('name="make-link" value="1" checked'); + expect(page).toContain("Remove keys and make a sign-in link"); +}); + test("removal of a member ends what the member was given, each grant with its tokens, and no other person's", async () => { const stack = await stackOf({ kept: [ @@ -90,11 +194,13 @@ /** A stack with an owner who is signed in with a passkey, and two added members. Of D1, what the * members page and a statement's check read and write. `changed` names each write that counts. */ async function stackOf({ + members = ["member@example.org", "other@example.org"], withPasskey = [], kept = [], -}: { withPasskey?: string[]; kept?: string[] } = {}) { +}: { members?: string[]; withPasskey?: string[]; kept?: string[] } = {}) { const [ownerKey, otherKey, stackKey] = [await keyPair(), await keyPair(), await stackKeyPair()]; const changed: string[] = []; + const heldPasskeys = new Set(withPasskey); // the OAuth library's store, by its keys: a grant, and each token of it under the grant's name const store = new Map( kept.map((name) => [name, { id: name.split(":")[2], userId: name.split(":")[1] }]), @@ -117,18 +223,26 @@ changed.push(`${String(bound[0])} removed`); return { email: bound[0] }; } - if (sql.includes("from members where email")) return { 1: 1 }; + if (sql.includes("from members where email")) + return members.includes(String(bound[0])) ? { 1: 1 } : null; if (sql.startsWith("select id from users where email")) return { id: `user_${String(bound[0]).split("@")[0]}` }; if (sql.includes("format = 'webauthn'")) - return withPasskey.includes(String(bound[0])) ? { 1: 1 } : null; + return heldPasskeys.has(String(bound[0])) ? { 1: 1 } : null; throw new Error(`not expected: ${sql}`); }, all: async () => { const session = sessions.statementOf(sql, bound); if (session) return session.all(); - if (sql.startsWith("update keys set revoked_at")) - changed.push(`keys removed of ${String(bound[1])}`); + if (sql.startsWith("update keys set revoked_at")) { + const email = String(bound[1]); + if (!heldPasskeys.has(email)) return { results: [] }; + heldPasskeys.delete(email); + changed.push(`keys removed of ${email}`); + return { + results: [{ id: "key_1", label: "Passkey", userId: `user_${email.split("@")[0]}` }], + }; + } return { results: [] }; }, run: async () => { @@ -195,6 +309,18 @@ }, owner: member(ownerKey), other: member(otherKey), + /** The members page itself, fetched by the owner's session. */ + get: async () => { + const answer = await membersResponse( + env, + new Request(`${ISSUER}/members`, { method: "GET", headers: { cookie } }), + async () => null, + ); + if (!answer) throw new Error("the members page did not answer"); + return (await answer.text()).replaceAll(/&#(\d+);/g, (_all, code) => + String.fromCharCode(Number(code)), + ); + }, /** The members page's own form, posted by the owner's session. Answers the page's text. */ post: async (fields: Record<string, string>) => { const answer = await membersResponse(
M core/auth-worker/src/members.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/auth-worker/src/mind-mark.test.ts
@@ -0,0 +1,230 @@ +// The mind's own logo at the head of the sign-in and consent pages (./mind-mark.ts): what the +// issuer takes from the mind's profile, how long it keeps it, and how the pages show it. +import { expect, test, vi } from "vitest"; +import type { Env } from "./env.ts"; +import { mindMarkOf } from "./mind-mark.ts"; +import { consentPage, signInPage } from "./pages.ts"; +import { configVars } from "./test-support.ts"; + +const WEBSITE = "https://example.com"; +const ICON = `${WEBSITE}/favicon.svg`; +const TILE = `<div class="tile" data-mind-mark="icon"><img src="${ICON}" alt="" referrerpolicy="no-referrer"></div>`; + +test("the mind's logo is the icon of its website's profile, read once in five minutes with no redirect followed", async () => { + const stack = stackOf(); + using web = answers(() => Response.json({ name: "Ada's mind", description: "", icon: ICON })); + expect(await mindMarkOf(stack.env)).toEqual({ html: TILE, origin: WEBSITE }); + expect(await mindMarkOf(stack.env)).toEqual({ html: TILE, origin: WEBSITE }); + expect(web).toMatchObject({ + asked: [{ url: `${WEBSITE}/.well-known/iterate-profile`, redirect: "manual" }], + }); +}); + +test.for([ + { name: "a mind with no icon", answer: () => Response.json({ name: "Ada", icon: null }) }, + { name: "a website with no profile", answer: () => new Response("Not found", { status: 404 }) }, + // the website's own origin over https, and nothing else + ...[ + "https://elsewhere.test/logo.svg", + "https://sub.example.com/logo.svg", + "http://example.com/favicon.svg", + "//elsewhere.test/logo.svg", + "/favicon.svg", + "javascript:alert(1)", + `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"/>`, + ].map((icon) => ({ name: `an icon at ${icon}`, answer: () => Response.json({ icon }) })), +])("$name is no logo: the pages show iterate's mark", async ({ answer }) => { + const stack = stackOf(); + using _web = answers(answer); + expect(await mindMarkOf(stack.env)).toBeNull(); +}); + +test.for([ + { name: "a 503", answer: () => new Response("down", { status: 503 }) }, + { name: "a redirect", answer: () => new Response(null, { status: 302 }) }, + { name: "no answer", answer: () => Promise.reject(new Error("no answer")) }, + { name: "a text that is no JSON", answer: () => new Response("<!doctype html>") }, + { name: "an object that is no profile", answer: () => Response.json({ icon: 7 }) }, +])( + "a website that answers with $name has said nothing new: the logo is what it was, and the website is asked again after a minute", + async ({ answer }) => { + const stack = stackOf(); + // nothing kept yet: no logo, and the next page does not ask again + { + using web = answers(answer); + expect(await mindMarkOf(stack.env)).toBeNull(); + expect(await mindMarkOf(stack.env)).toBeNull(); + expect(web.asked).toHaveLength(1); + } + // a logo that was kept stays + stack.keep({ icon: ICON, askAfter: 0 }); + using _web = answers(answer); + const before = Date.now(); + expect(await mindMarkOf(stack.env)).toMatchObject({ html: TILE }); + await stack.asked(); + expect(stack.kept()).toMatchObject({ icon: ICON }); + expect(Math.round((stack.kept().askAfter - before) / 60_000)).toBe(1); + }, +); + +test("a page that finds the logo older than five minutes shows what is kept and waits for nothing: the website is asked after the answer", async () => { + const stack = stackOf(); + stack.keep({ icon: ICON, askAfter: 0 }); + let answered = () => {}; + const slow = new Promise<void>((resolve) => (answered = resolve)); + using web = answers(async () => { + await slow; + return Response.json({ icon: null }); + }); + // the page has its logo while the website has not answered yet + expect(await mindMarkOf(stack.env)).toMatchObject({ html: TILE }); + expect(web.asked).toHaveLength(1); + answered(); + await stack.asked(); + // the website took its icon away: the next page shows iterate's mark + expect(await mindMarkOf(stack.env)).toBeNull(); +}); + +test("a logo never stops a page: a store that fails at the read or at the write, and a profile that is too long, leave iterate's mark or the logo that was read", async () => { + const profile = () => Response.json({ icon: ICON }); + // the store does not answer: no logo, and no error + { + const stack = stackOf(); + stack.env.OAUTH_KV.get = () => Promise.reject(new Error("the store is down")); + using _web = answers(profile); + expect(await mindMarkOf(stack.env)).toBeNull(); + } + // the row cannot be written: this page has the logo that was read + { + const stack = stackOf(); + stack.env.OAUTH_KV.put = () => Promise.reject(new Error("too many writes of one key")); + using _web = answers(profile); + expect(await mindMarkOf(stack.env)).toMatchObject({ html: TILE }); + } + // a profile over the bound is read no further than the bound, and is no word of the website + const stack = stackOf(); + let sent = 0; + let cancelled = false; + using _web = answers( + () => + new Response( + new ReadableStream({ + pull(stream) { + sent += 1; + stream.enqueue(new TextEncoder().encode(" ".repeat(8_000))); + }, + cancel: () => void (cancelled = true), + }), + ), + ); + expect(await mindMarkOf(stack.env)).toBeNull(); + expect({ cancelled, readNoFurther: sent < 6 }).toEqual({ cancelled: true, readNoFurther: true }); +}); + +test("a kept row is read again as it is shown: an icon of another origin in it is no logo", async () => { + const stack = stackOf(); + stack.keep({ icon: "https://elsewhere.test/logo.svg", askAfter: Date.now() + 60_000 }); + expect(await mindMarkOf(stack.env)).toBeNull(); +}); + +test("the consent page and the mind's sign-in page show the mind's logo where iterate's mark was, and the page's policy allows its one origin beside the client's", async () => { + const mindMark = { html: TILE, origin: WEBSITE }; + const consent = (mark: typeof mindMark | null, details: object = {}) => + consentPage({ + details: { + clientName: "Claude", + redirectUri: "https://claude.ai/api/mcp/auth_callback", + redirectHost: "claude.ai", + redirectIsLoopback: false, + ...details, + } as never, + handle: "handle", + email: "owner@example.net", + mind: "iterate.example.com", + mindMark: mark, + resource: "its MCP server", + here: "/oauth2/auth?client_id=c&state=s", + headers: new Headers(), + }); + const withLogo = consent(mindMark); + expect(withLogo.headers.get("content-security-policy")?.split("; ")).toContain( + `img-src data: ${WEBSITE}`, + ); + const html = await withLogo.text(); + // the mind's logo, the dotted line, the client's tile: and no mark of iterate's + expect(html).toContain(`<div class="asks">${TILE}<span class="joins" aria-hidden="true"></span>`); + expect(html).not.toContain(`class="mark"`); + // a mind with no logo is as before + expect(await consent(null).text()).toContain(`<div class="asks"><div class="mark"`); + // a client with a logo of its own: both origins, and both pictures + const both = consent(mindMark, { + clientName: "Notes", + redirectUri: "https://notes.example.org/callback", + redirectHost: "notes.example.org", + clientDomain: "example.org", + logoUri: "https://cdn.example.org/logo.png", + }); + expect(both.headers.get("content-security-policy")?.split("; ")).toContain( + `img-src data: https://cdn.example.org ${WEBSITE}`, + ); + expect(await both.text()).toContain( + `${TILE}<span class="joins" aria-hidden="true"></span><div class="tile" data-client-mark="logo">`, + ); + // a client with no tile: the mind's logo is the card's one mark + const alone = consent(mindMark, { + clientName: "Notes", + redirectUri: "https://notes.example.org/callback", + redirectHost: "notes.example.org", + }); + expect(await alone.text()).toContain(`<main class="centered">${TILE}<h1>`); + + const signIn = (mark: typeof mindMark | null) => + signInPage({ + mind: "iterate.example.com", + mindMark: mark, + next: "/oauth2/auth?client_id=c", + app: null, + offersEmail: false, + offersGuest: false, + asksAtOpen: false, + noPasskeyYet: false, + }).text(); + expect(await signIn(mindMark)).toContain(`<main class="centered">${TILE}<h1>Sign in to`); + expect(await signIn(null)).toContain(`<main class="centered"><div class="mark"`); +}); + +type Kept = { icon: string | null; askAfter: number }; + +/** A mind at `iterate.example.com` whose website is `https://example.com`, with the issuer's KV + * as a map. */ +function stackOf() { + const kv = new Map<string, string>(); + // the cast: the logo's code reads the config and this one binding + const env = { + ...configVars(), + OAUTH_KV: { + get: async (key: string) => JSON.parse(kv.get(key) || "null"), + put: async (key: string, value: string) => void kv.set(key, value), + }, + } as unknown as Env; + return { + env, + keep: (row: Kept) => void kv.set("iterate-mind-mark", JSON.stringify(row)), + kept: () => JSON.parse(kv.get("iterate-mind-mark")!) as Kept, + // what a page left to run after its answer has written its row + asked: () => + vi.waitFor(() => + expect(JSON.parse(kv.get("iterate-mind-mark")!).askAfter).toBeGreaterThan(0), + ), + }; +} + +/** The web for a test: every request gets `answer`, and `asked` lists them. */ +function answers(answer: () => Response | Promise<Response>) { + const asked: { url: string; redirect?: string }[] = []; + const spy = vi.spyOn(globalThis, "fetch").mockImplementation(async (input, init) => { + asked.push({ url: String(input), redirect: init?.redirect }); + return answer(); + }); + return { asked, [Symbol.dispose]: () => spy.mockRestore() }; +}
A core/auth-worker/src/mind-mark.ts
@@ -0,0 +1,125 @@ +// mind-mark.ts — THE MIND'S OWN LOGO, at the head of the pages where a person signs in to the +// mind or lets a client in: the sign-in page, the chooser, the consent page and a device's +// confirmation. A person sees which mind they give access to by its own picture, where the pages +// showed iterate's mark before. +// +// WHERE THE LOGO COMES FROM. The mind's website answers what the mind says of itself, for anyone, +// at `/.well-known/iterate-profile` of its zone: `{ name, description, icon }` (the template's +// profile.ts). This Worker reads it over the public internet, as it reads an app's description +// (./asking-app.ts), and follows no redirect. The icon counts only over https from the website's +// own origin, so the page's policy allows that one origin. Nothing else of the profile is read +// here: the pages name the mind by its control-plane hostname, which the mind's code cannot write. +// +// THE MIND'S CODE WROTE IT, and that code may be hostile. So the logo is shown as an image +// (`<img>`, which runs nothing), with no referrer, and it proves nothing: the words of each page +// say which mind it is and where access goes. A mind that draws another's mark as its own logo +// changes no word of the page. +// +// NO PAGE WAITS FOR IT TWICE. The answer is kept for five minutes. A page that finds it older +// shows what is kept and asks again after the answer (`waitUntil`). Only a page that finds +// nothing kept waits, for two seconds at most. A website that does not answer, or whose answer +// is no profile, has said nothing new: the logo is what it was, or iterate's mark, and the +// website is asked again after a minute. A website with no icon (`icon: null`, a 404) has said +// so: the pages show iterate's mark. +import { waitUntil } from "cloudflare:workers"; +import { reportIssue } from "iterate/lib"; +import { zoneOf } from "iterate/mind-config"; +import { z } from "zod"; +import { configOf, type Env } from "./env.ts"; +import { text } from "./pages.ts"; + +/** Where a mind's website answers its profile (the template's profile.ts `PROFILE_PATH`). */ +const PROFILE_PATH = "/.well-known/iterate-profile"; + +const KEY = "iterate-mind-mark"; +/** A profile is a name, a description of a thousand characters and an address. */ +const PROFILE_MAX_BYTES = 20_000; + +/** The mind's logo for a page: the tile's HTML, and the one origin that its image comes from. */ +export type MindMark = { html: string; origin: string }; + +type Kept = { icon: string | null; askAfter: number }; + +/** The mind's logo as a page shows it, or null for a mind that has none: the page then shows + * iterate's mark. */ +export async function mindMarkOf(env: Env): Promise<MindMark | null> { + // A LOGO NEVER STOPS A PAGE: when the store fails, the page shows iterate's mark. + return shown(env).catch((error) => { + reportIssue("mind-mark.failed", error); + return null; + }); +} + +async function shown(env: Env): Promise<MindMark | null> { + const config = configOf(env); + // the mind's website is the apex of the zone that its control plane is in + const origin = `https://${zoneOf(config, config.controlPlaneHostname) || config.zones[0]}`; + let kept = await env.OAUTH_KV.get<Kept>(KEY, "json"); + if (!kept) kept = await read(env, origin, null); + else if (kept.askAfter <= Date.now()) + waitUntil(read(env, origin, kept).catch((error) => reportIssue("mind-mark.failed", error))); + // a row is read again as it is shown: only an icon of the website's own origin is one + const icon = kept.icon && iconAt(kept.icon, origin); + if (!icon) return null; + return { + html: `<div class="tile" data-mind-mark="icon"><img src="${text(icon)}" alt="" referrerpolicy="no-referrer"></div>`, + origin, + }; +} + +/** Asks the website, and keeps what it said. `last` is what was kept before. */ +async function read(env: Env, origin: string, last: Kept | null): Promise<Kept> { + const heard = await fetch(`${origin}${PROFILE_PATH}`, { + headers: { accept: "application/json" }, + redirect: "manual", + signal: AbortSignal.timeout(2000), + }) + .then(async (answer) => { + // a website with no profile has no logo; any other answer but a profile is no word of it + if (answer.status === 404) return { icon: null }; + if (answer.status !== 200) return null; + const profile = await textUpTo(answer, PROFILE_MAX_BYTES); + // too long, or empty: no profile + if (!profile) return null; + const said = z + .object({ icon: z.string().max(2048).nullable() }) + .safeParse(JSON.parse(profile)); + return said.success ? { icon: said.data.icon && iconAt(said.data.icon, origin) } : null; + }) + .catch(() => null); + const kept = heard + ? { ...heard, askAfter: Date.now() + 5 * 60_000 } + : { icon: last?.icon || null, askAfter: Date.now() + 60_000 }; + // a row that could not be written is asked for again by the next page: this page has its answer + await env.OAUTH_KV.put(KEY, JSON.stringify(kept), { expirationTtl: 24 * 3600 }).catch((error) => + reportIssue("mind-mark.not-kept", error), + ); + return kept; +} + +/** The answer's text, read up to `maxBytes` and no further: null for a longer one, whose rest is + * not read. The profile is anyone's to write, so its length is not trusted. */ +async function textUpTo(answer: Response, maxBytes: number): Promise<string | null> { + if (!answer.body) return ""; + const reader = answer.body.getReader(); + const chunks: Uint8Array[] = []; + let bytes = 0; + for (;;) { + const { done, value } = await reader.read(); + if (done) break; + bytes += value.byteLength; + if (bytes > maxBytes) { + await reader.cancel(); + return null; + } + chunks.push(value); + } + return new TextDecoder().decode(await new Blob(chunks).arrayBuffer()); +} + +/** `icon` as an address of the website's own origin over https, or null. */ +function iconAt(icon: string, origin: string): string | null { + if (!URL.canParse(icon)) return null; + const url = new URL(icon); + return url.origin === origin && url.protocol === "https:" ? url.href : null; +}
M core/auth-worker/src/mind-sign-in.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/mind-sign-in.ts
@@ -32,7 +32,9 @@ // LOGIN CSRF. Another site can start this in a visitor's browser with ITS OWN mind, and finish it: // the visitor is then a member of the attacker's mind here. The state binds the return to the // browser that started, which bounds it to that; an app that shows what belongs to a mind says -// whose mind it is first (iterate/sdk `auth.person`). +// whose mind it is first (iterate/sdk `auth.person`). It replaces nobody: beside a person's +// session that the app takes, this sign-in is one of two choices on the chooser's page, and only +// the person's press there makes them the mind's person (./authorize.ts `chosen`). // // A STRANGER TYPES THE HOSTNAME, so this Worker fetches what anyone names: https alone, a 5-second // limit, counted for each visitor's address (`admitted`, "mind"), and the page answers one of three @@ -59,12 +61,13 @@ mindFormOf, mindFreshCookie, mindSessionCookie, + requestHashOf, } from "./cookies.ts"; import { admitted, TOO_MANY } from "./device/limits.ts"; import { configOf, type Env, issuerOf } from "./env.ts"; import { honouredNext } from "./key-rules.ts"; import { mindSignerOf } from "./minds.ts"; -import { mindHostResourceOf } from "./oauth.ts"; +import { AUTHORIZE_ENDPOINT, mindHostResourceOf } from "./oauth.ts"; import { appSignIn, errorPage, page, text } from "./pages.ts"; import { stackKeyOf } from "./stack-key.ts"; import { userOf } from "./users.ts"; @@ -263,8 +266,25 @@ // the app's next authorization takes this sign-in as the answer to a prompt, once // (./authorize.ts): it was the person's answer, made after any sign-out if (form.app) - headers.append("set-cookie", await mindFreshCookie(env, { user: user.id, app: form.app })); + headers.append( + "set-cookie", + await mindFreshCookie(env, { + user: user.id, + app: form.app, + request: await requestBegunFor(env, form.next), + }), + ); return facts.on(new Response(null, { status: 303, headers })); +} + +/** The hash of the authorization request that a sign-in was begun for, when `next` is one of + * this issuer (the sign-in page's): as ./authorize.ts reads it, without `prompt`. Null for an + * app's own page, whose request ingress makes after the return. */ +async function requestBegunFor(env: Env, next: string) { + const url = new URL(next); + if (url.origin !== issuerOf(env) || url.pathname !== AUTHORIZE_ENDPOINT) return null; + url.searchParams.delete("prompt"); + return requestHashOf(url.pathname + url.search); } /** THE PERSON B VOUCHES FOR in `sent`, the envelope as JSON text, or why not. Every field is
M core/auth-worker/src/oauth.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/oauth.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/auth-worker/src/owner-email-patterns.test.ts
@@ -0,0 +1,177 @@ +// owner-email-patterns.test.ts — WHAT AN OWNER EMAIL PATTERN OPENS, AND WHAT IT DOES NOT +// (iterate/mind-config `isOwnerEmail`): on a mind at example.com with one owner by address, one +// added member, and the pattern `*@company.example`. +import { expect, test, vi } from "vitest"; +import { sessionCookie, sessionOf } from "./cookies.ts"; +import { enrolmentCookie } from "./enrolment.ts"; +import type { Env } from "./env.ts"; +import { authResponse } from "./http.ts"; +import { isMember, isMemberSession } from "./members.ts"; +import { sqliteStack } from "./test-support.ts"; +import { userOf } from "./users.ts"; + +const OWNER = "ada@adas-mail.example"; +const ADDED = "bo@bos-mail.example"; +const AT_PATTERN = "cy@company.example"; +const PATTERNS = ["*@company.example"]; +const ISSUER = "https://iterate.example.com"; +const ctx = { waitUntil() {}, passThroughOnException() {} } as unknown as ExecutionContext; +const NOT_AT_PATTERN = [ + "cy@sub.company.example", + "cy@company.example.evil.example", + "cy@evilcompany.example", + "cy@company.example@evil.example", + "cy@other.example", +]; + +test("with no pattern, and with an empty list, the members are the owner and the added member alone", async () => { + for (const ownerEmailPatterns of [undefined, []]) { + const { env } = stackOf({ ownerEmailPatterns }); + expect(await membersAmong(env, [OWNER, ADDED, AT_PATTERN, ...NOT_AT_PATTERN])).toEqual([ + OWNER, + ADDED, + ]); + } +}); + +test("a pattern makes an address at exactly its domain a member, and leaves every other answer as it was", async () => { + const { env } = stackOf({ ownerEmailPatterns: PATTERNS }); + expect( + await membersAmong(env, [OWNER, ADDED, AT_PATTERN, " Cy@Company.Example ", ...NOT_AT_PATTERN]), + ).toEqual([OWNER, ADDED, AT_PATTERN, " Cy@Company.Example "]); +}); + +test("a session acts as a member by a pattern only when a passkey opened it: a mailed code's never does", async () => { + const { env } = stackOf({ ownerEmailPatterns: PATTERNS }); + expect(await isMemberSession(env, { method: "passkey", email: AT_PATTERN })).toBe(true); + expect(await isMemberSession(env, { method: "email", email: AT_PATTERN })).toBe(false); + expect(await isMemberSession(env, { method: "passkey", email: NOT_AT_PATTERN[0]! })).toBe(false); +}); + +test("Cloudflare's proof of an address at a pattern opens the first passkey's session, as an owner's does; with no pattern it opens none", async () => { + const request = new Request("https://iterate.example.com/sign-in/access"); + const withPattern = stackOf({ ownerEmailPatterns: PATTERNS }); + expect( + await enrolmentCookie(withPattern.env, request, AT_PATTERN, "cloudflare-access"), + ).toMatchObject({ setCookie: expect.any(String) }); + // an owner's link is for an added member: an owner by a pattern is an owner + expect(await enrolmentCookie(withPattern.env, request, AT_PATTERN, "member-link")).toEqual({ + refused: `${AT_PATTERN} is an owner of iterate.example.com. An owner's link signs in no owner.`, + }); + for (const email of NOT_AT_PATTERN) + expect( + await enrolmentCookie(withPattern.env, request, email, "cloudflare-access"), + ).toMatchObject({ refused: expect.stringContaining("is not an owner") }); + expect( + await enrolmentCookie(stackOf().env, request, AT_PATTERN, "cloudflare-access"), + ).toMatchObject({ refused: expect.stringContaining("is not an owner") }); +}); + +test("a deploy that takes the pattern away ends the membership of the people it named", async () => { + const stack = stackOf({ ownerEmailPatterns: PATTERNS }); + expect(await isMember(stack.env, AT_PATTERN)).toBe(true); + const without = stack.envOf({ ownerEmailPatterns: undefined }); + expect(await isMember(without, AT_PATTERN)).toBe(false); + expect(await isMemberSession(without, { method: "passkey", email: AT_PATTERN })).toBe(false); + expect(await membersAmong(without, [OWNER, ADDED])).toEqual([OWNER, ADDED]); +}); + +// A PERSON WHO LEFT: the mail provider closes the mailbox, and the passkey that the person added +// still works. An owner's block is what ends that one person, while the pattern stays. +test("an owner's block ends one person of a pattern: no member, no session, no way back in; the others of the pattern stay", async () => { + const stack = stackOf({ ownerEmailPatterns: PATTERNS }); + const { env } = stack; + const request = new Request("https://iterate.example.com/sign-in/access"); + const owner = await passkeyCookie(env, OWNER); + const leaver = await passkeyCookie(env, AT_PATTERN); + const asLeaver = new Request("https://iterate.example.com/keys", { headers: { cookie: leaver } }); + expect(await sessionOf(env, asLeaver)).toMatchObject({ email: AT_PATTERN }); + // a removal would change nothing, and says what does + expect(await posted(env, owner, "remove", AT_PATTERN)).toContain("Block this address"); + expect(await isMember(env, AT_PATTERN)).toBe(true); + + expect(await posted(env, owner, "block", AT_PATTERN)).toContain( + `${AT_PATTERN} is blocked: it is no owner and no member now`, + ); + expect(await membersAmong(env, [OWNER, ADDED, AT_PATTERN, "cy+tag@company.example"])).toEqual([ + OWNER, + ADDED, + ]); + expect(await isMember(env, "dee@company.example")).toBe(true); + expect(await isMemberSession(env, { method: "passkey", email: AT_PATTERN })).toBe(false); + expect(await sessionOf(env, asLeaver)).toBeNull(); + // neither Cloudflare's proof nor the recovery command's link opens a first passkey's session + for (const proof of ["cloudflare-access", "recovery-link"] as const) + expect(await enrolmentCookie(env, request, AT_PATTERN, proof)).toEqual({ + refused: `${AT_PATTERN} is not a member of iterate.example.com.`, + }); + // a deploy that takes the pattern away and one that brings it back: the block is still there + expect(await isMember(stack.envOf({ ownerEmailPatterns: undefined }), AT_PATTERN)).toBe(false); + expect(await isMember(stack.envOf({ ownerEmailPatterns: PATTERNS }), AT_PATTERN)).toBe(false); + + expect(await posted(env, owner, "unblock", AT_PATTERN)).toContain("is no longer blocked"); + expect(await isMember(env, AT_PATTERN)).toBe(true); +}); + +test("a block of a person of a pattern takes their row of /members with it, and an owner by address and an added member are never blocked", async () => { + const stack = stackOf({ ownerEmailPatterns: PATTERNS }); + const { env } = stack; + stack.db + .prepare("insert into members (email, added_by, added_at) values (?, ?, 0)") + .run(AT_PATTERN, OWNER); + const owner = await passkeyCookie(env, OWNER); + await posted(env, owner, "block", AT_PATTERN); + expect(stack.db.prepare("select email from members order by email").all()).toEqual([ + { email: ADDED }, + ]); + expect(await isMember(env, AT_PATTERN)).toBe(false); + for (const member of [OWNER, ADDED]) + expect(await posted(env, owner, "block", member)).toContain("a member is never blocked"); + expect(stack.db.prepare("select email from blocked").all()).toEqual([{ email: AT_PATTERN }]); +}); + +function stackOf(config: { ownerEmailPatterns?: string[] } = {}) { + const stack = sqliteStack({ zones: ["example.com"], ownerEmails: [OWNER], ...config }); + vi.stubGlobal("fetch", async () => new Response("Not found", { status: 404 })); + stack.db + .prepare("insert into members (email, added_by, added_at) values (?, ?, 0)") + .run(ADDED, OWNER); + return stack; +} + +/** The cookie of `email`'s session by a passkey, which the test gives them. */ +async function passkeyCookie(env: Env, email: string) { + const person = await userOf(env.DB, email); + const key = `key-of-${person.id}`; + await env.DB.prepare( + `insert into keys (id, user_id, public_key, format, label, added_via, added_by, added_at) + values (?2, ?1, ?2, 'webauthn', 'a passkey', 'keys-page', ?1, 1)`, + ) + .bind(person.id, key) + .run(); + const { setCookie } = await sessionCookie(env, new Request(ISSUER), person, key); + return setCookie.split(";")[0]!; +} + +/** The text of the members page after `cookie`'s person posted `action` for `email`. */ +async function posted(env: Env, cookie: string, action: string, email: string) { + const answer = await authResponse( + new Request(`${ISSUER}/members`, { + method: "POST", + headers: { origin: ISSUER, cookie }, + body: new URLSearchParams({ action, email }), + }), + env, + ctx, + ); + // a removal answers with a redirect, and the page writes an apostrophe as a numbered entity + return (await answer.text()).replaceAll(/&#(\d+);/g, (_all, code) => + String.fromCharCode(Number(code)), + ); +} + +async function membersAmong(env: ReturnType<typeof stackOf>["env"], emails: string[]) { + const members: string[] = []; + for (const email of emails) if (await isMember(env, email)) members.push(email); + return members; +}
M core/auth-worker/src/page-tag.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/pages.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/pages.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/stack-key.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/test-support.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/auth-worker/src/working-key.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/env.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/http.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/mail.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/mail.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/mind-transport.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/provided-mind.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/provided-mind.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/session-mind.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/stamp.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/boundary-worker/src/worker.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/AGENTS.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/agent-kinds.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/agent-tests/processor.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/agent/llm-apis/openai-responses.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/api.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps.md
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/dash/agent-catalog.ts
@@ -0,0 +1,36 @@ +// agent-catalog.ts — WHICH CONTEXT IS AN AGENT: the catalog on /agents, read in one call, and the +// test of one path against it. api.ts `taskDeps` uses both, since a follower's row writes +// to the path it names. +// @ts-expect-error -- a plain browser module of the Dash, with no types; this file uses `agentPathOf` alone +import { agentPathOf } from "./public/share-links.js"; + +/** Whether `path` is an agent in the catalog on /agents (its live state `{ agents: { [path]: row } }`): + * a row that said what runs it or what it is called. A row with neither is a folder + * (@iterate-com/ui lib/agent-summary.ts `folderTest`), and the root and any path outside /agents/ + * are refused before (`agentPathOf`). */ +export function isAgentOf(catalog: unknown, path: string): boolean { + if (!agentPathOf(path)) return false; + // the catalog's live state is `unknown` to its reader: iterate/agents writes `agents` as a map + // from a path to its row, and a state of any other shape has no row for the path + const agents = ( + catalog as { agents?: Record<string, { kind?: string; title?: string } | null> } | null + )?.agents; + const row = agents && Object.hasOwn(agents, path) ? agents[path] : null; + return Boolean(row && (row.kind || row.title)); +} + +/** What `agentCatalogOf` reaches of the mind: the catalog's facet on /agents. */ +export type CatalogItx = { + cd(path: string): { + facets: { get(name: string): { liveSnapshot(): Promise<{ state: unknown }> } }; + }; +}; + +/** The catalog on /agents (its live state), or null. It touches /agents alone. */ +export async function agentCatalogOf(itx: CatalogItx): Promise<unknown> { + try { + return (await itx.cd("/agents").facets.get("agents").liveSnapshot()).state; + } catch { + return null; + } +}
A core/configs/default/apps/dash/framed-sign-in.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/dash/index.html
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/dash/public/app.css
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/dash/public/app.js
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/dash/public/mcp-page.js
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/docs/index.html
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/docs/processors/merge.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/docs/public/app.css
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/docs/public/app.js
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/guestbook/app.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/guestbook/index.html
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/guestbook/mcp.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/configs/default/apps/mcp/app.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/configs/default/apps/mcp/server.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/meet/index.html
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/meet/public/app.js
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/onboarding/app.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/onboarding/launch.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/onboarding/steps/connect-iterate-cloud.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/tasks/app.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/askers.js
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/askers.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/asks.js
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/asks.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/board.js
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/board.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/cards.js
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/cards.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/feed.js
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/apps/tasks/feed.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/tasks/index.html
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/tasks/public/app.css
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/tasks/public/app.js
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/tasks/public/tasks-model.js
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/tasks/tasks-model.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/telemetry/crashes.test.mjs
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/telemetry/crashes.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/apps/telemetry/exceptions.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/cloud-handover.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/cloudflare.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/cloudflare.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/context-descriptions.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/errors.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/every-event.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/init.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/iterate.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/mail-replies.md
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/mcp.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/page-events.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/people.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/profile.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/sandboxes.md
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/skills/README.md
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/skills/mind-skills/SKILL.md
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/tasks.md
Not shown: the change is larger than this page shows. A clone has it.
A core/configs/default/telemetry-query-rule.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/configs/default/telemetry.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/template-updates.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/default/worker.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/minimal/AGENTS.md
Not shown: the change is larger than this page shows. A clone has it.
M core/configs/minimal/worker.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/home-lab/README.md
Not shown: the change is larger than this page shows. A clone has it.
M core/home-lab/src/link/relay.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/home-lab/src/main.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/home-lab/src/seed-repos.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/home-lab/src/seed-repos.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/caller.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/caller.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/context/awake.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/context/built-ins.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/itx/src/context/context-activity-stack.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/itx/src/context/context-activity-stack.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/context/context-catalog.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/context/facet-host.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/context/itx-expression-rewriting.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/context/stateless-context.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/itx/src/context/telemetry-query-rule.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/itx/src/context/workers-mcp-call.test.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/itx/src/context/workers-root-email.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/index.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/iterate-context-durable-object.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/iterate-context.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/serve-host.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/stream/core-events.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/stream/core-processor.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/itx/src/stream/facet-push-catch-up.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/stream/stream-versions.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/stream/stream.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/itx/src/stream/subscription-delivery.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/README.md
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/agents/README.md
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/agents/api.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/agents/catalog.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/agents/catalog.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/agents/collection.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/agents/collection.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/api.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/app-description.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/app-description.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cause.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/README.md
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/chatgpt.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/chatgpt.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/cli.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/cloudflare-access.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/cloudflare-access.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/deploy.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/deploy.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/device-login/index.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/lib/src/cli/mcp-clients.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/lib/src/cli/mcp-clients.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/lib/src/cli/oauth.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/oauth.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/recover.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/cli/recover.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/client/event-log.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/client/event-log.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/client/live-state.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/client/live-state.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/lib/src/client/new-version.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/client/new-version.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-dash.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-docs.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-guestbook.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-handover.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-mail-replies.test.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/lib/src/config-default-mcp.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/lib/src/config-default-mind-mcp.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-mirror.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-onboarding.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-publish-hook.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-tasks.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-telemetry-query-rule.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/config-default-telemetry.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/email.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/integrations.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/lib.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/mind-config.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/mind-config.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/mind-ingress.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/node-renewal.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/node.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/sdk/auth.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/sdk/index.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/sdk/index.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/sdk/itx-scope.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/sdk/itx-scope.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/lib/src/sdk/mcp.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/standalone-page.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/lib/src/workers.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/context/egress-upgrade.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/context/fixtures/egress-upgrade.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/context/telemetry.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/http.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/mind-worker/src/integrations/email-hook.test.ts
Not shown: the change is larger than this page shows. A clone has it.
D core/mind-worker/src/integrations/email-hook.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/integrations/email-receive.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/integrations/email.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/library.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/library/mcp.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/library/mcp.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/mcp-config.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/mcp-skill-frontmatter.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/mcp-skills.test.ts
Not shown: the change is larger than this page shows. A clone has it.
A core/mind-worker/src/mcp-skills.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/mcp.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/mind/contract.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/mind/processor.test.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/mind/processor.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/mind/publication.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/mind-worker/src/rpc.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/index.html
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/approvals.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/apps.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/connect.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/finish.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/follow-up.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/github.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/instructions.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/let-iterate-in.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/links.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/look.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/mail.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/mcp.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/pays.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/people.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/reach.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/research.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/sandbox.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/signed-requests.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/speak.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/subagents.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/telemetry.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/voice.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/onboarding/website.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/public/app.js
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-build-an-app.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-connect-iterate-cloud.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-connect-mcp.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-connect-tools.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-devices-and-character.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-invite-people.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-look.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-mail.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-remove-onboarding-app.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-research.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-sandbox.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-secrets-and-approvals.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-telemetry.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-voice-call.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/tasks/onboarding-website.md
Not shown: the change is larger than this page shows. A clone has it.
M core/repos/onboarding/worker.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/telemetry-worker/src/rpc.ts
Not shown: the change is larger than this page shows. A clone has it.
M core/telemetry-worker/src/store-query.test.ts
Not shown: the change is larger than this page shows. A clone has it.