Skip to content

fix(router): don't crash dev response when X-Void-Routing trace is non-ASCII - #226

Merged
Brooooooklyn merged 2 commits into
mainfrom
fix/dev-routing-trace-non-ascii
Jun 30, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
fix/dev-routing-trace-non-ascii

Conversation

@hyfdev

@hyfdev hyfdev commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

A dev request through a rewrite/redirect whose path contains a non-ASCII character (e.g. a CJK route) no longer crashes with a 500 — the dev-only routing trace header now degrades gracefully.

The bug

In dev mode, __voidAnnotateRouting (the generated helper that adds the X-Void-Routing trace header for rewrite / redirect / c.rewrite responses) builds the header value by interpolating the matched rule's user-supplied source/dest (e.g. "rewrite[" + source + "] -> " + dest + " (...)"). If the path contains a character > U+00FF (CJK, etc.), that value fails the header ByteString conversion, so the unguarded headers.set("X-Void-Routing", trace) throws and crashes the response with a 500.

Expected-correct behavior

The dev trace header is a debugging convenience — it must never crash the actual response. The sibling pass-through trace set is already wrapped in try { … } catch {} for exactly this reason (with a test + comment: "silently swallow … instead of crashing, matching the existing pattern elsewhere"), but __voidAnnotateRouting was missed.

The fix

Wrap the __voidAnnotateRouting set in try { headers.set("X-Void-Routing", trace); } catch { return response; } — on throw, silently drop the trace header and return the response intact, matching the pass-through guard. (Production is unaffected: the whole helper is a no-op when __VOID_DEV_ROUTING is false.)

This completes commit b3b73842 ("Use ASCII characters in headers only"), which ASCII-fixed only the framework's own → arrow in the trace, not the user-supplied source/dest — and is the residual of the non-ASCII-header crash reported in void-sdk/void#54.

Tests

Added a codegen assertion in compile.test.ts (same style as the existing pass-through-guard test) that the emitted __voidAnnotateRouting wraps its set in the try/catch — failing on origin/main and passing after. (Confirmed independently that Headers.set throws on a > U+00FF value, and that the rule source/dest reach the trace unencoded.) Local gate: compile.test.ts 122/122; full --project unit zero-collateral; typecheck + lint + fmt clean.

Prepared with AI assistance.

@netlify

netlify Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for staging-void-cloud failed.

Name Link
🔨 Latest commit e42a5af
🔍 Latest deploy log https://app.netlify.com/projects/staging-void-cloud/deploys/6a341789d7bc6c000839fff4

@hyfdev
hyfdev marked this pull request as ready for review June 18, 2026 15:50
…n-ASCII

The dev-only X-Void-Routing trace header set by __voidAnnotateRouting
(rewrite / redirect / c.rewrite paths) interpolates the user's rule
source/dest into the value. A non-ASCII path (e.g. a CJK or other >U+00FF
char) makes that value fail the header ByteString conversion, so the
unguarded headers.set threw and crashed the dev response with a 500.

The sibling pass-through trace set is already wrapped in try/catch for
exactly this reason; apply the same guard to __voidAnnotateRouting so a
non-ASCII trace is silently dropped and the response is returned intact.
(Completes commit b3b7384, which only ASCII-fixed the framework's own
arrow, and the residual of void-sdk/void#54.)
@hyfdev
hyfdev force-pushed the fix/dev-routing-trace-non-ascii branch from 41187a7 to e42a5af Compare June 18, 2026 16:06
@Brooooooklyn
Brooooooklyn merged commit 78c7de5 into main Jun 30, 2026
6 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/dev-routing-trace-non-ascii branch June 30, 2026 01:28
@cpojer

cpojer commented Jul 8, 2026

Copy link
Copy Markdown
Member

This was already fixed on main, and this is the wrong fix.

b3b7384

cpojer added a commit that referenced this pull request Jul 8, 2026
…ce is non-ASCII" (#266)

Reverts #226

This was already fixed on main, and a try-catch does not fix the issue
correctly.
cpojer pushed a commit that referenced this pull request Sep 11, 2026
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

3 participants