fix(crypto): re-sync rotated public keys + explicit key recovery choice#127
Merged
Conversation
The carrier 'file' message renders (and MessageAttachments fetches /api/files/message/:id) before its files finish uploading, so the initial fetch returns nothing. Because the effect only keyed on [messageId], it never re-fetched and the attachment stayed invisible until a full page refresh remounted the component. Dispatch an 'attachments:updated' CustomEvent after the uploads + loadMessages complete; MessageAttachments listens for its own messageId and bumps a reloadKey to re-fetch and render the now-present files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…rompt Two related cross-device key problems: 1. needsKeySync() only checked whether *any* public key existed in the DB for the user, not whether it matched the local key. After switching browsers / rotating keys, the DB kept the OLD public key, so the sync was skipped and everyone kept encrypting to a dead key the new device can't read. Now it compares the DB key to the local key and re-syncs on mismatch (the server RPC already upserts via ON CONFLICT DO UPDATE). 2. EncryptionWarning now gives an explicit choice when a device has no keys: "Upload existing keys" (recommended — routes to Settings import/restore, preserves history) vs "Generate new keys" (with a confirm that past messages become unreadable). Previously it silently pointed at Settings, which let users end up on fresh keys without understanding the cost. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
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
Messaging a user who switched browsers silently failed (note-to-self worked). Root cause: after a key rotation / new device, the DB kept the user's old public key, so everyone encrypted to a dead key the new device couldn't decrypt.
Fixes
needsKeySync()previously only checked whether any key existed in the DB, not whether it matched the local key — so a rotated key was never uploaded. Now compares DB key vs local key and re-syncs on mismatch. Server RPC already upserts (ON CONFLICT DO UPDATE), and the check self-corrects (no loop, heals legacy 768 keys too).EncryptionWarningnow offers an explicit choice when a device has no keys:confirm()warning that past messages become permanently unreadablePreviously it silently pointed to Settings, letting users land on fresh keys without understanding the cost.
oxlint clean. Note: old messages on a brand-new key still require restoring the old private key — by design (E2EE).
🤖 Generated with Claude Code