Repository navigation
Conversation
Text, manifest and chunk AAD covered only the message or transfer ID, so a relay could rewrite room, sender, recipient, timestamps, item kind or seq, extend expiry, and replay old envelopes once the 120 s in-memory cache expired or the daemon restarted. Envelope v2 (RoutingHeader.version = 2) authenticates a canonical encoding of the full routing header for every frame; chunks are bound to the accepted manifest's header, index and count. Receivers reject envelopes for another room or recipient, from unpinned senders, outside the expiry window (30 s skew), or with a seq not newer than the last accepted v2 seq of that sender. Sender seq and receiver high-water marks persist in the private replay-state.json, so protection survives restarts. Hello stays at protocol version 1 for relay compatibility. Updated receivers accept legacy v1 from a sender until its first v2 envelope and reject it afterwards as a downgrade; sync.legacy_envelopes lets an updated device keep sending v1 to a not-yet-updated peer. Docs now state that the Noise handshake result is unused and sender identity is not bound per device.
|
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. |
| if frame.ciphertext.len() < AEAD_NONCE_LEN { | ||
| return Err(TransferError::Chunk("ciphertext too short")); | ||
| } | ||
| let mut nonce = [0u8; AEAD_NONCE_LEN]; |
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
Text AEAD associated data was only
"{message_id}:text", manifests used"{transfer_id}:manifest", and chunks usedtransfer_id || index. The routing header fieldsroom_id,sender_device_id,recipient,sent_at,expires_at,item_kindandseqwere not authenticated. Receivers never checkedexpires_at. Replay protection was the in-memoryLoopGuardmessage-ID cache: 120 s TTL, empty after every restart.docs/security.mdlists replay as an in-scope threat, and it implied protections that Noise and sender IDs do not provide.Attack scenario
A relay operator records a text envelope (or a manifest and its chunks) and re-sends it more than 120 s later or after the receiving daemon restarts. The receiver decrypts it and overwrites the user's clipboard with stale content. The relay can also extend
expires_ator rewrite sender/recipient/room metadata, and the receiver still accepts the envelope.Resulting behavior
RoutingHeader.version = 2): the AAD is a canonical, length-prefixed encoding of the whole routing header plus a frame tag. It is used for text, manifest and every chunk. Chunks are bound to the accepted manifest's header, index and count. The encoding is specified indocs/protocol.md.sent_at/expires_atwith a namedCLOCK_SKEW_SECS= 30 s, lifetime ≤HARD_MAX_TTL_SECS.seqis stored in the privatereplay-state.json(0600, atomic write). It is committed only after AEAD succeeds, so forged headers cannot raise it. Senderseq = max(last_sent + 1, unix_micros)is persisted before sending, so it stays monotonic across restarts, clock steps back, lost state, and concurrent daemon/one-shot sends.Inboundentry point covers the daemon loop, thehello_okqueued text, andpull. The mobile path uses the same engine.Compatibility impact
hello.protocol_versionstays1; the relay is unchanged and forwards v2 headers as is. The chunk frame layout and its version byte are unchanged.sync.legacy_envelopes = true(new, default false) makes an updated device send v1 to a not-yet-updated peer. Receiving is unaffected.Verification
left: "2" right: "1"), expired/misaddressed envelopes ("4"vs"1"), and a relay-rewritten header accepted ("2"vs"1"). They pass with the fix.sync.legacy_envelopes;cargo +1.100.0 fmt --all -- --check: pass.cargo +1.100.0 clippy --workspace --all-targets --locked -- -D warnings: pass.cargo +1.100.0 test --locked: protocol, transfer, storage, core (62 lib tests), mobile and relay all pass. One relay test,secure_listener::verified_https_keeps_certificate_and_private_key_symlink_support, failed once during the parallel full run; this PR does not touch the relay, and it passed 3/3 reruns.cargo +1.95.0 check --workspace --all-targets --locked: pass.cargo +nightly fuzz build protocolpasses, and a 30 s run found no crashes.scripts/check-source-headers.pyandscripts/check-regressions.pypass.Remaining limitations
replay-state.jsonlimits protection to the expiry window until each sender's next accepted envelope.