Repository navigation
fix(runtime): base64url-encode the forwarded identity header (non-Latin-1 claims break every RPC) - #262
Conversation
HTTP header values are WebIDL ByteStrings, but the worker forwarded verified caller identity to the shard as raw x-lunora-userid / x-lunora-identity (raw JSON.stringify(claims)) header values. Any non-Latin-1 code unit in a claim or userId — a CJK/Cyrillic/Arabic name, an emoji, an IDN — made new Request(...) throw before the shard was ever reached, turning into an opaque INTERNAL 500 for every RPC/batch/fan-out/REST/dispatch call for that user. Latin-1-only text (incl. accented Latin letters) survived unencoded, which is why local testing with ASCII-ish names missed this. Add shared/identity-header.ts: encodeIdentityHeader/encodeUserIdHeader UTF-8-encode then base64url-encode so the header value is always ASCII; decodeIdentityHeader/decodeUserIdHeader invert this, sniffing a legacy unencoded value so an old producer and a new consumer (or vice versa) both keep working during rollout. Every decode fails soft to undefined on malformed input, matching the prior parseIdentityHeader posture. Switch every producer (createWorker's resolveForwardContext, cross-shard-relations' fan-out headers, the dispatch runner, and createShardClient's .as() identity — the last found via a repo-wide grep once the first three were fixed) to the codec, and every consumer (ShardDO's request/WS-upgrade identity capture via parseIdentityHeader, the voice DO's parseIdentity) to decode it back. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 31 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (11)
📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thank you for following the naming conventions! 🙏 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Merging this PR will degrade performance by 17.53%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | + resolveIdentity (userId + claims → x-lunora-identity) |
1.6 ms | 2 ms | -17.53% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing advisor/213-identity-header-encoding (f3ed90a) with alpha (a540991)2
Footnotes
-
10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
alpha(d9791ea) during the generation of this report, so a540991 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Move toBase64Url/fromBase64Url from shared/identity-header.ts into shared/base64.ts alongside their standard-base64 siblings, and export identity-header's isByteStringSafe instead of leaving it private - three test files were re-implementing it inline, one with a subtly different (codePointAt-in-a-length-indexed-loop) iteration than the real charCodeAt version. Also documents the deploy-ordering constraint on decodeUserIdHeader's `=` sentinel for mixed-rollout safety. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The worker forwards verified identity to the shard as HTTP headers (
x-lunora-userid,x-lunora-identity= rawJSON.stringify(claims)). HTTP header values are WebIDL ByteStrings — workerd/undici throw TypeError for any code unit > 255 — so aresolveIdentityreturning any claim with a non-Latin-1 char (a CJK/Cyrillic/Arabic name, an emoji, an IDN) makesnew Request(...)throw before the shard is reached, becoming an opaque INTERNAL 500 for every RPC/batch/fan-out/REST/dispatch for that user (Latin-1 accents survive, which is why local testing misses it).Adds a zero-dep
shared/identity-header.ts(UTF-8 → base64url, with a sniffing decoder for order-independent rollout) and routes all four producer sites (create-worker, cross-shard-relations, dispatch-runner, and shard-client's.as()path — the last two found via repo-wide grep, not in the original inventory) plus every consumer (parseIdentityHeader, voice-turn's parseIdentity, and the raw userId reads in shard-do/voice-do) through it. Legacy raw-JSON headers still decode during a mixed-version deploy.Verified: runtime 814, dispatch 23, do 503, agent 288; a real createWorker→ShardDO integration test with CJK/emoji claims + a non-Latin-1 userId (reproduces the ByteString TypeError pre-fix).
⚠ Touches runtime/create-worker.ts + do/shard-do.ts — merge-order vs #248 (226 create-worker), #243 (206-207 shard-do).
🤖 Generated with Claude Code