From 6e3e494d7a3e1cf70bcb6334d5247b270680a3a9 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Fri, 20 Nov 2026 00:02:59 -0600 Subject: [PATCH 1/3] docs(mesh): runnable REST demo, and the beta-track behaviour changes Add a section walking through core's example/mesh: a billing teapot that exports a balance step and its REST routes, and a shop teacup that needs balance like a local step. It shows the run, the curl calls, and what happens when billing stops and comes back. Update what core changes on the same branch: - createApp refuses a ws:// teapot off loopback unless mesh.allowInsecure (it only warned), and the earlier example now uses wss://; - mesh on the edge fails at createApp and edgeHandler; - a remote step call runs only that step's closure; - route exports are per method; - a non-HTTP error on a teapot reaches the client as a generic 500. These describe core's fix/hardening-batch-1 branch, so this lands with or after that release. Signed-off-by: Diego Resendez --- src/content/docs/guides/mesh.md | 76 +++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/src/content/docs/guides/mesh.md b/src/content/docs/guides/mesh.md index 7ea60c2..e913c22 100644 --- a/src/content/docs/guides/mesh.md +++ b/src/content/docs/guides/mesh.md @@ -17,7 +17,7 @@ Exports are opt-in (`export: true`) on **steps and routes** — a provider canno Mesh runs on **Node, Deno and Bun**, as both teapot and teacup, in any combination — a Deno teapot can serve a Node teacup. The wire is JSON over a WebSocket, so peers only have to agree on the protocol version, not the runtime. -**Edge (Cloudflare Workers) is not supported.** The teapot's secret comparison uses `node:crypto`'s `timingSafeEqual`, which workerd's `nodejs_compat` does not provide. +**Edge (Cloudflare Workers) is not supported.** The teapot's secret comparison uses `node:crypto`'s `timingSafeEqual`, which workerd's `nodejs_compat` does not provide, and a teacup's links are long-lived outbound sockets a Worker cannot hold. `createApp` with `mesh` throws inside a Worker, and so does `edgeHandler` given such an app, so the mistake surfaces at startup rather than on some later request. You do **not** need `listen()`. `serveDeno` and `serveBun` boot the graph before they bind, so a teacup has reached its teapots — or spent its `bootTimeoutMs` grace trying — by the time the port opens: @@ -63,7 +63,7 @@ class TeacupModule {} const teacup = createApp({ modules: [TeacupModule], experimental: true, - mesh: { teapots: [{ url: 'ws://A-host:3002/__mesh__/control', secret: 'shh' }] }, + mesh: { teapots: [{ url: 'wss://A-host:3002/__mesh__/control', secret: 'shh' }] }, }); await teacup.listen(3003); // GET B:3003/api/local/who (x-token: abc) @@ -76,8 +76,78 @@ await teacup.listen(3003); That is also why a **provider cannot be exported**. A provider is a factory whose value *is* the object it builds — a pool, a client, a `db` — and an object is not what a JSON wire carries. What used to cross was whatever half of it survived serialization, cached app-scope on the teacup for the life of the process, out of a cache the teapot no longer stood behind. Export a `@Step` that returns what the provider's value carried instead; the [next section](#what-can-cross-data-never-behaviour) has the shape. +On the teapot, a call runs the exported step and only what that step needs: the providers and steps in its own closure, sliced once at boot the way a route's are. A step nobody asked for does not run, and one that throws cannot break an export that does not depend on it. + +A route is exported per method: `@Get('/items/:id', { export: true })` exports the `GET`, and a teacup asking for a `DELETE` on the same pattern is refused unless that handler is exported too. When a remote step fails, its client sees what it would see locally: an `HttpError`'s status and message, or `500 Internal Server Error` for anything else. The full error stays on the teapot, in its `mesh:rpc:error` event. + Remote tokens become synthetic nodes in the local graph with RPC-backed runners, so the rest of the pipeline is unchanged. For non-mesh apps `createApp` stays synchronous; a mesh app defers graph finalization until it boots — connecting to teapots is network I/O — and boots on whichever comes first: `app.fetch`, `app.upgrade` or `listen()`. Whoever triggers it, it happens once. +## A complete example: one REST API on two processes + +The core repository has a runnable version of all of this in [`example/mesh/`](https://github.com/Expressive-Tea/green-tea/tree/develop/example/mesh): a small shop split across two nodes, with a test that runs it as two real processes. + +- **`billing.ts`** is the teapot. It owns a ledger, which it never exports, and exports a step, `balance`, plus its REST routes under `/billing`. +- **`shop.ts`** is the teacup. Its checkout route needs `balance` exactly as it would need a local step, and it serves billing's routes as if they were its own. + +The two halves that matter: + +```typescript +// billing.ts: computed on billing, per request, from the caller's route params +@Step({ provides: 'balance', needs: ['ledger'], export: true }) +class BalanceStep { + run(ctx: { ledger: Ledger; params: { customer?: string } }) { + const customer = ctx.params.customer ?? ''; + const due = ctx.ledger.invoices(customer).filter((i) => !i.paid).reduce((sum, i) => sum + i.amount, 0); + return { balance: { customer, due } }; + } +} + +@Route('/billing') +class BillingController { + @Get('/invoices/:customer', { export: true }) + list(@needs('ledger') ledger: Ledger, @param('customer') customer: string) { /* … */ } + + @Post('/invoices/:customer', { export: true }) + create(@needs('ledger') ledger: Ledger, @param('customer') customer: string, @body() data: { amount?: unknown }) { /* … */ } +} +``` + +```typescript +// shop.ts: nothing here says where `balance` lives; only the mesh config does +@Route('/shop') +class CheckoutController { + @Get('/checkout/:customer') + checkout(@needs('balance') balance: { customer: string; due: number }) { + return { customer: balance.customer, due: balance.due, canCheckout: balance.due === 0 }; + } +} + +createApp({ + modules: [ShopModule], + experimental: true, + mesh: { + teapots: [{ url: 'ws://127.0.0.1:3401/__mesh__/control', secret }], + reconnect: { initialDelayMs: 100, maxDelayMs: 1_000 }, + }, +}); +``` + +Run it from a checkout of the core repository. Start billing first: checkout needs `balance` at boot, and a teacup refuses to boot without a producer for a token it needs. + +```bash +npx tsx example/mesh/billing.ts # teapot on :3401 +npx tsx example/mesh/shop.ts # teacup on :3400, in a second terminal +``` + +```bash +curl localhost:3400/shop/checkout/ada # {"customer":"ada","due":40,"canCheckout":false} +curl -X POST -H 'content-type: application/json' \ + -d '{"amount":10}' localhost:3400/billing/invoices/ada # served by billing, through the shop +curl localhost:3400/billing/invoices/ada # both invoices +``` + +Now stop billing. The shop keeps running, and everything that needs billing answers `503` with `retry-after`: the checkout, and billing's own routes. Start billing again and the shop reconnects on its own within about a second. The ledger lives in memory, so it starts over. That is the whole failure story of a teapot that [goes away](#when-a-teapot-goes-away) and [comes back](#reconnecting), on your machine, in four commands. + ## Inspecting a mesh graph `inspect()`, `graph()` and `explain()` are synchronous, but a mesh graph is not knowable until its teapots have been asked — so on a mesh app they throw until the graph is resolved. `await app.ready()` resolves it: @@ -282,7 +352,7 @@ The channel is authenticated, but an unauthenticated peer still gets to send byt On Node a peer that sends more than 64 KiB before its `hello` is dropped before `ws` assembles the frame. Bun and Deno offer no per-socket limit to hold that to, so there an unauthenticated peer can still make the teapot receive one frame up to the post-`hello` bound before it is refused. If untrusted peers can reach a Bun or Deno teapot's `/__mesh__/control`, limit frame size at the proxy in front of it. :::caution[The secret travels in the handshake] -The shared secret is sent verbatim in the `hello` frame. Over `ws://` that puts it in front of anyone on the path, so **use `wss://`** unless the link already runs inside an encrypted network. green-tea warns at boot for a `ws://` teapot that is not on loopback — a warning rather than a refusal, because a private network doing its own mutual TLS is a real deployment and the framework cannot tell the two apart. +The shared secret is sent verbatim in the `hello` frame. Over `ws://` that puts it in front of anyone on the path, so **use `wss://`**. `createApp` refuses a `ws://` teapot that is not on loopback (`localhost`, `127.0.0.0/8`, `[::1]`), before anything connects. A private network that already encrypts the link, such as a service mesh doing mutual TLS, is a real deployment the framework cannot tell apart from an exposed one, so it can opt in with `mesh: { allowInsecure: true }`; each such teapot is still logged as a warning. ::: ## Protocol version From de0642869b2eca53afde89dee500beba5ab8dd50 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Fri, 20 Nov 2026 00:38:16 -0600 Subject: [PATCH 2/3] docs(stability): only the year breaks after stable Match core's versioning policy (core #75): after the first stable release, breaking changes ship only in the first release of a year, so the default ^ range is safe within a year. Deprecations still last at least two monthly releases and then wait for the next YY.1.0. Link core's support table (core #74). Signed-off-by: Diego Resendez --- src/content/docs/stability.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/content/docs/stability.md b/src/content/docs/stability.md index d01e5e0..ec10db1 100644 --- a/src/content/docs/stability.md +++ b/src/content/docs/stability.md @@ -1,6 +1,6 @@ --- title: API stability -description: "What the RC.1 freeze covers, what may change between RC.1 and stable, and how deprecations work after stable." +description: "What the RC.1 freeze covers, what may change between RC.1 and stable, and why after stable only the first release of a year can break." --- **From the first release candidate (RC.1), the public API of `@green-tea/core` is frozen.** The @@ -32,7 +32,23 @@ If a fix turns out to need an API change, the freeze is reopened for it on purpo bent quietly, and the CHANGELOG lists the change under `### Breaking`. So the CHANGELOG is the one place to check: a release candidate with no `### Breaking` section changed no public API. -## After stable: deprecations come before removals +## After stable: only the year breaks + +Versions are calendar versions, `YY.M.PATCH`, and npm reads the year as the major version. After +the first stable release, a release inside a year (`26.12.0`, `27.3.1`) never removes or breaks a +public API, so the range npm writes by default, `^26.12.0`, is safe to take. Breaking changes ship +only in the **first release of a year** (`27.1.0`, `28.1.0`): that is the one release to read +before upgrading, and a `^` range never crosses into it on its own. + +The one exception is a security fix that cannot be made without breaking an API. It ships when it +is ready, listed under both `### Security` and `### Breaking`. + +Which releases receive fixes, and for how long, is in the core repository's +[SECURITY.md](https://github.com/Expressive-Tea/green-tea/blob/main/SECURITY.md#supported-versions): +the latest monthly release gets bug and security fixes, and the one before it gets security fixes +for three months after the latest ships. + +## Deprecations come before removals Once a stable release has shipped, nothing public disappears without notice: @@ -41,7 +57,9 @@ Once a stable release has shipped, nothing public disappears without notice: you use it. - Where it has a runtime path, it **warns once per process** through `app.logger` — never `console`, so the warning goes wherever you sent the rest of the framework's diagnostics. -- It is removed only in a release whose CHANGELOG lists the removal under `### Breaking`. +- It is removed only in the first release of a year, whose CHANGELOG lists the removal under + `### Breaking`. Something deprecated in `26.4.0` goes in `27.1.0`; something deprecated in + `26.12.0`, too late for two monthly releases before January, goes in `28.1.0`. A type has no runtime path, so a deprecated type warns only in your editor. From 3ba6429481d425975c4556d7a6fe68f94601c949 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Mon, 23 Nov 2026 12:49:05 -0600 Subject: [PATCH 3/3] docs: 26.11.0-rc.2, the security fixes and what they change Document core 26.11.0-rc.2: bump documentsCoreVersion and the package version, add an RC.2 section to What's new with the behaviour changes an upgrade can hit, and correct the guides those changes made wrong: trustProxy's right-most X-Forwarded-For, cors '*' with credentials failing createApp, WebSocket Origin checks, dotfiles never served, generic stream error frames, the channel() default buffer, the /__ready__ body, Node's slow-client reaping and the Node-only limit warnings on Deno, Bun and the edge. Signed-off-by: Diego Resendez --- astro.config.mjs | 2 +- package-lock.json | 4 +- package.json | 2 +- src/content/docs/guides/ai-agents.md | 2 +- src/content/docs/guides/arguments.md | 2 +- src/content/docs/guides/html.md | 2 + src/content/docs/guides/introspection.md | 2 +- src/content/docs/guides/runtimes.md | 12 +++-- src/content/docs/guides/security.md | 30 ++++++++--- src/content/docs/guides/streaming.md | 11 +++- src/content/docs/reference/createapp.md | 2 +- src/content/docs/whats-new.md | 66 ++++++++++++++++++------ 12 files changed, 101 insertions(+), 36 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index cb26fb1..7dafdd7 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -10,7 +10,7 @@ import starlightLlmsTxt from 'starlight-llms-txt'; * not. It is shown on every page because a reader arriving from a search result has no other way * to tell whether what they are reading matches what they installed. */ -export const documentsCoreVersion = '26.11.0-rc.1'; +export const documentsCoreVersion = '26.11.0-rc.2'; // Docs site for @green-tea/core. Content lives in src/content/docs/**. export default defineConfig({ diff --git a/package-lock.json b/package-lock.json index 57879f8..56ea857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "green-tea-docs", - "version": "26.11.0-rc.1", + "version": "26.11.0-rc.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "green-tea-docs", - "version": "26.11.0-rc.1", + "version": "26.11.0-rc.2", "dependencies": { "@astrojs/starlight": "^0.41.6", "astro": "^7.1.6", diff --git a/package.json b/package.json index c5ae67e..7063911 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "green-tea-docs", "type": "module", "private": true, - "version": "26.11.0-rc.1", + "version": "26.11.0-rc.2", "scripts": { "dev": "astro dev", "clean": "rm -rf dist .astro node_modules/.astro", diff --git a/src/content/docs/guides/ai-agents.md b/src/content/docs/guides/ai-agents.md index 82c316c..05f8f1e 100644 --- a/src/content/docs/guides/ai-agents.md +++ b/src/content/docs/guides/ai-agents.md @@ -51,7 +51,7 @@ It matches the installed version and overrides what you know about Express-style **Deno (JSR).** There is no `node_modules`; link the copy on JSR for your version: ```md -https://jsr.io/@green-tea/core/26.11.0-rc.1/llms.txt +https://jsr.io/@green-tea/core/26.11.0-rc.2/llms.txt ``` **Chat tools with no file access.** Paste the file in, or give it this URL if the tool can fetch: diff --git a/src/content/docs/guides/arguments.md b/src/content/docs/guides/arguments.md index 54f2bf5..c62faa6 100644 --- a/src/content/docs/guides/arguments.md +++ b/src/content/docs/guides/arguments.md @@ -45,7 +45,7 @@ graph. in, plus built-ins. Use it to read values like `ctx.protocol` and `ctx.ip`. `ctx.ip` is the client address: the socket peer, or, when `trustProxy` is on and the request has -an `X-Forwarded-For` header, that header's first hop. On the edge, under `trustProxy`, +an `X-Forwarded-For` header, that header's last (right-most) entry: the address your proxy saw. On the edge, under `trustProxy`, `cf-connecting-ip` wins over both, because Cloudflare sets it itself. A bare `app.fetch(request)` from your own code has no socket, so there it is `''` unless a trusted header supplies it. diff --git a/src/content/docs/guides/html.md b/src/content/docs/guides/html.md index 2170f9b..26cd916 100644 --- a/src/content/docs/guides/html.md +++ b/src/content/docs/guides/html.md @@ -132,6 +132,8 @@ const app4 = createApp({ modules: [ApiModule], static: { dir: 'assets', cacheCon - Files are served at their URL path; content-type is inferred from the extension. - `/` (and any directory-shaped path) resolves to `index.html`. - Only `GET` and `HEAD` are handled — other methods fall through. +- **Dotfiles are never served.** A path with any segment starting with `.` (`/.env`, `/.git/config`) + is a `404`. Under `/.well-known/` the directory is served, but a dotfile inside it still is not. - **Declared routes always win.** Static is only consulted when nothing matched, so `@Get('/api/ping')` is never shadowed by a file at `public/api/ping`. - Path traversal (`../`, encoded or not) is rejected — a request can't escape the static root. - Symlinks are confined to the root too. A file, or a directory's `index.html`, is served only if diff --git a/src/content/docs/guides/introspection.md b/src/content/docs/guides/introspection.md index 025b9ac..8cf513d 100644 --- a/src/content/docs/guides/introspection.md +++ b/src/content/docs/guides/introspection.md @@ -127,7 +127,7 @@ const app = createApp({ modules: [ApiModule], health: true }); |---|---| | booting — until `boot()` resolves | `503 {"status":"booting"}` | | ready | `200 {"status":"ok"}` | - | ready, with degraded optional providers | `200 {"status":"degraded","degraded":["cache"]}` (from `app.degraded()`) | + | ready, with degraded optional providers | `200 {"status":"degraded"}`. The names are in the boot log and `app.degraded()`, not in a public probe. | | draining — from the moment `close()` starts | `503 {"status":"draining"}` | The state only moves forward: a boot that finishes after `close()` started stays draining. diff --git a/src/content/docs/guides/runtimes.md b/src/content/docs/guides/runtimes.md index cb56042..866ccad 100644 --- a/src/content/docs/guides/runtimes.md +++ b/src/content/docs/guides/runtimes.md @@ -94,7 +94,9 @@ Same API is not the same behaviour in every detail. The differences this page co `<= 0` leave Node's connection count unlimited. Positive values map to Node's `server.maxConnections` when the app runs through `app.listen()`. When the cap is reached, Node destroys excess sockets without sending an HTTP response. `Deno.serve` and `Bun.serve` expose no -equivalent active-socket cap, so `serveDeno` and `serveBun` cannot enforce this option. Apply the +equivalent active-socket cap, so `serveDeno` and `serveBun` cannot enforce this option. They, and +`edgeHandler`, warn through the app's logger at startup, naming each Node-only limit the app set +(`maxConnections`, `requestTimeoutMs`, `headersTimeoutMs`, `keepAliveTimeoutMs`). Apply the connection limit at the deployment platform or reverse proxy on those runtimes. `limits.maxConcurrentRequests` is separate from the connection limit and applies per server or Fetch adapter instance, so an app using both `app.listen()` and `app.fetch` has two independent request budgets. It bounds concurrently executing handlers; a handler that never returns continues to hold its slot, while on Node a client disconnect releases that slot. Excess requests receive `503 Service Unavailable` with `Retry-After: 1`. @@ -285,7 +287,8 @@ A `@Ws` handler's outbound iterator is pulled only while the socket's send buffe `serveDeno()` and `serveBun()` give `app.fetch` the socket peer, so `ctx.ip` is populated on Deno and Bun as it is on Node. All three follow one rule: with `trustProxy` on and an `X-Forwarded-For` -header present, `ctx.ip` is the header's first hop; otherwise it is the socket peer. That includes +header present, `ctx.ip` is the header's right-most entry, the one your proxy appended; otherwise it +is the socket peer. That includes `trustProxy` with no `X-Forwarded-For`, which falls back to the peer. `ctx.ip` is resolved the first time a step, a handler or a plugin reads it, and kept for the rest of @@ -299,7 +302,10 @@ the request; a route that never reads it pays nothing. What reading it costs dep | edge | the `cf-connecting-ip` header, under `trustProxy` | negligible | Behind a proxy that sets `X-Forwarded-For`, `trustProxy: true` takes the address from the header on -every runtime and never asks the socket. Inside a stream body `ctx.ip` is `''` unless a step or the +every runtime and never asks the socket. It takes the right-most entry because the client writes +everything to the left of it: up to RC.1 core took the left-most, so a client that sent +`X-Forwarded-For: 6.6.6.6` got that address in `ctx.ip`. Behind a chain of several proxies, the +right-most entry is the address the last proxy saw. Inside a stream body `ctx.ip` is `''` unless a step or the handler read it before returning the stream, because the socket may already be gone by then. Addresses are passed through as each runtime reports them. The IPv6 loopback is `::1` on all three, diff --git a/src/content/docs/guides/security.md b/src/content/docs/guides/security.md index 3a63123..e93ec8f 100644 --- a/src/content/docs/guides/security.md +++ b/src/content/docs/guides/security.md @@ -35,7 +35,9 @@ const app = createApp({ modules: [App], trustProxy: true }); ``` Behind a reverse proxy, reads `X-Forwarded-Proto` / `X-Forwarded-For` to populate -`ctx.protocol` (`'http' | 'https'`) and `ctx.ip` (read via `@ctx()`). Off by default — +`ctx.protocol` (`'http' | 'https'`) and `ctx.ip` (read via `@ctx()`), on every runtime. `ctx.ip` is +the **right-most** `X-Forwarded-For` entry, the one your proxy appended; the entries to its left are +whatever the client sent. Off by default — forwarded headers are ignored (and spoofable) until you opt in. It trusts the immediate hop unconditionally; there's no CIDR allowlist yet. @@ -62,6 +64,9 @@ route or the router's automatic `204` + `Allow` response. - With `credentials: true`, the server **never** sends `Access-Control-Allow-Origin: *` — it echoes the concrete allowed origin (or blocks the request). +- `origins: '*'` with `credentials: true` **fails `createApp`**. Together they would let any site + make credentialed reads. List the trusted origins, or, if an open credentialed API is really the + intent, write it as a predicate (`origins: () => true`) so the decision is visible in the code. ### When `origins` is a predicate @@ -79,11 +84,6 @@ that failed has not said yes, and a backing store being briefly unavailable must allowlist. Watch the logs for it — from the outside, a broken lookup and a genuinely disallowed origin look the same to the caller, which is the price of failing closed. -:::caution[Reflect-any foot-gun] -`origins: '*'` together with `credentials: true` reflects *any* origin with credentials -attached. Only combine them if you truly intend an open credentialed API; prefer an explicit -allowlist. -::: ## `security` (headers, ON by default) @@ -108,6 +108,19 @@ const app = createApp({ modules: [App], security: { csp: "default-src 'self'" } WebSocket handshake (101/upgrade) response. ::: +## WebSocket origins + +CORS does not apply to WebSockets: a browser opens one from any page and sends the user's cookies +with it. So every adapter checks the upgrade's `Origin` itself, and refuses with `403` unless: + +- there is no `Origin` header (not a browser: a server, a CLI, a test client), +- the `Origin` is on the same host as the request, or +- `cors.origins` allows it. + +`Origin: null` is refused. The mesh control channel is exempt, since it authenticates with its +secret. A browser client served from another origin, or an app behind a proxy that rewrites `Host`, +needs that origin in `cors.origins`. + :::caution[TLS + trustProxy] HSTS is emitted only when the connection is judged secure. With `trustProxy: true` that judgement trusts the incoming `X-Forwarded-Proto` header — so a client that spoofs @@ -126,7 +139,10 @@ These hold by default, with nothing to turn on: (`maxWsMessageBytes`, `maxWsQueue`), closing with `1009` / `1013`: [streaming](/docs/guides/streaming/#inbound-limits). - **Static files** never resolve outside the static root, through `../` or through a symlink, and - an escape is a `404`, not a `403`: [HTML & views](/docs/guides/html/#static-files--createapp-static-). + an escape is a `404`, not a `403`. Dotfiles (`/.env`, `/.git/config`) are never served: [HTML & views](/docs/guides/html/#static-files--createapp-static-). +- **Slow clients** cannot hold Node's connection slots: a socket still sending headers past + `headersTimeoutMs` is closed within a second, and a WebSocket peer that stops answering pings is + dropped within a minute. - **`ctx.ip`** is the client address on Node and through `serveDeno()` / `serveBun()`, so anything keyed on it, such as a rate limiter, does not put every client in one bucket: [runtimes](/docs/guides/runtimes/#the-client-address--ctxip). diff --git a/src/content/docs/guides/streaming.md b/src/content/docs/guides/streaming.md index c5e1b7e..d51c6bf 100644 --- a/src/content/docs/guides/streaming.md +++ b/src/content/docs/guides/streaming.md @@ -118,11 +118,16 @@ So decide which kind of source you have, and say so: ### When a stream fails part-way A source that throws mid-stream is reported the same way on every runtime: the framework writes the -encoder's error frame — `event: error` with the message, for SSE — and then closes the response +encoder's error frame (`event: error`, for SSE) and then closes the response cleanly, and emits `stream:error` on the [bus](/docs/guides/observability/). A consumer that received an `error` event knows what happened; a connection that merely dropped tells it nothing, which is why the frame comes first. +The frame carries an `HttpError`'s message, and `Internal Server Error` for anything else, as a +buffered route would. The full error, message and stack, goes to `stream:error` only. Up to RC.1 the +frame carried the raw `err.message`, so a database error's connection string could reach the +client. + ### `ctx.ip` inside a stream body `ctx.ip` is worked out the first time something reads it, not on every request. A stream body runs @@ -152,7 +157,9 @@ class ChatController { } ``` -`channel()` is a multicast `AsyncIterable` with `push` / `close` / `fail` and an optional bounded buffer (`channel({ buffer: 100 })`, drop-oldest). +`channel()` is a multicast `AsyncIterable` with `push` / `close` / `fail` and a bounded buffer per subscriber: 1024 values by default, dropping the oldest. Set it with +`channel({ buffer: 100 })`; `channel({ buffer: Infinity })` restores the unbounded buffer RC.1 had, +which lets one slow client grow server memory without limit. :::note[WebSocket needs the `ws` peer] `@Ws` (and mesh) require the optional [`ws`](https://github.com/websockets/ws) peer dependency — `npm i ws`. SSE, ndjson, and plain HTTP need nothing extra. diff --git a/src/content/docs/reference/createapp.md b/src/content/docs/reference/createapp.md index 76c70ff..ddf1b14 100644 --- a/src/content/docs/reference/createapp.md +++ b/src/content/docs/reference/createapp.md @@ -84,7 +84,7 @@ WebSocket upgrade to the mesh path is closed. ### `CorsOptions` -`{ origins, methods?, allowedHeaders?, exposedHeaders?, credentials?, maxAge? }`. `origins` is a string, array, `'*'`, or a `(origin) => boolean` predicate. `credentials: true` is never combined with `'*'`. +`{ origins, methods?, allowedHeaders?, exposedHeaders?, credentials?, maxAge? }`. `origins` is a string, array, `'*'`, or a `(origin) => boolean` predicate. `origins: '*'` with `credentials: true` fails `createApp`; list the origins, or pass a predicate. ### `SecurityOptions` diff --git a/src/content/docs/whats-new.md b/src/content/docs/whats-new.md index 1e03a8d..d1c9ef5 100644 --- a/src/content/docs/whats-new.md +++ b/src/content/docs/whats-new.md @@ -1,6 +1,6 @@ --- title: What's new -description: "What changed in @green-tea/core RC.1, and what it means if you are already using it." +description: "What changed in @green-tea/core RC.2 and RC.1, and what it means if you are already using it." --- :::note[The API is frozen from RC.1] @@ -9,6 +9,40 @@ only: nothing public is added, removed, renamed or narrowed. [API stability](/do the full policy, including how deprecations work after stable. ::: +## RC.2: security fixes + +RC.2 fixes nine security advisories reported against RC.1, and every one of them is in RC.1 and +earlier. **Upgrade:** `npm i @green-tea/core@26.11.0-rc.2`, or `jsr:@green-tea/core@26.11.0-rc.2`. +The [security advisories](https://github.com/Expressive-Tea/green-tea/security/advisories) have the +details, and the [changelog](https://github.com/Expressive-Tea/green-tea/blob/main/CHANGELOG.md) +has every change. + +No public API changed, and the freeze holds. Some behaviour did, and that is what can affect an +upgrade: + +| What changed | Who it affects | What to do | +|---|---|---| +| `cors: { origins: '*', credentials: true }` fails `createApp` | apps that set that pair | list the origins, or write `origins: () => true` if you really mean it. [CORS](/docs/guides/security/#cors) | +| WebSocket upgrades from another site get `403` | browser clients on another origin; apps behind a proxy that rewrites `Host` | add the origin to `cors.origins`. [WebSocket origins](/docs/guides/security/#websocket-origins) | +| `static` no longer serves dotfiles | apps that served one on purpose | move it, or serve it from a route. [Static files](/docs/guides/html/#static-files--createapp-static-) | +| Under `trustProxy`, `ctx.ip` is the right-most `X-Forwarded-For` entry | apps behind several proxies | `ctx.ip` is now what the last proxy saw. [Client address](/docs/guides/runtimes/#the-client-address--ctxip) | +| A stream's error frame says `Internal Server Error` unless the error is an `HttpError` | clients that read the frame's text | throw an `HttpError` for a message meant for the client. [Streaming](/docs/guides/streaming/#when-a-stream-fails-part-way) | +| `channel()` buffers 1024 values per subscriber, dropping the oldest | subscribers that fall further behind | `channel({ buffer: Infinity })` for the old behaviour | +| `/__ready__` no longer lists degraded provider names | probes that read `degraded` | read `app.degraded()` or the boot log | +| Mesh: a `ws://` teapot off loopback fails `createApp` | mesh apps (experimental) | use `wss://`, or `mesh.allowInsecure` on an encrypted network. [Mesh](/docs/guides/mesh/) | + +Fixed with no behaviour change you need to act on: Node closes slow-header sockets and dead +WebSocket peers promptly; the template engine no longer re-renders `{{{ }}}` output; a form field +named `__proto__` is an ordinary key; argument decorators read own keys only; Deno, Bun and +`app.fetch` honour `X-Forwarded-Proto` under `trustProxy`; a mesh teapot checks the route's HTTP +method and stops sending internal error messages to the client. + +Other fixes: Bun no longer drops an SSE stream idle for 10 seconds, a long SSE stream no longer +grows the heap per event, an async bus listener that rejects no longer exits Node, and a bus +listener that throws is logged once. + +## RC.1 + This is what changed in **RC.1** since `26.9.0-beta.2`, in the order it matters to you rather than the order it was built. The [full changelog](https://github.com/Expressive-Tea/green-tea/blob/main/CHANGELOG.md) has every release and every detail; this page is only the current one. @@ -17,14 +51,14 @@ The breaking changes come first, because they are what can stop an upgrade. Each that had to move before the freeze, and each has a migration. Nothing published in beta.2 was removed: the one renamed type keeps its old name as a deprecated alias. -## Breaking +### Breaking -### Node 22 is the minimum +#### Node 22 is the minimum Node 18 and 20 are end-of-life and receive no security patches, so `engines.node` is now `>=22`. **Migrate:** upgrade Node before you upgrade green-tea. -### Response header values are `string | string[]` +#### Response header values are `string | string[]` `TransformerFn`, `ErrorResponse.headers`, `HttpError.headers` / `HttpErrorLike.headers` and the pipeline's `ResponseShape.headers` widen from `Record`, so a response can carry @@ -35,7 +69,7 @@ as one line joined with `, `. **Migrate:** code that *produces* headers needs nothing. Code that *reads* `headers[k]` from one of these types as a `string` stops compiling and must handle the array. -### Inbound WebSocket messages are capped at 1 MiB, and 16 unread messages +#### Inbound WebSocket messages are capped at 1 MiB, and 16 unread messages A larger message closes the connection with `1009`; a 17th unread message closes it with `1013`. Before, Node allowed 100 MiB, the other runtimes applied no cap, and the inbound queue was @@ -44,7 +78,7 @@ unbounded everywhere. A `@Ws` handler that never reads `inbound` counts too. **Migrate:** raise the bounds with `limits.maxWsMessageBytes` and `limits.maxWsQueue` if your clients legitimately need more. See [Streaming](/docs/guides/streaming/#inbound-limits). -### Overlapping constrained route params fail boot +#### Overlapping constrained route params fail boot Two routes of one method that branch at the same segment now fail `createApp` when both constraints accept a common segment (`/u/:id(\d+)` and `/u/:n(\d{1,3})`), or when a constraint that accepts @@ -56,7 +90,7 @@ Delete a plain param reported as unreachable: it never answered a request. For a declare the constrained route first. See [Routing](/docs/guides/routing/#overlapping-constraints-fail-at-boot). -### A token has one producer +#### A token has one producer A second node providing a token fails `createApp`, naming both: `token 'user' is provided twice: by 'user' (module:AppModule) and by 'shadow' (plugin)`. Before, @@ -66,7 +100,7 @@ keep working. **Migrate:** rename one producer's token. See [Plugins](/docs/guides/plugins/#what-a-plugin-can-and-cannot-touch). -### A node that needs the token it provides fails boot +#### A node that needs the token it provides fails boot A step with `needs: ['user']` and `provides: 'user'` used to boot and then read a value nobody had written. It now fails as a cycle: `cycle detected: user -> user (it needs 'user', which only it @@ -76,7 +110,7 @@ provides)`. Seeded tokens such as `req` and `params` still satisfy a node's own separate provider or step the node needs. See [Dependency injection](/docs/guides/dependency-injection/#a-node-cannot-need-what-it-provides). -### `/__mesh__/control` is reserved in every app +#### `/__mesh__/control` is reserved in every app A `@Ws`, `@Stream` or HTTP route that claims it — or a mountpoint that adds up to it — fails `createApp`, mesh or not. Before, Node served a user route there when no mesh was configured, while @@ -85,7 +119,7 @@ Deno, Bun and the edge refused it. **Migrate:** move the route, for example to `/mesh/control`. See [Routing](/docs/guides/routing/#reserved-paths). -### Static files are revalidated, not re-downloaded +#### Static files are revalidated, not re-downloaded Every static hit carries a weak `ETag`, `Last-Modified` and `Cache-Control: no-cache`, and a matching conditional request answers `304` without reading the file. @@ -94,7 +128,7 @@ matching conditional request answers `304` without reading the file. `'public, max-age=31536000, immutable'` for content-hashed assets. See [Caching & compression](/docs/guides/caching-and-compression/). -### A handler that returns `undefined` answers `204 No Content` +#### A handler that returns `undefined` answers `204 No Content` Before, Node sent an empty `200` with a JSON `content-type`, and Deno, Bun and the edge answered `500`. Every runtime now sends `204` with no body. `null` still gives `200` with `null`, and a route @@ -103,7 +137,7 @@ with its own `@Transformer` is not affected. **Migrate:** a client that checked for `200` after a handler with no `return` now sees `204`; return a value from the handler to keep the `200`. -### `serveDeno()` and `serveBun()` reject an app created with `tls` +#### `serveDeno()` and `serveBun()` reject an app created with `tls` Only Node's `listen()` ever read `tls`, so on Deno and Bun the same app came up as plain HTTP without a word. Both adapters now reject before they boot or bind. @@ -111,7 +145,7 @@ a word. Both adapters now reject before they boot or bind. **Migrate:** drop `tls` from `createApp` and configure TLS on the runtime's server, or terminate it at a proxy. See [Runtimes](/docs/guides/runtimes/). -### Edge WebSocket upgrades trust `cf-connecting-ip` only under `trustProxy` +#### Edge WebSocket upgrades trust `cf-connecting-ip` only under `trustProxy` `edgeHandler` copied the header into `ctx.ip` on every upgrade, so any client chose its own address. It now counts only under `trustProxy: true`; without it, `ctx.ip` on an edge WebSocket is @@ -120,7 +154,7 @@ address. It now counts only under `trustProxy: true`; without it, `ctx.ip` on an **Migrate:** an app behind Cloudflare that keys anything on the client address sets `createApp({ trustProxy: true })`. See [Runtimes](/docs/guides/runtimes/#the-client-address--ctxip). -## Added +### Added - **Health probes** — `createApp({ health: true })` serves `/__live__` and `/__ready__`, answered ahead of the route table, with `/__ready__` reporting `booting`, `ok`, `degraded` and `draining`. @@ -142,7 +176,7 @@ address. It now counts only under `trustProxy: true`; without it, `ctx.ip` on an - **`RequestHeaders`** — the request headers type under a name that does not shadow the Fetch `Headers` global. -## Changed and fixed +### Changed and fixed - **Route lookup uses a radix index per method.** Internal, and the same route still wins with the same params, `Allow`, implicit `HEAD` and 404/405. See [Routing](/docs/guides/routing/#matcher-scale). @@ -161,7 +195,7 @@ address. It now counts only under `trustProxy: true`; without it, `ctx.ip` on an routes removed; every change emits `mesh:routes`. The mesh exports are now marked `@experimental`, outside the freeze. See [Mesh](/docs/guides/mesh/). -## Deprecated +### Deprecated - **The `Headers` type.** Import `RequestHeaders` instead — the same type. `Headers` stays as an alias, so nothing breaks. See [API stability](/docs/stability/#currently-deprecated).