Repository navigation
feat(e2ee): recover a v1 account from its v1 recovery phrase - #1608
raivieiraadriano92 wants to merge 6 commits into
Conversation
Semgrep Security ScanNo security issues found. |
PR Metrics
Lighthouse runs without a signed-in session. SSO redirects may lead to the identity provider; these scores do not measure authenticated chat. Use the performance harness for signed-in chat and interaction measurements. Updated Thu, 19 Nov 2026 20:53:48 GMT · run #4414 |
[Critical impact] The PR changes how a pending device can gain access to an existing scheme-1 encrypted account. The PR should not merge until recovery works for a fresh device on an account at its device limit. Findings
Fix with agent prompt### Issue 1
backend/src/api/encryption.ts:1537-1540
Checking the limit after demoting siblings does not let a fresh device reach this route. `continueIntro` first calls `registerThisDevice`, and `POST /devices` rejects a new device with 422 when the account is full. The wizard therefore stops before phrase entry. Someone who lost all trusted devices remains locked out despite having the correct phrase and inbox access.
Allow a fresh device to enter recovery without granting trust above the limit, and test the flow starting before registration. The added limit test already has a pending caller, so it misses this failure.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds recovery for older encrypted accounts using their original recovery phrase and an emailed code.
|
| if (recoveringWithPhrase) { | ||
| const activeCount = await countActiveDevices(txDb, userId) | ||
| if (activeCount >= maxActiveDevicesPerUser) { | ||
| throw new ForbiddenError('Device limit reached — revoke an existing device first') |
There was a problem hiding this comment.
Recovery fails at device limit. Checking the limit after demoting siblings does not let a fresh device reach this route.
continueIntro first calls registerThisDevice, and POST /devices rejects a new device with 422 when the account is full. The wizard therefore stops before phrase entry. Someone who lost all trusted devices remains locked out despite having the correct phrase and inbox access.
Allow a fresh device to enter recovery without granting trust above the limit, and test the flow starting before registration. The added limit test already has a pending caller, so it misses this failure.
Prompt To Fix With AI
This is a comment left during a code review.
Path: backend/src/api/encryption.ts
Line: 1531-1534
Comment:
**Recovery fails at device limit.** Checking the limit after demoting siblings does not let a fresh device reach this route. `continueIntro` first calls `registerThisDevice`, and `POST /devices` rejects a new device with 422 when the account is full. The wizard therefore stops before phrase entry. Someone who lost all trusted devices remains locked out despite having the correct phrase and inbox access.
Allow a fresh device to enter recovery without granting trust above the limit, and test the flow starting before registration. The added limit test already has a pending caller, so it misses this failure.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Preview environment deployed 🚀
Stack: Auto-destroys on PR close/merge. Login via the bundled Keycloak realm — |
…sion proof and a step-up code
…gration on this device
2636046 to
8a212b2
Compare
| if (siblings === 'untrusted') { | ||
| await database | ||
| .update(devicesTable) | ||
| .set({ trusted: false, approvalPending: false, nodeId: null, nodeIdAttestedAt: null }) |
There was a problem hiding this comment.
📐 Convention — Could a sibling that was waiting for approval end up on the "denied" screen?
On the v1-phrase recovery path, every other regular device goes to trusted: false, approvalPending: false. That is the same row state a deny or a cancel leaves. A second device that is still polling for approval then gets the 422 "Approval not pending" from the approval-status route (backend/src/api/encryption.ts:1053). use-approval-polling.ts:102 turns that 422 into onDenied, so the user is told the device was denied when nobody denied it. Is that intended? If not, we could leave already-pending siblings pending in this mode, or give the client a way to tell "demoted by recovery" apart from "denied".
Accounts still on scheme 1 could only migrate from a trusted device that kept the v1 key, so users who lost that browser were locked out: their v1 phrase was rejected.
A pending device can now recover with the v1 phrase (the raw CK): it proves the phrase against the v1 canary locally, then runs the v1→v2 migration itself. Because the server's possession proof is a replayable secret, the upgrade also requires an emailed step-up code (new
v1-phrase-recoveryaction).