Skip to content

fix: base64-encode x-partykit-props header for ASCII safety#407

Merged
threepointone merged 1 commit into
mainfrom
fix/ascii-safe-props-header
Jun 14, 2026
Merged

fix: base64-encode x-partykit-props header for ASCII safety#407
threepointone merged 1 commit into
mainfrom
fix/ascii-safe-props-header

Conversation

@threepointone

Copy link
Copy Markdown
Collaborator

Summary

Props passed to getServerByName / routePartykitRequest (and, transitively, the Agents SDK's getAgentByName / routeAgentRequest) are serialized into the x-partykit-props request header. The header value was set via JSON.stringify(props) directly, so any non-ASCII characters in props (e.g. accented names like "Usuário", CJK text, emoji) produced a non-ASCII header value. workerd tolerates this as a UTF-8 quirk but emits a warning, and the same call throws a TypeError in browser fetch implementations.

This encodes the header as UTF-8 → base64 when writing and decodes it back on the server, so the header value is always ASCII while the original Unicode payload round-trips intact.

  • encodeProps — UTF-8 encode the JSON, then base64.
  • decodeProps — base64-decode back to the original Unicode. For backwards compatibility with stubs/requests created by older versions, it detects raw-JSON values (a leading {/[, which base64 can never produce) and parses them directly.

Fixes cloudflare/agents#1751.

Test plan

  • Added a regression test: a /unicode-props-parties/ route delivers { secret: "Usuário 日本語 🎉" }; PropsServer echoes back the raw x-partykit-props header. The test asserts props round-trip and that the header value the DO receives is ASCII-only (/^[\x00-\x7f]*$/). It fails on the old JSON.stringify behavior and passes with the fix.
  • Full partyserver suite passes (87/87).
  • npm run check:lint and npm run check:type clean; npm run format applied.
  • Added a patch changeset.

Made with Cursor

Props containing non-ASCII characters (e.g. accented names like
"Usuário") were written into the x-partykit-props header verbatim,
triggering workerd's "header value contains non-ASCII characters"
warning and a TypeError in browser fetch implementations.

Encode the header as UTF-8 base64 when writing and decode it on the
server. Raw-JSON values from older callers are still accepted for
backwards compatibility (base64 never starts with { or [).

Fixes cloudflare/agents#1751

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jun 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4359968

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

This PR includes changesets to release 1 package
Name Type
partyserver Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

hono-party

npm i https://pkg.pr.new/cloudflare/partykit/hono-party@407

partyfn

npm i https://pkg.pr.new/cloudflare/partykit/partyfn@407

partyserver

npm i https://pkg.pr.new/cloudflare/partykit/partyserver@407

partysocket

npm i https://pkg.pr.new/cloudflare/partykit/partysocket@407

partysub

npm i https://pkg.pr.new/cloudflare/partykit/partysub@407

partysync

npm i https://pkg.pr.new/cloudflare/partykit/partysync@407

partytracks

npm i https://pkg.pr.new/cloudflare/partykit/partytracks@407

partywhen

npm i https://pkg.pr.new/cloudflare/partykit/partywhen@407

y-partyserver

npm i https://pkg.pr.new/cloudflare/partykit/y-partyserver@407

commit: 4359968

@threepointone threepointone merged commit 2be6104 into main Jun 14, 2026
6 checks passed
@threepointone threepointone deleted the fix/ascii-safe-props-header branch June 14, 2026 00:16
@github-actions github-actions Bot mentioned this pull request Jun 14, 2026
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.

A header value for "x-partykit-props" contains non-ASCII characters

1 participant