Skip to content

Proxy: don't corrupt non-UTF-8 bodies when scrubbing - #1265

Merged
theoephraim merged 1 commit into
mainfrom
fix-proxy-binary-text-response
Nov 2, 2026
Merged

theoephraim merged 1 commit into
mainfrom
fix-proxy-binary-text-response

Conversation

@theoephraim

Copy link
Copy Markdown
Member

Fixes #1263.

Response scrubbing decoded text/* bodies as UTF-8 and re-encoded them, so every invalid byte became U+FFFD. Go's checksum database serves binary tiles as text/plain, so go get through a strict proxy failed with len=226, want 128.

  • Response scrubbing (buffered and streamed) and request-body substitution now work on the raw bytes (latin1 strings, with item values converted to their UTF-8 bytes). Nothing is ever re-encoded.
  • Response headers are left alone when nothing was scrubbed. Previously a HEAD response on a scrubbed route had its content-length rewritten to 0 and lost its etag.
  • 206 partial bodies are no longer rewritten (that would break Content-Range); only their headers are scrubbed.
  • Docs: proxy limitations now mention the 206 skip and that matching is on UTF-8 bytes (works for ASCII secrets in ASCII-compatible charsets, not UTF-16/32).

Response scrubbing decoded text/* bodies as UTF-8 and re-encoded them, so
any invalid byte became U+FFFD (Go checksum tiles served as text/plain came
back corrupted). Bodies are now handled as latin1 byte strings on both the
response and request side. Also keeps headers intact when nothing was
scrubbed (HEAD content-length was rewritten to 0) and never rewrites 206
partial bodies.

Fixes #1263
@github-actions

Copy link
Copy Markdown
Contributor

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • @varlock/native-helper-darwin 1.24.0 → 1.24.1
  • @varlock/native-helper-linux-arm64 1.24.0 → 1.24.1
  • @varlock/native-helper-linux-x64 1.24.0 → 1.24.1
  • @varlock/native-helper-win32-x64 1.24.0 → 1.24.1
  • varlock 1.24.0 → 1.24.1

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Bundle size

⚠️ grows the bundle by 3.0 KB (+0.1%)

Metric main This PR Δ
Total dist 5173.1 KB 5176.1 KB +3.0 KB (+0.1%)
JS 1975.4 KB 1976.4 KB +1.0 KB (+0.1%)
Sourcemaps 3060.5 KB 3062.5 KB +2.0 KB (+0.1%)
Type defs 137.1 KB 137.1 KB —
Other 0.0 KB 0.0 KB —

dist/ only; native binaries are versioned separately and not counted here.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website 86a9029 Commit Preview URL

Branch Preview URL
Oct 30 2026, 10:11 PM

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes: Reviewed the byte-handling changes, response metadata behavior, documentation, and regression coverage; all 127 targeted proxy tests passed after building workspace dependencies.

  • Byte-exact rewriting: Buffered and streamed response scrubbing and request-body substitution match UTF-8 value bytes without corrupting unrelated non-UTF-8 bytes.
  • Response semantics: Unchanged buffered bodies retain their metadata, HEAD responses preserve content-length, and 206 bodies bypass rewriting while headers remain scrubbed.
  • Coverage and limitations: Regression tests cover binary responses, split secrets, Unicode request substitution, HEAD, and partial content; the guide documents byte matching and partial-response passthrough.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

varlock

npm i https://pkg.pr.new/varlock@1265

@varlock/astro-integration

npm i https://pkg.pr.new/@varlock/astro-integration@1265

@varlock/cloudflare-integration

npm i https://pkg.pr.new/@varlock/cloudflare-integration@1265

@varlock/nuxt-integration

npm i https://pkg.pr.new/@varlock/nuxt-integration@1265

@varlock/vite-integration

npm i https://pkg.pr.new/@varlock/vite-integration@1265

@varlock/native-helper-darwin

npm i https://pkg.pr.new/@varlock/native-helper-darwin@1265

@varlock/native-helper-linux-arm64

npm i https://pkg.pr.new/@varlock/native-helper-linux-arm64@1265

@varlock/native-helper-linux-x64

npm i https://pkg.pr.new/@varlock/native-helper-linux-x64@1265

@varlock/native-helper-win32-x64

npm i https://pkg.pr.new/@varlock/native-helper-win32-x64@1265

commit: 86a9029

@theoephraim
theoephraim merged commit 92975ce into main Nov 2, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: proxy corrupts binary response bodies served as text/* (UTF-8 decode)

1 participant