Repository navigation
fix: every form read is capped - #1434
Conversation
Review recordTwo independent review rounds by GPT 6.1 Sol. The second, on Round 1 (on
Round 2 (on
The reviewer confirmed by running: the first round's input now invites all 50 addresses; the new tests fail with the old cap; declared and streamed bodies one byte past each cap get a whole answer and a close; the MCP door's 413 is byte-for-byte what it was; and the bundled CLI exited 2 on all 12 over-cap calls it tried, up to 8 MiB of arguments, with the client receiving the whole refusal in 20 of 20 attempts at 8 and 32 MiB. Dismissed: the socket test helper does not validate chunked framing in a response. No caller reads a chunked answer through it. |
f68c8de to
aedbfbd
Compare
424f51d to
c455b0f
Compare
aedbfbd to
3517ce7
Compare
c455b0f to
6d6c5c4
Compare
3517ce7 to
b131060
Compare
6d6c5c4 to
aef6c64
Compare
b131060 to
2de49fa
Compare
aef6c64 to
b4a8abc
Compare
…1426) ## What changed Effect moves from 4.0.5 to 4.1.4 (`effect`, `@effect/platform-node`, `@effect/sql-pg`, `@effect/sql-pglite`, `@effect/vitest`). People using Patchy see no difference. Nothing stored changes: tokens, digests, HMACs and sealed values are still made and checked by the same `node:crypto` code. This supersedes #1380, whose CI was red because 4.1 stores `HttpApiSchema.status` where our `refuse()` didn't look, so every refusal answered 400. Beside the Effect group, the lockfile moves only ws, to 8.23.0, which `@effect/platform-node-shared` 4.1.4 pins exactly. undici 8.12.4 and PGlite 0.5.16, which the 4.1 packages need, are already on main from #1424, so the workspace holds one PGlite again. ## Look at **Crypto.** 4.1 replaces `effect/Crypto` with per-family services and drops crypto from the runtime `*Services` bundles. The `Cryptography` seam stays as it was. `NodeCryptography.layer` now also provides Effect's `SecureRandom` and `Digest`, using Effect's own Web Crypto layers: no new dependency, nothing at import time, and the same behaviour on Node and Bun. Every entrypoint and test layer already provides it, so "provide `NodeCryptography.layer`" stays the one rule. The seven direct `effect/Crypto` users take `SecureRandom` or `Digest` instead. `@patchy/limits` can't depend on core, so `Digest` is what it uses. AGENTS.md, the service-conventions spec and the oxlint messages say this now. **Refusal statuses.** 4.1's `HttpApiSchema.status` writes a key annotation, which `SchemaAST.resolveAt` doesn't read. HttpApi's own reader, `getStatusErrorSchema`, is internal and missing from the published types, so `respond.ts` follows its rules exactly: 1. The last check that sets a status wins, looking into check groups too. 2. Otherwise the schema's own annotation counts, and an explicit `undefined` clears the status. 3. Otherwise the key annotation counts. 4. With none of those, the status is 500. `respond.test.ts` compares each case with HttpApi's own reader. One consequence: a schema with no status now answers 500, where it used to answer 400. No current refusal schema lacks one. **Request targets.** 4.1's server adapter turns an absolute-form target into its path, and sets `Host` to the target URL's host, which drops userinfo and the scheme's default port. The door's `Host` gate then saw a cleaned-up host, so `POST http://<public host>/mcp` and `POST https://user@<public host>/mcp` reached the bearer check instead of answering 421. `RequestTrust.requestAuthority` now reads the target and the `Host` fields from the Node request as the client sent them (`request.source`). Sources without raw fields, such as a web `Request` or the in-memory test client, keep the old reading. I also checked everything else that reads the target or `Host`: - The API guard, serving and the portal resolve `request.url` against the configured origin, and compare `Origin` rather than `Host`. They don't trust the target's authority, and the rewrite makes an absolute target reduce to its path. - The CLI dev server's DNS-rebinding guard compares `Host`. Browsers send origin-form, which the adapter leaves alone, so the guard still does its job. - Two private listeners now accept an absolute-form target where they used to refuse it before authentication, and the behaviour stays as it is. The callback gateway (`CallbackGatewayApi.ts`) used to answer `POST https://anything/callback` with 200 `invalid_request`; now it reaches the bearer and identity checks. The supervisor's callback proxy (`supervisor.ts`) looks up its callback path from the rewritten target. Neither grants anything the checks behind it don't already require. **Oversized uploads.** Under 4.1, an undeclared (chunked) body over its cap is answered instead of reset. But the adapter then keeps reading up to 256 KiB more with no deadline, so a sender that stalled kept its connection until the runtime's own timeout. A declared length over the cap had the same problem below 256 KiB, on origin/main as well. A size refusal now closes the connection, through one hook: `closeAfterAnswer` in `@patchy/api`. It adds `Connection: close` to the current request's answer, and the adapter then ends the socket and destroys it within its 500 ms grace. Measured here, the server closed it about 7 ms after answering, on Node and on Bun. Every capped reader runs the hook, for a cap crossed mid-stream and for a declared length over the cap. Each keeps its existing status and body: - `readBody`, for every JSON API route that reads one: 400 "Malformed request body." mid-stream, 413 declared. - The 16 form readers in auth and portal, through `capBody(maxBytes)`: beta links, device login, the OAuth token request and consent answer, machines, shortcuts, logout, terms, What's new, patch pages, sharing, home (two), feedback, user lifecycle, and pinning. Their declared-length prechecks run the hook too. - The runtime's call, file and stage readers (413), and the subscriptions stream (413). - The callback gateway: the file bound and the byte budget answer, as before, with a 200 refusal body. - The supervisor's callback proxy (413). One reader is left out: the MCP door reads a chunked body to its end by design, so its refusal is unchanged. The device start, device poll and shortcuts descriptions, and `docs/API.md`, say what the code does. Nothing is stored on any refusal. **Row ids.** 4.1's `SecureRandom.uuidV7` counts within a millisecond: 42 counter bits and 32 random. #214's contract test pins 74 random bits per id, and Effect's own docs say a monotonic id reveals the one minted before it. So `TableOperations` builds the UUIDv7 itself from the Effect clock and 16 bytes from `SecureRandom`, clamping the timestamp to the 48-bit field as 4.0 did. **Other behaviour 4.1 changed that tests asserted:** - A failed migration step is a typed `MigrationError` (`kind: "Failed"`) instead of a defect. Startup still fails and the process exits. - The CLI parser now splits `-json=true` into `-j -s -o -n`, so `jsonRequested` stops treating it as `--json`. A global flag's bad value (`--log-level loud`) now goes through Effect's usage path like any other parse error. That made the entrypoint's `InvalidValue` catch dead, so it is gone. Under `--json` stdout stays empty; without it, usage comes before the one line, as ADR-0004 allows. **Mechanical.** `SqlClient.make` takes a `driver`, and `sql.insert` takes a non-empty array. `docs/API.md` drops the eight duplicate `RuntimeFailure_N` components that differed only by status. **On top of the GitHub integration.** Everything on main since #1427 was written against 4.0.5: the GitHub App connection (#1448) and its reads (#1451), workerd binding its own port (#1444), CLI refresh (#1446) and sidebar pins (#1437). Checked against each 4.1 change: - **Crypto.** None of it uses `effect/Crypto`. `Cryptography` gains `rsaSha256Sign` for the App's JWT, which runs on `node:crypto` like the rest, and `NodeCryptography.layer` still provides it beside `SecureRandom` and `Digest`. - **Statuses.** It adds no routes and no status-bearing refusal schemas. GitHub's refusals reach clients through the existing connection pages, `ConnectionsApi` (whose declared errors HttpApi encodes itself) and the runtime, which takes its status from the error. The GitHub, connections and dev-read suites assert those statuses over `HttpApiTest` and real sockets, and pass on 4.1. - **Body reads.** The one new body read is the pin form, which provided `MaxBodySize` directly. It now goes through `capBody`. GitHub's connect flow adds none: its filter is a GET, and its choices post through the connection page's existing form read, which #1434 caps. - **Targets and `Host`.** The GitHub sign-in's redirect URI is built from the configured origin, and nothing new reads `Host`. - **The rest.** Nothing new calls `SqlClient.make`, the Migrator, `uuidV7` or `ws`, and no new flag uses a single-dash long spelling. **On top of Pidgeon's new API.** #1458 rewrote the Pidgeon integration against 4.0.5, and nothing in it needed a 4.1 change: - Its crypto goes through `Cryptography`. - It adds no routes, status-bearing refusal schemas, body reads or CLI flags. Its connect page posts through the connection page's existing form read, which #1434 caps. - It doesn't call `SqlClient.make`, the Migrator or `uuidV7`. - Its migration `0044_pidgeon_drafts` joins the record behind this branch's, and the record and upgrade tests pass. ## How it was verified **Red, then green, on Effect 4.1.4:** | Case | At 8980889 | Now | | --- | --- | --- | | `RequestTrust.test.ts`, the gate behind the real `NodeHttpServer` adapter: `POST http://cloud.patchyhq.com/mcp` | passed the gate | 421 | | `McpDoor.test.ts`, the whole server: `POST http://user@<host>/mcp` | 400 (past the gate) | 421 | | Same tests: origin form, the door's own absolute target (200), two `Host` fields | — | unchanged | | `AuthApi.socket.test.ts` (JSON) and `AuthPages.socket.test.ts` (form): an unterminated 8 KiB chunked upload | 400, connection still open at 3 s, on Node and Bun | 400, then closed, on Node and Bun | | `AuthApi.socket.test.ts`: `Content-Length: 8192` sent with no body (open on origin/main too) | 413, still open at 3 s, on Node and Bun | 413, then closed | | `RuntimeApi.test.ts`: a call streamed just past its cap, a stage upload streamed past its cap, and a stage upload declared past it | 413, still open at 3 s, on Node and Bun | 413, then closed | | `RuntimeStreamApi.test.ts`: a subscriptions body streamed past its cap | 413, still open at 3 s, on Node and Bun | 413, then closed | | `CallbackGatewayApi.test.ts`: a callback file body streamed past its bound | 200 refusal, still open at 3 s, on Node and Bun | 200 refusal, then closed | | `respond.test.ts`: a status set inside a check group | 409 | 403, as HttpApi | | UUIDv7 contract: a clock at −1 ms | timestamp field all ones | 0 | **Suites:** - On the head rebased onto main at 2a17d16, which now carries the Effect checker at 0.68 (#1425), `pnpm check` passes in full (3741 offline tests). - `pnpm verify` on the previous head, on main at 47deb91: - Pass in the full run: format, lint, typecheck, synth, the offline tests on Node (3732) and Bun (3405), postgres-concurrency and install. - Pass rerun alone: cli-smoke, tier2-smoke and the Chromium browser suite (189). In the full run they couldn't find the browser builds that Playwright 1.65 (from #1424) asks for; once installed, all three pass. - Could not start: the Firefox suite, because Firefox there lacks the system libraries it needs. CI's required `browser-firefox` job covers it, and it passed in an earlier round (186 tests). - The suites the Pidgeon rewrite touches pass on Node and on Bun (646 tests across 72 files each): all of `packages/integrations` and `packages/api`, the CLI's `pidgeon`, dev-resource and dev-preparation tests, and the server's migration record test. - The GitHub integration's suites, run alone on 4.1, pass on Node (361 tests across 27 files, with portal and the CLI's repo, global-CLI and dev-resource files) and on Bun (286 tests across 24 files; the CLI files run on Node only). They cover: - `github/Connections.test.ts`: connecting through the App against a stub GitHub on real sockets. - `github/Operations.test.ts`: the reads. - `github/Pages.test.ts`: the connect pages. - `github/Source.test.ts` and `Generate.test.ts`: the source and generated tables. - `ConnectionsApi.test.ts`, `ConnectionPages.test.ts` and `DevReads.test.ts`, with their status assertions. - `NodeCryptography.test.ts`, including RS256 signing. - Each rebase took main's lockfile and regenerated it with `pnpm install`; it differs from main's only in the Effect group and ws. - `install.test.ts` builds its PATH from the running Node, so these runs put the repo's pinned Node 24 first. - The supervisor's callback proxy gets the same hook, but has no socket test: reaching it needs a live workerd resident to register the callback path and capability. - Not checked: the server image (`server-image` needs Docker; CI runs it), live Clerk, and a deploy. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required This is a dependency bump, and the stored formats and the API's statuses and bodies are unchanged. Three things a client could notice: - An oversized chunked upload now gets its refusal and a closed connection, where it used to get a reset. - A declared length over a cap gets its 413 and a closed connection, where the connection used to stay open. - The undocumented single-dash `-json=<b>` spelling is no longer read as `--json`. `--json` and `--json=<b>` are unchanged. - **What does a revert leave behind?** Nothing: no migration, no new stored shape. Ids, tokens, digests and sealed values are made the same way on both sides. - **Does the release before it still work with that?** Yes. Built by Claude Opus 5.5 in T3 Code via Claude Code. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Join, People, Agent access, Teams, the connection forms and the dev server's agent door and shortcuts form read their bodies with no limit. Each now reads through capBody at a cap sized from its largest legitimate form, and answers an over-cap form as it answers any it can't read. capBody refuses a declared length over its cap before reading, so a sender that declares too much and stalls is answered and closed at once instead of waited on. stalledUpload now insists the whole answer arrived before the close, and returns its body. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The invite cap counted three bytes a character, but an address the page accepts can take nine a UTF-16 unit once percent-encoded, so a full batch of long accepted addresses was refused before anyone was invited. The cap is now worked out from the address schema: twice a full batch of the longest addresses, separators included, and room for the filter. A patchy dev agent call over the body cap got a plain 400, which the CLI reports as an unknown outcome. The dev server now answers it with the door's own too_large refusal, shared from @patchy/api, so the CLI says the call was refused and exits 2. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
b4a8abc to
23d0ca3
Compare
A roster form carries about 70 bytes a person and nothing limits how many people a company holds, so 1 MiB refused a roster past roughly 14,000 people that the page itself had rendered. The cap moves to 8 MiB, about 119,000 people. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
The acceptance run on |
Acceptance: PASS with notesChecked Done means
Golden journeys
Rollback answers match the diff. A revert restores the earlier form handling, including the dev-agent oversized-request behavior. The MCP door keeps its existing 413 response body. There are no migration, persisted data shape or infrastructure changes for the older release to handle. Notes
Not run
|
What changed
A few forms never got a body cap, so the server read whatever was sent to them: creating or joining a company, People and Agent access, Teams, the integration connection forms, and the local dev server's agent door and shortcuts form. They now cap their reads as the rest of Patchy's forms do. A submission over the cap gets the answer that page already gives a form it can't read, and the connection closes.
Builds on #1426, now merged, which added
closeAfterAnswer.Look at
capBodynow refuses a declared length over its cap before reading. Until now it noticed an overflow only once the bytes arrived, so a sender that declaredcontent-length: 4097to a 4 KiB form and sent nothing got no answer until Node's request timeout. It now fails at once, with the sameHttpServerErrorthe platform raises mid-stream. Each page answers it as it answers any unreadable form, and the connection closes after the answer. The forms in auth and portal that already read throughcapBodyalone get the same: logout, terms, beta links, machines, What's new, patch pages, sharing, home, feedback and user lifecycle. Their answer is unchanged; it just comes without the wait. Readers that check the declared length themselves (readBody, device login, OAuth) answer their own 413 first, as before.With the new socket test over
capBodywithout that check:With it, the test passes.
The caps, each sized from the largest legitimate submission of its form:
/join(Join.ts)CompanyPage.ts)CompanyPage.ts)TeamsPage.ts)formBodyinConnectionPage.ts)/~dev/agentmcp.body.bytes(1,114,112)/api/me/shortcuts/api/me/shortcutsreads itHow an over-cap form answers is how that page already answers an unreadable one:
Send value=on or value=off.too_largein the door's words, as the dev agent's usual answer, sopatchy dev agentreports a refusal and exits 2 (below). A malformed call within the cap keeps its 400Bad request.An over-cap
patchy dev agentcall is the door'stoo_large. A plain 400 would have made the CLI say the tool "may or may not have run" and exit 3, when the call was refused before anything started. A body overmcp.body.bytesis refused unread, so the dev server answers with the door's own refusal of such a body. That refusal,bodyTooLarge, now lives in@patchy/apibeside the other shapes of a tool call's answer, and the door's 413 reads its words from there, unchanged.patchy dev agentthen exits 2 with the door's words, as the README and ADR-0004 already say any refusal the door would give does; both now name thistoo_largebeside the oversized read. Answered before the body is read, the CLI's own client (undici) still reads the refusal: a 1,114,155-byte call gets it, in each of four runs.test/socket.ts.stalledUploadreads the answer'scontent-lengthand rejects when the server closed before the whole answer arrived, so a close that cuts a refusal short no longer passes for one. It returns the body, so tests assert which refusal came back. Against a throwaway server, a whole answer resolves, one cut 5 bytes short rejects with "The server closed the connection 5 bytes short of its answer's body.", and a close with no answer rejects too. The five suites that already used it pass unchanged.How it was verified
Each reader gets a body one byte past its cap over a real socket (
NodeHttpServer.layerTest), twice: as one chunk that never ends, and as a declared length with nothing sent. Each must answer its whole refusal and close within 3 seconds. Routes that share a reader share one case.AuthPages.socket.test.ts: Join, the four People and Agent access reads, Teams.ConnectionPages.test.ts: the connect form, through the oneformBodyevery connection form reads with.devServer.test.ts: both dev server readers, inside the existing dev server test, so it boots once. The agent door's answer is the door's refusal, also sent through the CLI's own client; a malformed call within the cap is still a 400.cliDevAgent.test.ts:patchy dev agentgiven that refusal exits 2 and prints the door's words, in text and--json.CompanyPage.test.ts: a full batch of the longest addresses the page accepts (50 addresses, 114,924 bytes with the longest filter) is read and invites all 50; twice that (228,024 bytes) is refused by its count, "That is 100 addresses". The socket case refuses one byte past 233,596.Red, with one piece taken out at a time, then green with it back:
capBody's declared-length check/join {"declared":4097}: expected +0 to equal 400/settings/company/teams/create {"chunked":1048577}: expected +0 to equal 400{"chunked":262145}: expected +0 to equal 400POST /~dev/agent HTTP/1.1 {"chunked":1114113}: expected +0 to equal 200POST /~dev/agent HTTP/1.1 {"chunked":1114113}: expected 400 to equal 200expected 400 to equal 303Existing page tests post real forms through
HttpServerRequest.fromWeb, which enforcesMaxBodySizeas the socket does, so a cap below a legitimate form would fail them. They pass, including the 51-address invite refusal and every connection form.Rebased onto #1426's earlier head (
b1310609, on main at47deb913, with Pidgeon's new API from #1458 and the dependency sweep from #1424),pnpm checkpasses in full: format, lint, typecheck, synth and all 3,736 offline tests. Neither #1458 nor #1424 added a body read. Pidgeon's connect form now posts through the sharedformBody, so the 256 KiB cap covers it, and Postgres's connection string is still the largest thing a connection form carries. The suites this PR and the rebase touch pass on Node (810 tests, before the sweep landed:packages/integrations,packages/companies,packages/api,packages/mcp, the auth socket and company-page tests, and the CLI's dev-agent, dev-server andpidgeontests). On Bun at this head they pass too (803; the dev-agent and dev-server files run on Node only).pnpm verifyran before the rebase, at the first commit,6e54ccd5, on a shared machine under heavy load (load average 40 to 60 during the test phases). Format, lint, typecheck, synth and every acceptance suite passed: postgres-concurrency, cli-smoke, install, tier2-smoke, browser and browser-firefox. The offlinetestandtest (bun)phases each failed some tests: timeouts in files this PR doesn't touch, a different set on each run. Rerun alone at low load, all of them passed (10 files on Node, 6 on Bun). The socket cases ran in both phases, exceptdevServer.test.ts, which is Node-only, as the CLI is. The installer suite needsnpmbeside thenodeit runs; with the pinned Node first onPATHit passes.Release impact
Breaking — requires action from anyone already running this
Not breaking — no action required: forms people submit read as before; only bodies past a form's largest legitimate size are refused
What does a revert leave behind? Nothing: no schema, rows or contract change.
Does the release before it still work with that? Yes.
Built by Claude Opus 5.5 (
claude-opus-5-5) in Claude Code, run from T3 Code.🤖 Generated with Claude Code