Repository navigation
Conversation
📝 WalkthroughWalkthroughThe pairing decoder now rejects Base64URL inputs with invalid padding length or a remainder of one modulo four. Mobile pairing parsing now applies the shared input-size limit to raw codes, URLs, and decoded URLs. Mobile decoding now uses the shared Base64 normalization helper. Tests cover malformed and canonical padding across runtimes. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/pairing.test.ts (1)
38-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the remainder-one branch.
This test covers the invalid padded-length branch at
src/shared/pairing.tsLine 88. It does not directly exercise the new unpadded length check atsrc/shared/pairing.tsLine 87. Add a valid payload with an unpadded length divisible by four, append one Base64 character, and assert thatparsePairingCodereturnsnull.Suggested boundary test
+ it('rejects unpadded Base64URL with length remainder one', () => { + const alignedOffer: PairingOffer = { ...offer, scope: 'mobile' } + const alignedUrl = encodePairingOffer(alignedOffer) + const alignedCode = new URLSearchParams( + alignedUrl.slice(alignedUrl.indexOf('?') + 1) + ).get('code')! + expect(alignedCode.length % 4).toBe(0) + expect(parsePairingCode(`${alignedCode}A`)).toBeNull() + })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8682d3d0-6ecf-49bc-ba53-dc20f28b0880
📥 Commits
Reviewing files that changed from the base of the PR and between 8fc892d and ce33961a6dfd61d74971e23ab7442d557d1393c4.
📒 Files selected for processing (2)
src/shared/pairing.test.tssrc/shared/pairing.ts
Greptile SummaryThis PR fixes a Node/browser split in base64 padding validation: Node's
Confidence Score: 4/5Safe to merge; the production change is a targeted two-line guard that makes validation stricter and consistent across runtimes, with no API surface changes. The two new guards in decodePairingBase64 are logically correct and close a real cross-runtime inconsistency. The only concern is in the tests: both new cases implicitly depend on the specific offer fixture producing a base64url code whose length mod 4 equals 2, without asserting that invariant. If the offer structure changes, both tests could fail with misleading messages, or the malformed-padding test could silently assert valid input should be rejected. Files Needing Attention: src/shared/pairing.test.ts — the two new tests rely on an unstated length-modulo property of the offer fixture.
|
| Filename | Overview |
|---|---|
| src/shared/pairing.ts | Adds two structurally sound pre-validation guards to decodePairingBase64: rejects length % 4 == 1 (impossible in any valid base64) and rejects padded inputs (contains '=') whose total length isn't divisible by 4. Both conditions are checked before the existing regex, consistently closing the Node-permissive/browser-strict gap. |
| src/shared/pairing.test.ts | Adds a cross-runtime malformed-padding regression and a canonical-padding acceptance test. Both tests silently depend on the specific offer fixture serializing to a JSON length whose mod-3 remainder is 1, producing code.length % 4 == 2; this invariant is not explicitly asserted, making future offer-structure changes potentially produce misleading test failures. |
Reviews (1): Last reviewed commit: "fix(pairing): reject malformed base64 pa..." | Re-trigger Greptile
| it('rejects malformed padding consistently across Node and browser runtimes', () => { | ||
| const url = encodePairingOffer(offer) | ||
| const code = new URLSearchParams(url.slice(url.indexOf('?') + 1)).get('code')! | ||
| const malformedCode = `${code}=` | ||
| const nodeDecoded = parsePairingCode(malformedCode) | ||
| const nodeBuffer = Buffer | ||
| let browserDecoded: PairingOffer | null = null | ||
| try { | ||
| vi.stubGlobal('Buffer', undefined) | ||
| browserDecoded = parsePairingCode(malformedCode) | ||
| } finally { | ||
| vi.stubGlobal('Buffer', nodeBuffer) | ||
| } | ||
|
|
||
| expect({ nodeDecoded, browserDecoded }).toEqual({ | ||
| nodeDecoded: null, | ||
| browserDecoded: null | ||
| }) | ||
| }) | ||
|
|
||
| it('accepts canonical base64 padding', () => { | ||
| const url = encodePairingOffer(offer) | ||
| const code = new URLSearchParams(url.slice(url.indexOf('?') + 1)).get('code')! | ||
|
|
||
| expect(parsePairingCode(`${code}==`)).toEqual(offer) | ||
| }) |
There was a problem hiding this comment.
Both new tests rely on an unasserted offer length property
Both tests work correctly for the current offer fixture (whose JSON serializes to 169 bytes, producing a base64url code of length 226, so code.length % 4 == 2). However, neither test asserts or documents this dependency:
- In
rejects malformed padding:code + "="is only malformed whencode.length % 4 ∈ {0, 2}. Whencode.length % 4 == 3, appending=produces valid canonical padded base64 —parsePairingCodewould return the offer, notnull, and the assertion would fail for the wrong reason. - In
accepts canonical base64 padding:code + "=="only haslength % 4 == 0(and therefore passes the new guard) whencode.length % 4 == 2. Any other remainder causes the new padding guard to reject it, making the test fail regardless of whether the production code is correct.
If the offer gains a new required field or the PairingOfferSchema changes the serialization, both tests could produce confusing failures. Adding a short assertion like expect(code.length % 4).toBe(2) with a clarifying comment would pin the implicit invariant and make future failures self-explanatory.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
ce33961 to
2b17595
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/transport/pairing.test.ts (1)
67-77: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the oversized URL through
parsePairingCode.
parsePairingCodehas its own early length check inmobile/src/transport/pairing.tsLines 61-63. This test covers that check only withoversizedRawCode. Add the URL assertion to protect the public entry point.Proposed assertion
expect(parsePairingCode(oversizedRawCode)).toBeNull() + expect(parsePairingCode(oversizedUrl)).toBeNull() expect(extractPairingCodeFromUrl(oversizedUrl)).toBeNull()
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bc9a66d0-6402-461f-9b45-65077b1e779c
📥 Commits
Reviewing files that changed from the base of the PR and between ce33961a6dfd61d74971e23ab7442d557d1393c4 and 2b17595.
📒 Files selected for processing (2)
mobile/src/transport/pairing.test.tsmobile/src/transport/pairing.ts
|
I am working through this pairing inconsistency as part of mobile bug batch 3. I will review and adapt this contribution with co-author credit, exercise the desktop/mobile decoders and pairing UI, and link the follow-up PR here. |
|
Follow-up implementation: #31465. Adapted and credited Henry Su and OrcaWin in the commit. Regression tests reproduce the decoder mismatch; 55 desktop/web/normalizer and 11 mobile tests pass, and real simslim iOS WKWebView before/after screenshots are attached with the fixture limitations described. |
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]>
Normalize bounded Base64 input consistently across desktop, browser, and mobile pairing paths while preserving lossless legacy padding and trailing-bit spellings. Retain offer validation and authentication behavior. Adapted from #12027. Compatibility verified across 378 spellings with no previously accepted inputs lost; full PR workflow and aggregate gate passed for a84dfae. Co-authored-by: Henry Su <[email protected]> Co-authored-by: OrcaWin <[email protected]>
|
Superseded by merged #31465. Thank you @hsusul and @OrcaWin for the original pairing normalization/input-bounds work; both contributors are credited in the replacement and its squash commit. The merged normalizer preserves lossless historical padding and trailing-bit spellings, with 378 before/after compatibility cases across desktop, browser, mobile, and web parser paths and no previously accepted input lost in that matrix. |
Summary
Problem
Orca's shared pairing parser accepted malformed Base64 padding in Node while rejecting the same pairing code in browser runtimes. A code formed by adding a single
=to an unpadded payload that requires==was decoded by Node's permissiveBuffer.from(..., 'base64'), whileatobrejected it.Before this fix, the regression test observed a decoded pairing offer from the Node path and
nullfrom the browser path for the identical malformed code.Root cause
decodePairingBase64validated the character set and allowed up to two trailing padding characters, but did not validate Base64 length and padding structure before dispatching to the runtime-specific decoder.Solution
Reject:
Canonical padded and existing unpadded pairing codes remain accepted.
Screenshots
Not applicable; this is shared pairing-code validation with no visual change.
Testing checklist
Bufferand browseratobpaths with the same malformed input.null.==padding remains accepted.pnpm exec vitest run --config config/vitest.config.ts src/shared/pairing.test.ts— 1 file, 20 tests passed.pnpm run typecheck— passed for node, CLI, and web projects.pnpm run lint— passed, including native, type-aware, reliability, max-lines, skill-manifest, and localization checks.pnpm run build— passed, including desktop and macOS native targets. The build reported the existing non-fatal/usr/local/bin/orca-devpermission warning.pnpm test— 4,052 files and 43,141 tests passed; 13 files and 81 tests skipped. One unrelated root-directory guard fixture file had 3 failures because macOS system Bash 3.2 does not support itsdeclare -Aassociative array, causing the script to exit 2 before its assertions.git diff --check upstream/main...HEAD— passed.Compatibility and non-goals
The change is platform-neutral and makes shared parsing consistent across Node and browser runtimes. It does not alter pairing payloads, public APIs, authentication flows, shell invocation, filesystem paths, SSH/folder workspaces, Git behavior, providers, or IPC.
AI Review Report
Reviewed every changed line against
upstream/main. The diff is limited to shared pairing validation and focused tests. Existing unpadded behavior and canonical padding are covered alongside the malformed-padding regression.Security Audit
No new input source, command execution, interpolation, authentication flow, secret handling, IPC surface, or dependency is introduced. The parser now rejects malformed credential-bearing pairing payloads before runtime-specific decoding, eliminating a Node/browser validation discrepancy.
Notes
parsePairingCode, invalid pairing codes, and Node/browser decoder parity found no same-root-cause report.