Repository navigation
Description
Evidence (origin/main ccb195b)
- `pkgs/id/hosted-worker/src/user-do.ts:291-300` (KV PUT): `const value = await req.text();` runs before any size check. The byte delta is computed only afterwards, in `this.assertWritable(new TextEncoder().encode(value).byteLength - priorBytes)` at `:295`.
- `pkgs/id/hosted-worker/src/user-do.ts:237` (blob PUT): `const bytes = new Uint8Array(await req.arrayBuffer());` has the same order. `assertWritable` runs at `:246`.
- `assertWritable` (`:135-146`) checks the storage ceiling only. Nothing in `hosted-worker/src` caps the request body size (grep for content-length, 413, too_large and bodyLimit finds only the storage 413 in `assertWritable`).
Result: a write that is already over the ceiling is still fully buffered into the Durable Object's memory before it is refused with a 413. A body larger than the DO's memory limit would fail inside the isolate rather than return the documented `ceiling_exceeded` response.
Not yet reproduced at runtime. The claim is about the code path, not a measured OOM.
Why it matters
The ceiling is documented as a fail-closed guard for writes. The guard runs after the most expensive step, so an oversized write can crash the DO instead of being refused cleanly. The user then gets an opaque error and the DO may reset.
Fix shape
- Reject early from `Content-Length` when it is present and already exceeds the remaining headroom (`ceiling - usage`), before reading the body.
- For bodies without a length, read through a size-capped reader that stops at the remaining headroom plus one byte, then returns `ceiling_exceeded`.
- Keep the existing `assertWritable` check as the authoritative delta check.
Acceptance criteria
- A PUT to `/v1/kv/:key` or `/v1/blobs` whose declared length exceeds the remaining headroom returns 413 `ceiling_exceeded` without reading the body.
- A chunked PUT larger than the headroom stops reading at the cap and returns the same 413.
- Existing under-cap writes and overwrite deltas behave as before.
- A test covers the early reject and the chunked cap.
Dedupe
Searched open and closed issues for "user-do KV body", "request body size limit hosted-worker" and "user-do": no matching issue or open PR. Related but different: #6880 and #2791 (cloudflare-export numeric handling) and #3000 (aggregator regex), none of which touch this path.
Queue: `repo-queue` is not available in this environment, so no queue item was enqueued. Coverage needs a follow-up pass.
Activity
developing-today commentedon Nov 17, 2026
CODE-4113
hosted-worker: kv shrink not refused when usage is over ceiling (#11332)
hosted-worker: revert max() headroom; shrink over cap is refused by a…
Merge pull request #11336 from developing-today/sweep/11332-user-do-b…
dezren39 commentedon Nov 17, 2026
Fixed in #11336 (merged as a merge commit).
ceiling - usage + prior value bytes) before reading the body. A declaredContent-Lengthover headroom returns 413ceiling_exceededwithout reading. A chunked body is read through a capped reader that stops at headroom.assertWritableremains the authoritative check. Under-cap writes and overwrites are unchanged.test/usage.test.ts.node --testover routing, blobs, usage and currency: 22/22 pass.Not reproduced at runtime; this is from the code path.