Skip to content

fix(hosted-worker): front door buffers every non-GET body with arrayBuffer() before routing, so the PR #11336 early refusal never runs #11337

Closed

Description

@dezren39

Summary

The hosted data-plane front door reads every non-GET/HEAD request body into memory before routing, so the body cap added to the user DO in PR #11336 (closing #11332) can never refuse an oversized request early. The early refusal (Content-Length check and readTextUpTo cap in pkgs/id/hosted-worker/src/user-do.ts:341-344) only runs after the Worker has already buffered the whole body.

Evidence (origin/main c4a5fb592e)

Why it matters

  • Memory: a single unauthenticated-size PUT/POST of arbitrary length is held in the Worker isolate before the storage ceiling or any per-route limit applies. The DO-side fix is therefore ineffective for the exact case it targets.
  • Cost and reliability: the buffer is paid even for requests the DO will refuse with 413 after the fact.
  • Scope: every mutating route in the hosted data plane (KV, blob, and any future POST) shares this path, so the gap is not specific to one route.

Suggested fix shape

  • In worker.ts, enforce a front-door body limit for non-GET/HEAD requests before arrayBuffer(): refuse a declared Content-Length above the largest per-route limit with 413, and pass the request body through as a ReadableStream (or a capped reader) so no route reads more than its limit into memory.
  • Keep the DO's per-route check as the authority for storage ceilings. The front-door check only bounds memory.
  • Route-specific limits should be defined once and used by both the front door and the DO, so the two cannot drift.

Acceptance criteria

  1. An oversized PUT with a declared Content-Length above the limit is refused with 413 at the Worker front door, and the forwarded body is never read into memory (test: a body stream that records bytes read, asserting the read stops at the limit).
  2. An oversized chunked PUT (no Content-Length) is refused after reading at most the limit plus one chunk (same instrumentation).
  3. A normal-size KV PUT and blob PUT still succeed end to end through worker.ts, not only through the DO in isolation. The existing test/usage.test.ts tests call UserDO directly and do not exercise worker.ts, so add a test that goes through the default export.
  4. Mutation check: removing the new front-door cap fails test 1.

Related

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 17, 2026
  2. developing-today commented on Nov 17, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    Current-main triage (2026-11-17): still reproducible by source inspection at origin/main a03c40960a6b938bf36258687f1305237da717e6. pkgs/id/hosted-worker/src/worker.ts:42-47 awaits req.arrayBuffer() for every non-GET/HEAD method before calling stub.fetch; the Durable Object cap in user-do.ts:342-345 therefore runs only after full buffering. wrangler.toml points production at this entry point. No open PR matches #11337.

    A fresh repo-queue dedupe lookup found the existing task 20766 in repo-health-code-pilot, status queued (the task is a fix task; the issue labels had not reflected that). I’m syncing issue labels to the live task.

  4. added
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    status/triagedTriaged and routed (see agent note)
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 17, 2026
  5. added a commit that references this issue on Nov 17, 2026
  6. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — picked up (queue task 20766, lane oc-code-04)

    Fresh claim revalidation found #11337 already CLOSED by merged PR #11427. The PR explicitly closes this issue, changes the front-door worker and adds the acceptance tests. No implementation started in this claim.

  7. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — done/already_done (queue task 20766, lane oc-code-04)

    Verified #11337 is CLOSED by merged PR #11427 (Closes #11337), merged 2026-11-17T22:24:59Z at c89be38. The PR fixes the front-door body buffering, adds end-to-end front-door tests, and reports 27 tests passing plus clean tsc --noEmit. No branch or code changes were needed in this claim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)queue/queuedHas a queued queue tasksource/creatorFiled by the new-issue-creator jobstatus/triagedTriaged and routed (see agent note)status:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions