Skip to content

fix: zstd compat flag, DevTools inspector, empty-body edge case, RPC hardening#6838

Closed
StilesCrisis wants to merge 3 commits into
cloudflare:mainfrom
StilesCrisis:fix/zstd-decode-hardening
Closed

fix: zstd compat flag, DevTools inspector, empty-body edge case, RPC hardening#6838
StilesCrisis wants to merge 3 commits into
cloudflare:mainfrom
StilesCrisis:fix/zstd-decode-hardening

Conversation

@StilesCrisis

Copy link
Copy Markdown

Summary

Hardening fixes from code review, stacked on top of #6837. None of these are correctness fixes for the happy path — they close edge cases and improve robustness.

  • Compat flag: gate zstd behind zstd_content_encoding (enabled 2026-06-21) to match the brotli_content_encoding pattern; workers pinned to old compat dates are unaffected
  • DevTools inspector: ResponseStreamWrapper now decompresses zstd response bodies for accurate network panel byte counts, matching the existing gzip/brotli handling
  • Empty-body edge case: EncodedAsyncOutputStream::endImpl() now rejects ZSTD encoding even when no write() was called, consistent with the prepareWrite() error path for non-empty bodies
  • RPC robustness: replace KJ_ASSERT(encoding == IDENTITY) with KJ_FAIL_REQUIRE in both ensureIdentityEncoding() fallthrough branches so unknown future encoding values from a newer RPC peer throw a catchable error instead of aborting (debug) or silently corrupting (release)

Depends on #6837.

Test plan

🤖 Generated with Claude Code

johnstiles-google and others added 3 commits June 21, 2026 14:39
…ncoding header

When a fetch() subrequest returns Content-Encoding: zstd, workerd now:
1. Decompresses the body transparently via a new ZstdAsyncInputStream class
2. Strips the Content-Encoding header from the Response so downstream code
   (e.g. Cache API) doesn't re-interpret the already-decoded body as zstd

This mirrors the existing gzip and brotli auto-decode behavior. Adds ZSTD to
the StreamEncoding capnp enum, implements ZstdAsyncInputStream using the zstd
streaming API in both system-streams.c++ and readable-source.c++, and adds
KJ_FAIL_REQUIRE for the unsupported zstd output compression path.

Fixes: cloudflare#5112

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds 4 readable-source tests and 2 writable-sink tests mirroring the
existing gzip test suite:
- Zstd encoded stream (readAllBytes)
- Zstd encoded stream (pumpTo)
- Zstd encoded stream (pumpTo same encoding passthrough)
- Zstd encoded stream (pumpTo different encoding → gzip)
- Zstd-encoding sink (throws for unsupported output compression)
- Zstd-encoding sink (identity passthrough via disownEncodingResponsibility)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…cases

- Add zstd_content_encoding compat flag (enabled 2026-06-21) to match the
  brotli_content_encoding pattern; workers on old compat dates are unaffected
- Fix DevTools network inspector to decompress zstd response bodies using a
  new ZstdDecompressor in ResponseStreamWrapper, matching gzip/brotli handling
- Fix empty-body ZSTD output: endImpl() now rejects ZSTD encoding even when
  no write() was called, consistent with the non-empty-body error path
- Replace KJ_ASSERT with KJ_FAIL_REQUIRE in ensureIdentityEncoding() else-
  branches so unknown future RPC encoding values throw catchable errors instead
  of aborting in debug or silently corrupting in release builds

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@StilesCrisis StilesCrisis requested review from a team as code owners June 21, 2026 19:24
@github-actions

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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