Skip to content

pkarr-worker: PUT and DoH POST bodies are fully buffered with arrayBuffer() before the size caps are checked (DoH rate limit also runs after the read) #4866

Closed

Description

@dezren39

Finding

In pkgs/pkarr-worker/src/index.ts, both request-body size caps are checked after the whole body has already been buffered with request.arrayBuffer():

// current main (eefeab5af), PUT /pkarr/<key> — cap is MAX_RELAY_PAYLOAD = 1072 bytes
120:  const body = new Uint8Array(await request.arrayBuffer());
121:  if (body.length > MAX_RELAY_PAYLOAD) return new Response("payload too large", { status: 413 });

// current main, POST /dns-query — cap is MAX_DOH_BODY = 4096 bytes (index.ts:44)
260:  return handleDoh(request, env, new Uint8Array(await request.arrayBuffer()));
179:  if (queryBytes.length > MAX_DOH_BODY) return new Response("message too large", { status: 413 });

For the DoH POST path the ordering is worse: the per-IP rate limiter (index.ts:198, inside handleDoh) also runs only after the full body has been read, so an oversized DoH body costs the Worker a full buffer before any limit — size or rate — is consulted. (The PUT path does rate-limit before reading; the DoH path does not.)

Evidence

Why it matters

The caps exist to bound what an unauthenticated remote caller can make the Worker handle — 1,072 bytes for a publish, 4,096 bytes for a DoH query. As written, the bound applies to what is processed, not what is buffered: a caller can send a body up to the platform request-size limit (100 MB on Cloudflare's free plan) and the Worker will allocate for all of it before returning the 413 the cap was supposed to produce cheaply. Against a 128 MB-memory Worker, oversized-body floods are a memory-exhaustion / error-1102 surface instead of a cheap early rejection — exactly the read-then-check pattern the repo's bounded-body work elsewhere exists to remove.

Acceptance criteria

  • PUT /pkarr and POST /dns-query reject an over-cap body without buffering it whole: a Content-Length pre-check where the header is present, and/or a streaming read that aborts once the cap is exceeded.
  • The DoH path consults its rate limiter (or at least the size pre-check) before reading the body.
  • Over-cap requests still return 413; at-cap and under-cap requests behave exactly as before (existing vitest suite green).
  • A test demonstrates an over-cap body is rejected on the pre-read check (e.g. declared Content-Length above the cap), not only after a full read.

Activity

  1. added
    kind/securitySecurity issue or security hardening
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/lowNice to have; do when convenient
    effort/sSmall: expected under 2 hours of work
    on Nov 3, 2026
  2. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: reviewed (coverage loop-back)
    Coverage pass 2026-11-03, loop-back review: this issue was re-reviewed (drift / overlap / already-handled / stale / blockers / ordering) so every open issue in the four repos is reviewed and in the system. Verdict: still live; in the system as task 7517 (triage, queued, priority 70) in repo-health-code-pilot. Labels audited and synced. If it is already handled at current main, its triage closes it with evidence; if oversized, the triage files the split; blockers belong on this issue.
    Found via: coverage loop-back 2026-11-03

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 4, 2026
  5. 14 remaining items

  6. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  7. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: picked_up (resume)
    task: 9302 (repo-health-code-pilot; openchamber-scheduled-lane 7b47536b-c162-444c-be8a-3a9538cc4cb5)
    state: claimed; fresh verification: #4866 OPEN, no related open PR, no hard-stop labels, and claim labels are in sync. Resuming from the prior opencode handoff; no existing task branch/worktree was recorded or found.
    next: implement bounded streaming reads for the PUT and DoH routes, rate-limit DoH before the read, add regressions, and open the PR before any polish.

  8. added a commit that references this issue on Nov 4, 2026
  9. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: done
    task: 9302 (repo-health-code-pilot; openchamber-scheduled-lane 7b47536b-c162-444c-be8a-3a9538cc4cb5)
    state: fixed_merged; PR #5621 merged at 6499f51.
    verification: 46 tests passed across 2 files; typecheck and diff check passed. The PR showed no GitHub CI run (CodeRabbit skipped); the checked-out policy-listed proxy workflow was merge_group-only despite policy text describing pull_request coverage. This coverage gap is recorded in task 9302.
    bookkeeping: sandbox backlog and sweep.log deferred to fleet reconciliation.

  10. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · done (already_done)

    Verdict: already done — closing as completed.

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

Metadata

Metadata

Assignees

Labels

app/pkarr-workerpkgs/pkarr-workereffort/sSmall: expected under 2 hours of workkind/securitySecurity issue or security hardeningpriority/lowNice to have; do when convenientsource/pr-diff-reviewFiled by the pr-diff-review jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions