fix(crypto,cache,search): safety-number session invalidation, out-of-…#396
Open
devchant wants to merge 1 commit into
Open
fix(crypto,cache,search): safety-number session invalidation, out-of-…#396devchant wants to merge 1 commit into
devchant wants to merge 1 commit into
Conversation
…order Double Ratchet, encrypted IDB cache, real search decryption (codebestia#359, codebestia#360, codebestia#357, codebestia#358)
|
@devchant Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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 Description
This PR addresses four related security and cryptographic issues across the web client:
lib/search/db.ts) stored full decrypted message objects as raw plaintext in IndexedDB, while a competing module (lib/messageCache.ts) was unused.decryptMessageText(), an explicit stub returning ciphertext verbatim, causing raw ciphertext or undecryptable messages to leak into the index.Implemented Solution
1. Safety-Number UI & Active Session Invalidation (#359)
apps/web/src/app/app/conversations/[id]/page.tsxhandleKeyChange()handler for key-change events (key_set_changed,key_changed,contact_key_changed,safety_number_changed,system_event) to invokeclearSessionKeys()andsessionStore.clear().apps/web/src/lib/crypto/sessionStore.ts.2. Double Ratchet Out-of-Order Delivery & Bounded Skipped Keys (#360)
apps/web/src/lib/crypto/doubleRatchet.tsimplementing Signal Double Ratchet with symmetric and Diffie-Hellman ratcheting steps.MKSKIPPEDstore keyed by(DHr, N)for out-of-order message decryption.MAX_SKIPPED_KEYS = 1000andMAX_SKIP = 100, purging the oldest skipped keys when capacity is reached.3. Encrypted-at-Rest Local IndexedDB Cache (#357)
apps/web/src/lib/cryptoStore.tsto persist private key JWK material and addedgetIdentityPrivateKeyJwk().apps/web/src/lib/search/db.tsto encrypt message content with AES-256-GCM using a PBKDF2 key derived (100,000 iterations, SHA-256) from non-public private key material before writing to IndexedDB.apps/web/src/lib/messageCache.ts.4. Real Search Index Decryption Pipeline (#358)
apps/web/src/lib/crypto/messageCrypto.tsdecryptMessageText()to invoke the real envelope decryption pipeline (decryptAndVerifyEnvelope()).nullwhen decryption fails so undecryptable messages are excluded from search indexing instead of indexing raw ciphertext noise.useMessageSearchIndexhook to handle decryption parameters and filter outplaintext === nullmessages.Files and Components Changed
apps/web/src/app/app/conversations/[id]/page.tsxapps/web/src/lib/crypto/sessionStore.tsapps/web/src/lib/crypto/doubleRatchet.tsapps/web/src/lib/cryptoStore.tsapps/web/src/lib/search/db.tsapps/web/src/lib/messageCache.ts(Deleted)apps/web/src/lib/crypto/messageCrypto.tsapps/web/src/hooks/useMessageSearchIndex.tsdoubleRatchet.test.ts,db.test.ts,searchIntegration.test.ts,safetyNumber.test.ts,ProposalCard.test.tsxTechnical Decisions Made
MKSKIPPEDexceedsMAX_SKIPPED_KEYS = 1000to bound memory consumption.Validation Performed
npx vitest run— 16/16 tests passed across 5 test suites.npx tsc --noEmit— 0 errors.npm run build— Next.js production build succeeded.Closes #359
Closes #360
Closes #357
Closes #358