Skip to content

fix(vendor): validate gRPC-web body trailers before completion - #31

Open
Crackdevs wants to merge 7 commits into
red-dev-inc:feat/nu7-portable-keysfrom
Crackdevs:fix/grpc-web-trailer-completion
Open

Crackdevs wants to merge 7 commits into
red-dev-inc:feat/nu7-portable-keysfrom
Crackdevs:fix/grpc-web-trailer-completion

Conversation

@Crackdevs

@Crackdevs Crackdevs commented Nov 17, 2026 •

Copy link
Copy Markdown

Follow-up to #28 and our discussion with Daniel/Konclave.

This PR depends on #28. While #28 remains unmerged, the full comparison includes its changes. Our incremental follow-up is:
Crackdevs@b0fd000

Changes

  • Continue delivering complete data frames as they arrive, but wait for clean HTTP body EOF before forwarding the terminal trailer.
  • Reject bytes after the trailer and propagate transport failures while awaiting EOF.
  • Require exactly one syntactically valid grpc-status in body trailers, counting header names after normalization.
  • Preserve recognized status codes and let tonic map unfamiliar numeric codes to Unknown.
  • Preserve existing empty trailers-only behavior.

Existing HTTP-header status precedence and duplicate handling for other metadata remain outside this change. The OHTTP transport hook is tracked separately in #30.

Validation

Recorded local validation:

  • 25 passing native tests.
  • Six regressions that fail against the fix(vendor): forward the gRPC-web trailer frame to tonic #28 baseline and pass with this patch.
  • 15 passing compiled Rust/WASM client fixture checks in Chromium.
  • Separate read-only public endpoint measurements: 15 recorded calls each in Node and Chromium.

Cancellation coverage includes browser timeout cancellation and native stream-drop cancellation.

The standalone WASM crate and harness build passed using dependency versions from the workspace lock. Building the vendored crate through the workspace’s plain WASM command encountered the same native Tokio/mio target failure on both the baseline and patched versions.

The public endpoint measurements were separate from the compiled Rust/WASM tests against controlled fixtures.

These results come from the original local validation. The published files match the reviewed patch; the tests were not rerun in Codespaces.

Review

@danielgorgonha, this is the follow-up we discussed. Please review the EOF handling and body-trailer status validation.

Thanks to Daniel/Konclave for the #28 backport, regression tests and public endpoint measurements. Attribution to the original Crackdevs proof and upstream changes is retained in VENDORED.md.

Review evidence

Test results, logs and reproduction instructions:
https://github.com/Crackdevs/zcash-browser-ohttp-proof/blob/main/webzjs-trailer-follow-up/README.md

danielgorgonha and others added 6 commits November 15, 2026 07:50
…wasm-client

The response body can now be fed from in-memory chunks, so the tests run
natively, without a browser: `ResponseBody::new` delegates to a private
`from_body_stream` (no change in behaviour), and a `cfg(test)`
`BodyStream::from_chunks` builds the stream. Eight of the tests fail on this
commit: the trailer frame is parsed but never handed to tonic, so a status
sent in the body trailer is lost.

Co-Authored-By: Claude <noreply@anthropic.com>
tonic-web-wasm-client 0.8.0 parsed the trailer frame, stored it in a field
nothing read, and ended the body as soon as it saw the trailer flag. tonic
never got the trailers, and with HTTP 200 and no trailers it reports success,
so a status sent in the body trailer (an error after some messages, or after
a unary message) was lost.

The body now yields the parsed trailers as a trailers frame, once, after the
last data frame. It only counts as finished once the trailer frame has been
read in full, so a trailer split across chunks is read and a stream that ends
inside the trailer frame is MalformedResponse instead of a clean end.

The first part is the response_body.rs change of upstream 0f232d33
(devashishdxt/tonic-web-wasm-client#90, released in 0.9.1).

Co-Authored-By: Claude <noreply@anthropic.com>
…ob for the vendored tests

trailers.patch applies on top of trailers-only.patch and reproduces src/ from
crates.io 0.8.0, apart from the test files: it carries their two cfg(test)
hooks but not src/response_body/. The vendored crate is excluded from the
workspace, so a separate job runs its tests against the workspace lock.

Co-Authored-By: Claude <noreply@anthropic.com>
Their browser OHTTP proof had already fixed it in its own patch, not only
found it.

Co-Authored-By: Claude <noreply@anthropic.com>
They found the lost trailer status, reproduced it and fixed it first in their
browser OHTTP proof (https://github.com/Crackdevs/zcash-browser-ohttp-proof).

Co-authored-by: Crackdevs <info@crackdevs.org>
Co-Authored-By: Claude <noreply@anthropic.com>
@Crackdevs
Crackdevs marked this pull request as draft November 17, 2026 16:05

@danielgorgonha danielgorgonha left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At b0fd000 the vendored crate's 25 native tests pass, and the six new regressions fail when src/response_body.rs is put back to #28 (a189141) with the new tests kept. Approving.

  1. EOF wait. After the trailer parses, the body waits on the stream's own waker and forwards the trailer only at a clean end. There is no busy loop, a transport error while waiting reaches tonic with the trailer dropped, and dropping the stream drops the source. Data frames are yielded one per poll and taken before the next step, so none is overwritten.
  2. Status validation. Each new check is covered. Removing any one of them (duplicate, missing, non-digit, leading zero, the blank-line guard, bytes after the trailer) makes a test fail. Since HeaderName::from_bytes lowercases, Grpc-Status counts as a duplicate. Only 0 reaches tonic as OK, and other numbers reach it as Unknown with message, details and metadata intact, as agreed in Crackdevs/zcash-browser-ohttp-proof#1.
  3. The three patches applied in order to the crates.io 0.8.0 source, plus src/response_body/, give the vendored src/ exactly.
  4. Non-blocking, a note for VENDORED.md. A server that keeps the body open after the trailer now holds the call, where #28 completed it. WebZjs builds its client with Client::new (crates/webzjs-wallet/src/bindgen/wallet.rs:144) and sets no timeout, so for WebZjs wallets "the existing fetch cancellation and deadline behavior" means no deadline. The public endpoint we measured (zcash-mainnet.chainsafe.dev) closes the body within 0.3 ms of the trailer, so this is unlikely to bite, but it is worth one sentence there.
  5. The raw_buf checks are not reachable yet, because the text path panics in decode_base64_chunk before them, on #28 as well. That matches the limitation VENDORED.md already lists, and the checks are right once that path is fixed.

This review was prepared with an AI assistant, which also ran the tests. I read it before posting.

@Crackdevs

Copy link
Copy Markdown
Author

Thanks, @danielgorgonha, for reviewing this and reproducing the tests. we've added the clarification in VENDORED.md that WebZjs currently sets no request timeout, so waiting for EOF can leave a call pending. The existing text/base64 limitation remains documented and outside this follow-up.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants