Skip to content

fix(pairing): normalize base64 consistently across clients - #31465

Merged
nwparker merged 2 commits into
mainfrom
nwparker/mobile-strict-pairing
Oct 21, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/mobile-strict-pairing

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​172 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​171
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21

Problem and behavior

Pairing codes could decode successfully on desktop but fail on another client because padding was handled differently. Use one bounded Base64 normalizer across desktop, mobile and web so a saved code yields the same offer everywhere.

Preserve standard/Base64URL, padded/unpadded, partially or redundantly padded codes, and nonzero unused trailing bits accepted by older clients. Remove trailing padding and restore the required amount before decoding. These spellings produce the same JSON, device token and public key; offer validation and authentication remain unchanged. Reject invalid alphabet/interior padding, impossible data lengths, and oversized input before decoding or URL parsing.

Compatibility verification

The earlier version rejected lossless historical aliases. That was an unnecessary compatibility change and has been removed. Current and historical Orca producers emit canonical unpadded Base64URL, but saved/manual spellings also deserve compatibility.

Compared production parsers before this PR with the revised parsers: 378 spellings covering all three payload byte remainders, trailing-bit aliases, 0–2 padding characters, both alphabets, and bare/query/hash forms. All four revised decoder paths return the identical offer for all 378 inputs. Every input accepted by any baseline decoder remains accepted with the same offer; no compatibility losses in this matrix. The shared browser path was exercised with Buffer absent.

69 focused desktop/browser/normalizer/mobile tests pass. Changed-code quality passes. Existing generated-offer and TLS proxy endpoint round trips remain covered. This is decoder compatibility verification; it does not claim a live pairing/authentication network session. The old simulator screenshots demonstrated the superseded strict rejection policy and have been removed from this description.

Credit

Original padding-parity work: #12027, Henry Su (@hsusul). Cross-client normalization/input bounds: OrcaWin. Both contributor trailers remain in the branch history and must be retained at squash merge.

Risk

Low. Full PR checks and the aggregate gate passed on the merged head. No protocol/schema/credential migration or host-version change. Compatibility is preserved for lossless legacy spellings; size limits and existing schema checks remain. Merged in 82512a4 with both contributor trailers verified; superseded #12027 is closed.

Adapt the community decoder normalization and input bounds from #12027 for current desktop, browser and mobile pairing paths.

Co-authored-by: Henry Su <[email protected]>
Co-authored-by: OrcaWin <[email protected]>
@nwparker
nwparker force-pushed the nwparker/mobile-strict-pairing branch from 412c525 to a14fe36 Compare October 21, 2026 08:27
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e44b30be-9d73-4003-9f4d-18152b7404f1
📥 Commits

Reviewing files that changed from the base of the PR and between a14fe36 and a84dfae.

📒 Files selected for processing: 5
  • mobile/src/transport/pairing.test.ts
  • src/renderer/src/web/web-pairing.test.ts
  • src/shared/mobile-pairing-base64.test.ts
  • src/shared/mobile-pairing-base64.ts
  • src/shared/pairing.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📝 Walkthrough

Pairing-code decoding now uses shared Base64URL normalization that validates padding, allowed characters, and canonical trailing bits. Shared, mobile, and web pairing paths reject inputs that exceed the configured character limit. Tests cover oversized input and canonical versus malformed Base64URL values.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to a84df

The reviewed pairing-code changes have no established merge-blocking risk. Normal build and test checks remain appropriate before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the problem, behavior changes, compatibility scope, testing results, risk, and contributor credit. However, it omits most required template sections, including ELI5, What Chan… Complete the required template sections. Add an actual linked issue in the Linked Issue section, provide Visual Proof or state N/A with a reason, document testing and platform coverage, complete applicable checkboxes, and include the requir…
Docstring Coverage Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: consistent Base64 normalization across pairing clients.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, behavior changes, compatibility scope, testing results, risk, and contributor credit. However, it omits most required template sections, including ELI5, What Changed, Why, an actual Linked Issue entry, Visual Proof or N/A, Testing checkboxes, AI Disclosure, Review, the upstream boundary section, Notes, and the Checklist.

Resolution

Complete the required template sections. Add an actual linked issue in the Linked Issue section, provide Visual Proof or state N/A with a reason, document testing and platform coverage, complete applicable checkboxes, and include the required security, cross-platform, SSH, mobile, compatibility, and build-validation notes.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@BichengWang BichengWang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed a14fe362751472088f25bf173cdd84c918b317f9, including all eight changed files and the desktop, web, and mobile decoder call sites. No blocking findings in the Base64 validation change.

I independently reproduced acceptance of incomplete padding and nonzero trailing-bit aliases on main (5dd5294294), then verified that this head rejects both across all three parsers while preserving canonical padded and unpadded offers. The four changed test suites passed: 66 tests. I also checked every one-, two-, and three-character input over the 64-character alphabet in both standard and URL-safe spellings (532,608 cases) against canonical re-encoding, plus longer payload round trips; the normalizer matched throughout. The trailing-bit positions cover both one-byte and two-byte tails, and the input guards run before trimming or URL parsing.

The shared normalizer has no Node-only imports, keeps the offer schema and wire version unchanged, and bounds input before replacement/allocation, so I found no added platform, mixed-version remote, or unbounded-input risk in this diff. Validation ran on macOS with Node 26 and Bun, using an isolated Vitest config and the existing installed dependencies: the normal root configuration was blocked by a missing @orca/process-host package build, and the mobile configuration by missing Expo dependencies. These are parser checks; I did not run an iOS/Android app, Metro bundle, full build, full typecheck, or end-to-end network pairing.

@nwparker nwparker changed the title fix(pairing): validate base64 consistently across clients fix(pairing): normalize base64 consistently across clients Oct 21, 2026
@nwparker
nwparker merged commit 82512a4 into main Oct 21, 2026
47 checks passed
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