Repository navigation
fix(link): refuse a prepared relay body that ends before its declared Content-Length - #8611
Merged
Merged
Conversation
… Content-Length readDeclaredBody returned the shorter slice when a compressible request body ended cleanly before its declared length, and the relay forwarded it to the Home as a complete body with the shorter Content-Length. A short body now throws, which the relay already answers with 400 before anything reaches the Home. The streamed path is unchanged. Refs #8604
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Contributor
|
✅ Deterministic PR hygiene checks passed. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
From the final review of #8594. Closes #8604.
A Child's link relay buffers and zstd-compresses a request body when the route allows it and the Home named
link-request-zstd/1.readDeclaredBody(src/client/link-request-compression.ts) reads exactly the declared Content-Length into one buffer. When the body ended cleanly before that length, it returned the shorter slice. The relay then set Content-Length to that shorter length and forwarded the body, so the Home received a body that looked complete although the client had declared more. In practice the truncated JSON failed to parse on the Home.readDeclaredBodynow throws aRangeErrorwhen the body ends with fewer bytes than declared, as it already did for more. The relay's existing catch answers400 link relay request body unreadable(or the tunnel-unavailable 503 when the caller aborted), releases the preparation allowance, and sends nothing to the Home.The streamed path does not call
readDeclaredBodyand is unchanged. It covers a Home that did not name the capability, routes that do not compress, chunked bodies, and bodies that do not fit the preparation allowance. A streamed body keeps the caller's Content-Length, so the Home still sees a short upload there. I checked this with a scratch test outside the repository, run against both versions. A body 10 bytes short on/v1/responsesto a Home without the capability, and on/v1/images/generationsto a Home with it, reached the Home with the declared length (8212), the Home's read ended inAbortError, and the caller got 503 at the relay's header deadline (about 12 s), the same before and after. That check depends on the wall clock, so it is not committed.structure/remote-link.mdnow states the refusal and the streamed-path difference.What keeps this inert. Only the prepared path changes, and it runs only on a Child whose Home named
link-request-zstd/1, for a POST on a compressible route with a declared length between 1 KiB and 16 MiB. A body whose bytes match its declared length, which is every well-formed request, is prepared exactly as before. No config key, default or other code path changes.Verification
Tests written first, on
devat e85a975, intests/clients/link-request-zstd.test.ts:a body that ends cleanly before its declared length is unreadable, never a shorter complete body:readDeclaredBodyon a stream 10 bytes short of its declared length must reject with a RangeError, and an exact-length stream still resolves to the same bytes. Ondevit failed with "Received promise that resolved".a prepared body shorter than its declared Content-Length answers 400 and reaches no Home: through the relay to a real hub-link session dispatcher that named the capability, a short body must answer 400link relay request body unreadable, leave the Home's traffic book at the one priming request, and release the preparation allowance. Ondevthe truncated body reached the Home's JSON decoder ("JSON Parse error: Unterminated string") and the test failed.Commands on this branch (exit codes):
TMPDIR=/tmp bun test tests/clients/link-request-zstd.test.ts: 16 pass, 0 fail (exit 0).bun run typecheck: exit 0.bun run privacy:scan: exit 0.bun run structure:check: exit 0.TMPDIR=/tmp bun scripts/test.ts --parallel=2 tests/clients tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/structure-ssot.test.ts tests/ci-workflows/ci-structure-gate.test.ts tests/ci-workflows/file-size-ratchet.test.ts(203 files, includingtests/clients/client-link-relay.test.tsandtests/clients/link-boundary.test.ts): 3410 pass, 67 skip, 3 fail (exit 1). The 3 failures are the Rust ocx-child tests (tests/clients/link-ocx-child-e2e.test.ts, two cases, and the Rust case oftests/clients/link-ocx-child-conformance.test.ts). They stop before any test code runs, becausecargoon the build machine has no default rustup toolchain. This branch touches no Rust code.NOT RUN: the full
bun run testsuite (the build machine allows focused files only; CI covers the rest); the three Rust ocx-child tests above (no toolchain); whether Bun ever ends a real request body cleanly when it is short (the issue left this open; the fix holds either way); Windows and macOS (the changed code is platform-independent).Review: one read-only round by an independent reviewer (gpt-6.1-terra, xhigh effort) on the exact head 12894b9 found no P0–P2. It confirmed that
readDeclaredBodyhas one production caller (the prepared-body path, reached only by eligible POSTs without Content-Encoding; HEAD, chunked and already encoded bodies never enter it), that the error path releases the preparation lease and the reader lock before contacting the Home, and that an aborted relay signal maps to 503 and a clean short end or stream error to 400. It also confirmed that both new tests fail on the parent for the stated reasons and pass on this head (link-request-zstdandclient-link-relay: 61 pass, 0 fail). Not established by the tests: which stream and signal behaviour Bun produces for every real client disconnect; the tests simulate a clean short stream.Checklist
Implemented by Claude Opus 5.5 (anthropic/claude-opus-5-5) in GOAT through the Codex harness; review by GPT-6.1 Terra (xhigh). Received as a git bundle from the VM that built it and pushed by the coordinator.