Repository navigation
fix: rotate restored JWT & guard status window - #1431
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
Working on inserting WhatsApp template placeholders at the current textarea cursor/selection position and restoring caret focus. |
PR Summary by QodoRotate JWT secrets on restore and protect startup from status-window failures
AI Description
Diagram
High-Level Assessment
Files changed (12)
|
Code Review by Qodo
1.
|
Rotate settings.jwt_secret to a fresh 32-byte hex secret during authoritative backup restore alongside updating users.tokens_valid_after so backups carrying safe-storage:v1 work both with and without OS safeStorage. Guard window-all-closed while runtimeState is starting and destroy failed or timed-out status windows in openWindow() so status-window failures before mainWindow creation cannot quit the app on Windows or Linux. Remove unreachable dataOnlyRestore, readRevocations, mergeRevocations, and RevocationRow from main/db.ts, and update the restore-backup IPC handler dialog and completion message to reflect authoritative restore with forward migration. Fixes #1427
… Every file changed in the PR diff must conform to the repository's `oxfmt` formatting standard (`scripts/ci/check-changed-format.cjs`), which guarantees that `Lint & Build Validation (Linux)` and the downstream `Required Checks Gate` succeed. - **Violated Sites:** Four files modified in the PR (`main/status-window.ts`, `main/window-recovery.ts`, `tests/shutdown-lifecycle.test.ts`, and `tests/status-messages.test.ts`) failed `oxfmt --check` during `node scripts/ci/check-changed-format.cjs`, causing `Lint & Build Validation (Linux)` (ci-1) and consequently `Required Checks Gate` (ci-2) to fail. ### Fix Applied Formatted the four unformatted changed files using `npx oxfmt --write -- main/status-window.ts main/window-recovery.ts tests/shutdown-lifecycle.test.ts tests/status-messages.test.ts`. ### Verification - `node scripts/ci/check-changed-format.cjs --base 7b18927` (passed) - `npm run lint` (passed) - `npm run build` (passed) - `npx tsx tests/shutdown-lifecycle.test.ts` (passed) - `npx tsx tests/status-messages.test.ts` (passed) - `git diff --check` (passed)
ed80fab to
93bbbf1
Compare
Intent
Resolve the three follow-up findings from the review of commit
26639fdf7e1646da0a82fac91dbb64ee66d9d5ea(PR #1425, tracked in #1427):settings.jwt_secret(safe-storage:v1) from backups without rotating it, breaking sign-in when OS encryption is unavailable and reusing the target machine's existing key when available:main/db.ts(restoreBackup()), rotatesettings.jwt_secretto a fresh 32-byte hex secret (crypto.randomBytes(32).toString('hex')) alongside updatingusers.tokens_valid_after, matchingrestoreCompatibleBackupForDowngrade().tests/backup-restore-production.test.tsaccordingly and verify that restoring a backup containingsettings.jwt_[REDACTED]:v1'rotatessettings.jwt_secretsogetJWTSecret()works both with and without OSsafeStorage.window-all-closed:initialize()inmain/index.ts,showStatus('starting')opensstatusWindowbeforemainWindowis created. Ifwindow.loadURL(...)rejects or times out inopenWindow()(main/status-window.ts), or a subsequentshowStatus(...)call fails inexecuteJavaScript,closeStatus()destroysstatusWindow. On Windows and Linux (process.platform !== 'darwin'), destroying the only openBrowserWindowfireswindow-all-closed(main/index.ts) and callsapp.quit()mid-startup.window-all-closed/ status-window closure during startup (runtimeState === 'starting') and failed/timed-out status-window loads so a status-window failure or close beforemainWindowexists cannot quit the application on Windows or Linux.main/db.ts(dataOnlyRestore,readRevocations,mergeRevocations) and stale data-only copy inmain/ipc.ts:dataOnlyRestore,readRevocations, andmergeRevocationsfunctions (andRevocationRowif unused) inmain/db.ts.restore-backupIPC handler inmain/ipc.tsso its schema-version-mismatch dialog and completion result message reflect authoritative restore with forward migration rather than legacy data-only mode.What Changed
settings.jwt_secretto a fresh 32-byte hex secret duringrestoreBackup()so restored databases do not inherit stalesafe-storage:v1values or reuse the prior signing key.window-all-closedapplication termination whileruntimeState === 'starting'and destroy/disable the status window when initialloadURLfails or times out so startup continues on Windows and Linux.dataOnlyRestoreand revocation-merging helpers frommain/db.tsand update therestore-backupIPC handler and documentation to reflect authoritative restore with forward migration.Risk Assessment
✅ Low: The changes cleanly rotate the JWT secret on authoritative backup restore, guard status-window failures and all-windows-closed events during startup, remove unreachable legacy data-only restore helpers, and remove the unused 'updating' status key cast from round 1 with matching test and documentation updates.
Testing
Ran the targeted backup/restore, JWT secret, status-messages, window-load-retry, and shutdown-lifecycle test suites, and drove the compiled Electron main-process modules live in isolated disposable environments to verify JWT secret rotation across restore with and without OS safeStorage, older-schema IPC restore dialog and result copy, and real Electron BrowserWindow startup status-window failure handling and screenshots. All checks and live scenarios passed.
Evidence: Live restore JWT rotation and older-schema IPC restore verification
{ "jwtRotationWithoutSafeStorage": { "restoreSuccess": true, "mode": "direct", "rotatedSecretLength": 64, "rotatedSecretIsHex64": true, "jwtSignAndVerifySucceeded": true }, "jwtRotationWithSafeStorage": { "restoreSuccess": true, "mode": "direct", "rotatedSecretLength": 64, "rotatedSecretIsHex64": true, "differsFromPreRestoreEncFile": true, "persistedMarkerAfterRead": "safe-storage:v1" }, "ipcOlderSchemaRestore": { "response": { "success": true, "mode": "direct", "backupVersion": 123, "currentVersion": 124, "tablesRestored": 69, "message": "Database restored successfully", "cleanupPending": false }, "dialogTitle": "Schema Version Mismatch", "dialogMessage": "Backup was created with Schema v123", "dialogDetail": "Current database uses Schema v124.\n\nRestoring will replace the current database with this backup and migrate its schema to v124.\n\nDo you want to continue?" } }Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
main/status-window.ts:96-showStatus()checks(key as string) === 'updating'using a type cast to bypass theStatusKeyunion (main/status-messages.ts:1-9), which only defines'starting' | 'checking' | 'backingUp' | 'services' | 'welcome' | 'closing' | 'shutdownBackup' | 'saved'and has no'updating'key anywhere in the codebase. Neither the user intent nor any caller requires an'updating'branch; recommend narrowing the reset condition toif (key === 'closing').🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Test** - 1 issue found → no changes applied ✅
🔧 No changes applied.
✅ Re-checked - no issues remain.
npm run test:backupnpm run test:shutdown-lifecyclenpm run test:status-messagesnpm run test:window-load-retrynpm run test:jwt-secret-safe-storagenpm run test:jwt-secret-cache-identitynpm run test:jwt-secret-persist-before-cachenpm run test:newer-db-recoveryelectron --no-sandbox <live-status-window-harness>(real Electron BrowserWindow rendering, loadURL rejection, window-all-closed suppression during startup, and 'closing' recovery with PNG screenshots)ELECTRON_RUN_AS_NODE=1 electron -e <live-restore-and-ipc-harness>(compiled dist/main/db.js, dist/main/security/jwt-secret.js, and dist/main/ipc.js verification with safe-storage:v1 backups and older-schema IPC restore)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Fixes #1427