Skip to content

feat(e2ee): recover a v1 account from its v1 recovery phrase - #1608

Open
raivieiraadriano92 wants to merge 6 commits into
mainfrom
raivieiraadriano92/e2ee-v1-phrase-recovery
Open

raivieiraadriano92 wants to merge 6 commits into
mainfrom
raivieiraadriano92/e2ee-v1-phrase-recovery

Conversation

@raivieiraadriano92

@raivieiraadriano92 raivieiraadriano92 commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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-recovery action).

@raivieiraadriano92 raivieiraadriano92 self-assigned this Nov 19, 2026
@github-actions

Copy link
Copy Markdown

Semgrep Security Scan

No security issues found.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Metrics

Metric Value
Lines changed (prod code) +929 / -164
JS bundle size (gzipped) 🟢 657.5 KB → 658.7 KB (+1.1 KB, +0.2%)
Test coverage 🟢 89.15% → 89.18% (+0.0%)
Lighthouse performance (signed out; preview) Lighthouse results unavailable
Accessibility —
Best Practices —
SEO —

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

@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Recovery fails at device limit. ▶
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.

Summary

Adds recovery for older encrypted accounts using their original recovery phrase and an emailed code.

  • A pending device can migrate a scheme-1 account with its original phrase and an emailed code.
  • The recovery wizard asks for an email code and shows the replacement phrase.

Diagram

sequenceDiagram
    actor User
    participant App
    participant Server
    participant Email
    User->>App: Enter original recovery phrase
    App->>App: Check phrase against old canary
    App->>Server: Request recovery code with old secret
    Server->>Email: Send recovery code
    User->>App: Enter emailed code
    App->>Server: Submit upgrade, old secret, and code
    Server->>Server: Check code and commit keys and device trust together
    Server-->>App: Upgrade succeeded
    App-->>User: Show replacement recovery phrase
Loading

Reviews (2) · Last reviewed commit: "docs(e2ee): document v1-phrase recovery ..." · Reviewed by Greptile

Comment on lines +1531 to +1534
if (recoveringWithPhrase) {
const activeCount = await countActiveDevices(txDb, userId)
if (activeCount >= maxActiveDevicesPerUser) {
throw new ForbiddenError('Device limit reached — revoke an existing device first')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Preview environment deployed 🚀

Service URL
Marketing / blog / docs https://thunderbolt-pr-1608.preview.thunderbolt.io
App https://app-pr-1608.preview.thunderbolt.io
API https://api-pr-1608.preview.thunderbolt.io
Keycloak https://auth-pr-1608.preview.thunderbolt.io
PowerSync https://powersync-pr-1608.preview.thunderbolt.io

Stack: preview-pr-1608 · Commit: 8a212b2fa1296a7ea3c0295b3539ccdce5612e0a

Auto-destroys on PR close/merge. Login via the bundled Keycloak realm — demo@thunderbolt.io / demo by default.

@raivieiraadriano92
raivieiraadriano92 force-pushed the raivieiraadriano92/e2ee-v1-phrase-recovery branch from 2636046 to 8a212b2 Compare November 19, 2026 20:51
@raivieiraadriano92
raivieiraadriano92 marked this pull request as ready for review November 19, 2026 20:55

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔭 thunder-deep-review (advisory)

Reviews the diff for grounded findings. Never approves, never requests changes, never gates merge.
head: 8a212b2fa129 · mode: deep

if (siblings === 'untrusted') {
await database
.update(devicesTable)
.set({ trusted: false, approvalPending: false, nodeId: null, nodeIdAttestedAt: null })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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".

This branch was successfully deployed

1 active deployment
preview — 8a212b2f Deployed Nov 19, 2026 by raivieiraadriano92 via deploy / deploy #5365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant