Repository navigation
fix(crypto): send a proof, never the key, for recovery and family claims - #256
Merged
Merged
Conversation
Merged
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
Two requests sent the server the raw key that unlocks a copy of the master key the server already stores:
/api/recoverreceivedrecovery_key, the AES key ofusers.recovery_vault./api/family/grants/claimreceivedfamily_keyasproof, the AES key offamily_grants.wrapped_master.Anyone able to read those request bodies on the server side (a compromised server, the TLS-terminating proxy, request logging) could unwrap that account's master key at the moment of a recovery or claim. Login was never affected; it already sends a separately derived key.
Fix
proof = SHA-256(key). At creation it sendsverifier = SHA-256(proof), which is what the server stores. The keys never leave the browser:crypto.tsno longer returns them from any exported function.recovery_proof,grant_proof,recovery_verifier,grant_verifier.users.recovery_verifierandfamily_grants.grant_verifier. It converts each existing value (SHA-256(key) becomes SHA-256(SHA-256(key))) and clears the old column. Keeping the old value would make a database leak a working credential, because it equals the new proof.proof,grant_proof,recovery_proofandgrant_auth; the claim endpoint now redacts too.Rollback
The migration is marked compatible, so an older image still boots on schema 10. Its recovery and family claims fail with a 401, not a 500, until the roll-forward. Everything else works.
Residual
Database backups taken before this deploy hold the old SHA-256(key) values, which are now valid proofs. With one, someone could reset an account's password (the account stays recoverable with its code) or claim an invitation (ciphertext only, since the family key is still needed to decrypt). No plaintext is exposed. Treat pre-deploy backups as sensitive and let them age out.
Testing
test_proof_not_key.pycovers proof/verifier checks, legacy acceptance, confusion cases (raw key in the proof field, verifier as proof, both fields present, JSON null), verifier storage on register and grant creation, and the migration. A real-Postgres test checks that the SQL conversion matches the Python hashing and is a no-op on replay. The existing tests were moved to the new fields.crypto.proof.test.tsruns the real recovery and family flows with a deterministic KDF stand-in: nothing returned or sent equals a derived key, and the request layer has no field for a raw key. All 6 tests fail on the old code. svelte-check 0/0. Build OK.origin/main(schema 9) was upgraded by this branch: 13 checks passed through the real endpoints. Recovery with a proof gives 200, an old client sending the raw key gives 200, a raw key in the proof field gives 401, and a family claim gives 401 with the key and 200 with the proof./healthwill reportschema: 10.