Skip to content

fix: require current password before changing password#3572

Open
shivv23 wants to merge 2 commits into
getAlby:masterfrom
shivv23:fix/password-change-require-current-password
Open

fix: require current password before changing password#3572
shivv23 wants to merge 2 commits into
getAlby:masterfrom
shivv23:fix/password-change-require-current-password

Conversation

@shivv23

@shivv23 shivv23 commented Jun 25, 2026

Copy link
Copy Markdown

Describe the changes you have made in this PR

Require the user to enter their current password before allowing a password change. Previously, anyone with access to an unlocked extension could change the password without re-authentication.

The fix decrypts the stored account config with the provided current password (same pattern used in unlock.ts) before accepting the new password.

Link this PR to an issue

Fixes #2865

Type of change

  • fix: Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  • yarn tsc:compile — 0 errors
  • yarn lint:js — 0 errors, 0 warnings
  • yarn test:unit — all 75 suites / 168 tests pass
  • Manual testing: verified the password change flow works end-to-end with correct current password, and rejects incorrect current passwords

Checklist

  • Self-review of changed code
  • Manual testing
  • Added automated tests where applicable
  • Update Docs & Guides
  • For UI-related changes
  • Darkmode
  • Responsive layout

Summary by CodeRabbit

  • New Features
    • Added a “current password” field to the change-password flow.
    • Password updates now require both your current password and the new password.
  • Bug Fixes
    • Improved validation and clearer error messaging when the current password is incorrect or required fields are missing.
    • The submit button is disabled until the current password is provided.
    • After a successful password change, the modal resets automatically.
  • Documentation
    • Added a new localized label for the current password field in Settings.

- Validate currentPassword by decrypting account config (same pattern as unlock)
- Add currentPassword field to the Settings UI modal
- Update MessageChangePassword type with currentPassword arg
- Add i18n key for current password label
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 61cc7f73-eaac-4af5-97fb-71c4c6afba04

📥 Commits

Reviewing files that changed from the base of the PR and between 3c2b8c0 and 60c4850.

📒 Files selected for processing (2)
  • src/app/screens/Settings/index.tsx
  • src/extension/background-script/actions/settings/changePassword.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/extension/background-script/actions/settings/changePassword.ts
  • src/app/screens/Settings/index.tsx

📝 Walkthrough

Walkthrough

The Settings password-change flow now collects current and new passwords, labels the current-password field, and sends both values to the background action. The background action verifies the current password, re-encrypts stored account data with the new password, updates state, and persists the result.

Changes

Password change verification

Layer / File(s) Summary
Message contract and label
src/types.ts, src/i18n/locales/en/translation.json
MessageChangePassword now carries currentPassword and password, and the settings locale adds the current password label.
Settings modal wiring
src/app/screens/Settings/index.tsx
The Settings screen stores currentPassword, submits both passwords, clears the form after success, toasts error messages directly, adds the current password field, and requires it before submit.
Background password update
src/extension/background-script/actions/settings/changePassword.ts
The changePassword action validates both inputs, verifies currentPassword against stored account data, re-encrypts account fields with the new password, updates stored password state, and saves the result.

Sequence Diagram(s)

sequenceDiagram
  participant SettingsScreen
  participant changePassword
  participant state
  participant saveToStorage
  SettingsScreen->>changePassword: currentPassword and password
  changePassword->>state: read account configs
  changePassword->>changePassword: verify currentPassword and re-encrypt data
  changePassword->>state: update accounts and stored password
  changePassword->>saveToStorage: persist updated state
  changePassword-->>SettingsScreen: {}
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I nibbled the lock, then gave it a peek,
Two passwords now hop in the same little tweak.
Old keys get checked before new ones appear,
Then storage tucks them in nice and clear.
Hoppy code, secure mode, with a twitch and a cheer!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main fix: requiring the current password before changing it.
Description check ✅ Passed The description covers the change, linked issue, type, testing, and checklist, with only optional screenshots missing.
Linked Issues check ✅ Passed The code matches #2865 by verifying the current password before allowing a password change.
Out of Scope Changes check ✅ Passed The UI, background action, types, and localization changes all directly support the password-verification fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/screens/Settings/index.tsx`:
- Around line 50-53: The error handling in Settings/index.tsx is showing raw
backend text through toast.error in the catch block, which bypasses
react-i18next. Update the password-change flow to translate stable backend error
codes (including the new invalid current password case) into
t("change_password.errors...") keys before toasting, and keep the existing catch
logic in the change password handler from exposing e.message directly.
- Line 21: The currentPassword field in Settings/index.tsx is being handled in a
way that can both alter the user’s input and leave stale state behind. Update
the form flow so the verification logic in the submit handler uses the exact
currentPassword value without trimming or otherwise modifying it, and make the
field controlled like the other form inputs. Also clear formData.currentPassword
inside closeModal() and on any reset path so a previous value cannot be reused
on the next modal open; use the existing closeModal and submit/verification
logic as the touchpoints for the fix.

In `@src/extension/background-script/actions/settings/changePassword.ts`:
- Around line 29-36: The changePassword flow in the account re-encryption logic
is only shallow-copying the accounts map, so mutating each entry’s config and
other secret fields can leak into live state before the whole loop succeeds.
Update the logic in changePassword to deep-clone each account object before
decrypting/re-encrypting fields, then write the encrypted values back on the
cloned object and only replace the original state after all per-account updates
complete; apply this consistently for the config, nostrPrivateKey, and mnemonic
handling in the same function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aa0709a8-27a1-4eee-81b3-df0bfb67c81a

📥 Commits

Reviewing files that changed from the base of the PR and between bad06c2 and 3c2b8c0.

📒 Files selected for processing (4)
  • src/app/screens/Settings/index.tsx
  • src/extension/background-script/actions/settings/changePassword.ts
  • src/i18n/locales/en/translation.json
  • src/types.ts

Comment thread src/app/screens/Settings/index.tsx
Comment thread src/app/screens/Settings/index.tsx
Comment thread src/extension/background-script/actions/settings/changePassword.ts
- Remove .trim() on currentPassword so passwords with leading/trailing spaces work
- Add value prop to currentPassword TextField (make it controlled)
- Move formData reset into closeModal() and remove duplicate from updateAccountPassword
- Deep-clone each account entry in changePassword before re-encrypting fields
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.

[BUG] New passwords can be set repeatedly without verification of old passwords

1 participant