Repository navigation
Conversation
Derive a 6-digit short authentication string from the SPAKE2 secret and transcript (HKDF label clipsync/v1/sas). Send DeviceBind and persist room keys, room record, and credentials only after the local user confirms that both devices show the same code; rejection or timeout stores nothing. Add CLI prompts, room confirm/reject for background create, and --insecure-skip-sas; a desktop verification panel; and a mobile SasVerifier callback API while keeping the existing exports. No wire or relay change.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The relay generates the 6-digit pairing code. It returns the code in the create response and receives it in the join request, and the same code is the SPAKE2 password. Neither device compared anything out of band, so:
Attack scenario
The relay creates the room and learns the code. When the joiner connects, the relay answers each device's SPAKE2 message with its own and completes
key_confirmon both sockets. It decrypts bothdevice_bindmessages, re-encrypts them under the other session's key, and sendspairing_complete. Each device stores room keys that the relay also knows, so the relay can read and re-encrypt all later sync traffic. A code guesser gets the same result as the creator's peer, without any relay compromise.Resulting behavior
clipsync-cryptoderivessas_key = HKDF-SHA-256(SPAKE2 secret, salt = transcript hash, info = "clipsync/v1/sas"). It renders the key as 6 decimal digits:u64be(sas_key[0..8]) mod 10^6. Length and sampling are named constants. Two devices show the same code only when they ran SPAKE2 with each other.run_pairingcalls a caller-supplied confirmation after it verifies the peer'skey_confirm. The confirmation receives aSasCheckwith the code, the peer device ID, and the relay-reported peer name. The device sendsdevice_bindonly afterSasDecision::Confirmed. Room keys, the room record, the device token, and the sync config are written only after ourdevice_bindwent out and the peer'sdevice_bindandpairing_completearrived. Previously room keys were saved right after our owndevice_bind. A rejection sendserror{code: "sas_rejected"}, which makes the relay drop the session, and returns an error. A timeout or a dropped prompt also stores nothing.PendingCreate::wait,create_room,join_room,App::room_create, andApp::room_joinnow take the confirmation, so every caller must decide explicitly.room joinandroom create --foregroundprint the code and the other device's name, then read one line.y/yes, or the code shown on the other device, confirms. Anything else, or end of input, rejects. The default backgroundroom createpublishes the code in the existing pairing file (statusconfirm_sas). The worker then waits forclipsync room confirm [CODE]orclipsync room reject.--insecure-skip-sasis the explicit opt-out for scripts and is documented as removing the protection.--non-interactivefails closed at the prompt.SasVerifiercallback interface pluscreate_room_verifiedandjoin_room_verified. The existingcreate_room()andjoin_room()keep working unchanged: they accept without comparing, log a warning, and are documented as unverified.docs/security.mdgains a "Verification code (SAS)" section covering what it protects against, the limit below, older peers, and the opt-outs.docs/protocol.mdgains the derivation and commit order.docs/interfaces.md,docs/mobile.md,docs/assurance-case.md, and the README pairing section are updated.Compatibility impact
sas_rejecteduses the existingerrorframe.device_bindis buffered until the local user confirms. The older device shows no code, so the comparison cannot be made; the docs say to treat such a pairing as unverified.PairingWaitgains optionalsas,peer_device_name, andsas_decisionfields (serde default, skipped when empty). Old files still load.PairingKeysgained asas_keyfield. All in-workspace callers are updated.Verification
hmac/hashlib.device_bindand nothing stored while the prompt is open.pairing_completearrives early.sas_rejectedand neverdevice_bind, with no room or*.secretfiles.room confirm <code>flow.room confirmandroom rejectstore nothing on either device.--insecure-skip-sasend to end.Local results (macOS):
Test totals: crypto 27, storage 25, core 62, relay 74, cli 14, desktop 18, mobile 8, all passing. The foreground CLI pairing test was also run once with
CLIPSYNC_TEST_DISPOSABLE_HOST=1and passed. A rare race in the rejection path, where a late peer frame could drop the queuedsas_rejectedframe before it was flushed, was fixed: a bounded drain after close. The rejection tests then passed 8 times in a row.Remaining limitations
docs/security.mdstates this plainly and still recommends a trusted relay.create_room()andjoin_room()remain unverified for compatibility until apps move to the*_verifiedcalls.