Repository navigation
feat(mcp): agents connect through consent: authorize, the code exchange and refresh - #881
Conversation
Review: GPT-6.1-Sol (xhigh), two roundsRound 1, on fb827df: one blocking, two should-fix.
Sol agreed with the failures-only reading of the per-address limit: a failure past 60 a minute gets 429, and a success is never refused. Round 2, on aeb26fd: nothing blocking, nothing new. Sol rechecked all eight threat areas, the ticket and #833 invariants, and the mirrored surfaces. |
Acceptance: PASS with notesChecked Done means
Golden journeys
Additional evidence Focused command at the checked head: Independent HTTP checks, using the default registry values: Production CORS ( Rollback answers: match the diff. Reverting leaves the additive Mirrored surfaces checked: the two limits and rendered documentation, Auth's Consent glossary, migration composition, and server/test launcher wiring. No API schema, CLI contract, dev runner, package layout or company-resource path changed. Not run
Notes
|
867c072 to
056b09a
Compare
aeb26fd to
9fa5e38
Compare
056b09a to
1dd34b1
Compare
…ge and refresh Patchy becomes the authorization server for agent connections. GET /oauth/authorize signs the person in before anything else, then holds the request to every rule and explains a refused one on the page, sending nowhere. Consents.approve records only a minute's code for the account, bound to its client, redirect and S256 challenge; deny records nothing; every answer carries iss. POST /oauth/token exchanges a code once, creating the agent connection, and a replay ends the connection it made before invalid_grant. Refresh runs AgentConnections' rotation with resource and client checked. Issuance and the exchange hold agent access; off deletes the company's codes not yet exchanged; a code made at or before the credentials-ended stamp is dead. Failed token attempts are limited per address (a success is never refused) and refreshes per connection, as registry rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ns spend the refresh limit Sol's round 1. Expired codes are swept only while unexchanged, so an exchanged code stays with its connection and a replay after its minute still ends it. The per-connection limit counts refreshes that present the current token, so retries within the minute spend nothing. Authorization request refusals name their parameter in one message; a foreign resource at the token endpoint is its own error, ResourceRefused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9fa5e38 to
d994ee4
Compare
Stacked on #881 (ticket #849); merges with the rest of #833's stack, not alone. ## What changed An MCP client asking to connect got #849's placeholder heading and nothing to answer with. Now the person gets the consent door picked on #739. It shows who is asking to act as whom, and what the agent will and won't be able to do. The person answers Allow or Deny, and only that answer goes back to the client. Closes #850 ## Look at **1. The answer's guards** (`packages/auth/src/OAuthEndpoints.ts`). `POST /oauth/authorize` posts back the request's own query and runs `Consents.check` on it again, then calls #849's `approve` or `deny`. Each item below is a test in `OAuthEndpoints.test.ts` or `DevPersonas.test.ts`. I removed each guard in turn and its test went red. - **CSRF.** The answer goes through `RequireSession.sameOrigin`, the same check as every first-party POST. Another `Origin`, `Origin: null`, or no `Origin` without `Sec-Fetch-Site: same-origin` gets a 403 before the body is read. Nothing is recorded. - **Clickjacking.** Every consent page sends `frame-ancestors 'none'`. - **Account switch.** The form carries the `userId` the page was rendered for. If someone else is signed in when the answer arrives, the page is drawn again for them with the warning, as a 409, and nothing goes back to the client. - **Persona switch mid-consent (dev only).** `GET /dev/sign-in?as=` is refused with a 403 for `Sec-Fetch-Site: cross-site` or `same-site`, and sets no cookie. `none`, `same-origin` and no header all still switch. - **Open redirect through Deny.** Deny runs the same check as Allow. A query whose `redirect_uri` the document doesn't list gets the "can't connect" page as a 400, with no `Location`. A signed-out answer is sent back to the page (303 to `GET /oauth/authorize?…`) and answers nothing. - **What the page echoes.** The client's name is already cleaned and cut to 64 characters by #846's `clientName`. The site is a host Patchy fetched from, so DNS bounds it. Both are escaped with everything else. The test document's name is `<img src=x onerror=alert(1)>` plus U+202E and 80 `a`s. It renders escaped, without the bidi control, and cut to 64 characters. - **`form-action`.** Browsers hold a form's redirect to `form-action`, so the page adds the redirect's origin, for example `form-action 'self' https://claude.ai`. A host CSP can't name exactly, such as `[::1]` or one with other characters, adds only its scheme. A stranger's document can never write into the header. - **The name the connection keeps** is the one the page showed. The answer fetches the client's document again, so the form carries the shown name. An Allow whose document now names the client differently asks again (409), and approves nothing. - **A request too long to carry through sign-in** is refused before it (414). Sign-in and Use another account carry the request's address in their own addresses, encoded again at each hop, and a browser adds the page it came from as `Referer`. The bound is 2,048 characters of query (real clients send under 1 KiB). The socket test carries the longest allowed request through sign-out and back to the sign-in door, with a browser's headers. **2. For Allison: four calls the ticket didn't settle.** - **The page lasts ten minutes.** "A request that ran out" needs a lifetime, and nothing server-side expires before Allow. The form carries when it was shown. An answer more than ten minutes later gets "This request has run out" (410), and nothing goes back to the client. Ten minutes matches a device login's code. The time isn't signed: only a same-origin POST from the person's own browser can send it, so changing it helps no one but themselves. - **"Logged as Jordan Lee via Claude"**, with the full name. The mock says "Jordan via Claude", but the log will write "Jordan Lee via Claude" (#739), and the page promises what the log says. - **Use another account** is today's "Not you?" sign-out block under the footer, with a new label. The mock puts it inline in the footer sentence, but a sign-out needs a POST, and the shell has no inline link-button style. `/logout` now takes a `return`, so it signs out and lands on the sign-in door for the same request. The off page has it too, for someone signed in to the wrong company. - **The limit counts signed-in loads and answers.** Signed-out loads only reach the sign-in door, fetch nothing and spend nothing. A connect costs two (page and answer). This is `oauth.consent.perMinute` in the registry and `docs/limits.md`. ## Before and after Before, #849's placeholder: | Desktop | Phone | | --- | --- | |  |  | After, as Jordan Lee (member) at Brightline Studio on a `pnpm dev up brightline` instance. The real Claude and Claude Code documents were fetched from claude.ai. **Claude (hosted redirect)**  **Claude Code (answer returns to this computer)**  **The account changed while the page was open** (Priya signed in from another tab, then Jordan's page pressed Allow)  **Agent access off, as a member, then as an admin**   **The request ran out** (`shown` set an hour back, then Allow)  **Deactivated** (today's page) **and no company yet** (create-or-join, then back to consent, where the new company's access is off and its creator is the admin)    **Use another account** lands on the sign-in door, returning to the same request  **Phones (390 px)** | Claude | Claude Code | Account changed | | --- | --- | --- | |  |  |  | | Off, member | Off, admin | Ran out | | --- | --- | --- | |  |  |  | | Deactivated | Create-or-join | Back to consent | Use another account | | --- | --- | --- | --- | |  |  |  |  | ## How it was verified - **Done means, on a dev instance in a browser** (Playwright as dev personas against the `brightline` environment, with the real claude.ai documents): - **Allow.** Claude Code's request, with the redirect on a random `127.0.0.1` port where the script listened. The callback got `code`, `state=client-state` and `iss=<instance>`. The code exchanged at `/oauth/token` for `200 {access_token, expires_in, refresh_token, scope: "patches", token_type: "Bearer"}`. - **Deny.** The callback got `error=access_denied`, `state` and `iss`, and no code. - **Account switch.** Priya signed in from another tab, then Jordan's page answered. Patchy asked again as Priya and sent nothing back. - **Every state** above, at 1280 px and 390 px. - **Tests.** - `OAuthEndpoints.test.ts` gains 13 consent tests. They cover: - the page's content and headers; - the loopback warning with its CSP source (IPv4 and `[::1]`); - escaping and the cut; - Allow then exchange, and Deny recording nothing; - cross-site answers; - the account switch and the renamed client; - the ten-minute boundary (TestClock at 10:00 passes, 10:01 runs out); - access off for a member and an admin, including Allow from a page shown while it was on; - a signed-out answer, and Deny to an unlisted redirect; - the 2,048-character bound, exactly at it and over it; - the per-address limit. - `DevPersonas.test.ts` covers the persona refusal. `AuthPages.test.ts` covers logout's `return`, which stays local. `AuthPages.socket.test.ts` covers the longest request through sign-out to the door. - `apps/server/src/AgentConsent.test.ts` now approves through the page's POST instead of a service call. - Each guard in "Look at" was removed in turn, and its test went red. - **Review.** GPT-6.1-Sol (xhigh), four rounds; [the rounds and their outcomes](#882 (comment)). Round 4 found nothing blocking or should-fix. - **Suites.** CI's 14 checks pass on the head. Locally: auth (216), core (81), portal (98), limits (25) and the server's AgentConsent test pass. eslint, prettier, `tsc -p tsconfig.test.json` and the builds of auth, portal and server are clean. - **`pnpm verify` on 2e101dc.** 8 of 9 steps pass: format, lint, typecheck, synth, postgres-concurrency, cli-smoke, tier2-smoke and browser (81). The test step passed 2,183 of 2,184. The one failure was `packages/patchy/src/cliRepoPublish.test.ts`: tar read `typescript/lib/_tsc.js` as another checkout on this machine rewrote that shared, hard-linked file (`File shrank by 10893220 bytes`). The suite passes rerun alone (3/3), and passes in CI's three test jobs on this head. - **Rollback rehearsal** against production's commit, which has #837 and #838: `pnpm test:rollback-rehearsal --live e4243ff` passed e4243ff → 2e101dc → e4243ff → 2e101dc in 185 s. CI's `rollback-rehearsal` job skips, since nothing here migrates. - **Acceptance:** [PASS with notes](#882 (comment)) on 2e101dc, by GPT-6.1-Sol (xhigh). **Surfaces:** - The shell gains `agent-mark` (with core's `agentMark` and `agentIcon`, now shared with the guide), `consent-strip` and `can-list`, and `ui-consistency` names all three. The consent door joins its list of doors. - The limits registry gains `oauth.consent.perMinute`, rendered into `docs/limits.md`. - `docs/product.md` › Consent gains the ten minutes and how Use another account behaves. The Auth glossary's *Consent* gains the ten minutes. - `docs/DEVELOPMENT.md` gains the persona refusal, "Connecting through consent" (the walkthrough #849 left for this page) and a Consent entry under What to exercise. `patchy-dev-loop` says the same. Untouched: - `packages/api`, so `docs/API.md` stands. - The CLI. - Migrations. - The dev runner's code: its tools already send `none` or no `Sec-Fetch-Site`. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required One new route (`POST /oauth/authorize`), a registry row and shell CSS. `/logout` takes an optional `return`. No schema change. - **What does a revert leave behind?** Nothing new. Codes an Allow made are #849's `agent_consents` rows, which expire in a minute. - **Does the release before it still work with that?** Yes. It has no POST route, so an open consent page's answer would 404, and the client would start again. Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).
## What changed This PR adds release 17's What's new entry, written from `5dd94f3`. It covers everything merged since release 16's `through` (`dd3f41f`), and it sets the `patchy` release to `0.17.0` in `packages/patchy/package.json` and `CURRENT_RELEASE`. With this release, people's agents can use their company's patches through Patchy MCP (#833). | Change | PRs | | --- | --- | | New: Your AI agent can use your company's tools | #873, #878, #880, #881, #882, #883, #884, #886, #887 | | New: Admins choose whether agents can use the company's tools | #871 | | Improved: Your machines shows your agents too (Revoke all machines is now Disconnect everything) | #885, #879 | | New: See what agents can do with a tool | #876 | | New: The log says when an agent made a change | #888 | | New: Your agent can make a tool ready for agents | #869, #870, #872, #875, #896 | | Behind the scenes: agents' calls have their own limits, and a server only an agent uses rests a minute after its last call | #889, #892 | | Behind the scenes: New and Improved changes are public, for patchyhq.com | #893 | | Behind the scenes: library updates | #899 | Five merged PRs get no line: - #874 is release 16's own entry. - #894 is dev tooling: worker agent launchers and scenario data. Its one CLI fix lets a `patchy` installed outside a tier 2 repo publish it. The skills have agents use the repo's pinned `pnpm patchy` instead, so that path is off the documented one. - #900 is CI. - #901 rewords an internal skill. ## Look at - **The entry**, at the top of `releases` in `packages/core/src/whatsNew.ts`. - It names only Claude Code and Codex. Both have connected through real consent against dev instances. Hosted clients (Claude.ai, ChatGPT) are checked in production only (`docs/product.md` › Patchy MCP › Acceptance). - Its labels are the pages' own: Agent access on Company, Your machines, What agents can do, Disconnect everything, and "Jordan Lee via Claude". - **Rollback safety, from the live commit `e4243ff` to `5dd94f3`.** - No PR in the range is labelled `one-way`, and every PR answers both Release impact questions with "Yes". - Migrations 0020–0025 are all additive: - three defaulted or nullable columns on `companies`; - `agent_name` on the runtime log, with a widened `credential_kind` check; - the agent connection tables, `agent_consents` and `change_keys`; - two columns on execution bindings. The new tables reference `users` without a cascade, but no release deletes users or companies. Release 16 reads the runtime log only for credential kinds it knows, so rows from agents can't break it. - `rollback-rehearsal` on #892 rehearsed the whole stack, since #892 adds the last migration and the rest of the stack sits below it: `Exercised rollback paths passed: e4243ff → c8bede4 → e4243ff → c8bede4, in 238s.` #896's run skipped, because it changes no migration or handler descriptor. - #883 turns on the load balancer's host header preservation, which the Deploy workflow's app stack deploy applies. A rollback leaves it on. That's harmless, because release 16's server never reads `Host`. - A rollback takes `/mcp` and `/whats-new.json` away. Connected agents get a 404 until this release returns, and then their connections work again, unless one ended in between. Agent tools published in between stay refused to pages, because #837 already shipped in release 16. ## How it was verified - `pnpm check` on `2d528b1`: format, lint, typecheck and synth passed. In the test step, 2,300 of 2,301 tests passed. The one failure was `packages/sdk/src/install.test.ts` › "says how to reach patchy when the prefix's bin is not on PATH", which timed out at 180 s while the shared machine was loaded. Rerun alone, that file passes all 7 tests in 62 s. The release's own tests pass too: `whatsNew.test.ts`, `schemas.test.ts` and `WhatsNewPages.test.ts`. - The live commit was pinned from `/healthz/deep`: `e4243ff`, release 16. The Deploy run updated last succeeded, and none is unfinished. - Each PR in the range was read with `gh pr view`, including its Release impact answers. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required This PR changes only the changelog text and the `patchy` version. As with every release, a CLI installed before this deploy is told to upgrade. - **What does a revert leave behind?** Nothing. People whose seen marker reached 17 would just see no new release. - **Does the release before it still work with that?** Yes. If this release misbehaves, roll back to `e4243ff54d2acbbc88b60eeb0cf9b82a26dc9d5d` (release 16). Prepared by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code. Co-authored-by: Claude Opus 5.5 <[email protected]>
Stacked on #880 (ticket #848); merges with the rest of #833's stack, not alone.
What changed
An MCP client couldn't turn a person's consent into an agent connection: nothing answered
/oauth/authorizeor/oauth/token. Now Patchy is the authorization server. The person signs in before anything else happens. The request is checked before anything is shown. An approval records only a short-lived code. The client's code exchange creates the agent connection, and refresh rotates it.Closes #849
Look at
packages/auth/src/OAuthEndpoints.ts).GET /oauth/authorizesigns the person in first. A refused request is explained on the page and never sent back to the client, because its redirect is vouched for only by a stranger's document (RFC 9700 §4.11.2). Only the person's own answer, Allow or Deny (People answer an agent's request on a consent page #850), goes back to the client, withissandstate. An unsigned request even namesredirect_uri=https://evil.example/:packages/auth/src/Consents.ts), each a race test inConsents.test.tsheld open both ways round:Companies.setAgentAccess), so off then on doesn't revive them;clock_timestamp()under the person's row lock, so one made at or before Deactivation and Disconnect everything end pending device logins and record when a person's credentials ended #838's stamp is dead. Disconnect everything and deactivation need no change; the stamp cancels their codes;invalid_grant.answers 429 to an address's failures past the limit, never to its successespins my reading.How it was verified
apps/server/src/AgentConsent.test.tsboots the whole server as a dev instance boots it: personas, a<label>.localhostorigin, its token endpoint at127.0.0.1, and Claude Code's fixture document. It covers each Done means item:Consents.approve, exchanges with a loopback redirect on a random port and refreshes.worktoken is 401 on/api/me.Consents.test.ts› with agent access off nothing is issued… and both off races.plain, no challenge, or the challenge sent as the verifier);resourceandredirect_urimix-ups;isson approve and deny;*without credentials in production, and none plus no preflight on a dev instance.Consents.test.ts› a replay long after…).OAuthEndpoints.test.ts› limits rotations per agent connection…).pnpm typecheckand eslint are clean. These all pass:pnpm verifypassed on aeb26fd: format, lint, typecheck, synth, test, postgres-concurrency, cli-smoke, tier2-smoke and browser (81 specs).pnpm test:rollback-rehearsal --live e4243ffpassed, going e4243ff → fb827df → e4243ff → fb827df in 191 s. e4243ff is main's tip and has Tier 2 readers accept handler descriptions, read-only actions and agent tools, and enforce them #837 and Deactivation and Disconnect everything end pending device logins and record when a person's credentials ended #838. CI'srollback-rehearsaljob also passes on aeb26fd.Surfaces:
oauth.token.failures.perMinute,oauth.token.rotations.perMinute), rendered intodocs/limits.md;0023_agent_consents;ClientDocumentNetworknow comes from the launcher (start.tsbrings the pinned one, so a test can serve fixtures);AgentConnections.chainOf, a lock-free read the token endpoint checksclient_idand limits by before it calls Agent connections: theworkcredential and its tokens #846'srefresh.Untouched:
packages/api, sodocs/API.mdstands;docs/DEVELOPMENT.mdgets its consent walkthrough with People answer an agent's request on a consent page #850's page.For #850: the authorize page's success branch (
consentPageinOAuthEndpoints.ts) is a placeholder heading. The consent page replaces it and adds thePOSTanswer: re-runConsents.checkon the form's fields, thenapproveordeny, which return the redirect.Release impact
Two new routes, a new table and two operating rows. Nothing existing changes shape.
agent_consentstable and any minute-long codes in it, and agent connections made through consent, which Agent connections: theworkcredential and its tokens #846's tables already hold.agent_consents, and the release before keeps ending and refusing agent connections by Agent connections: theworkcredential and its tokens #846's and Every way a person's credentials end also ends their agent connections #847's rules.Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).