Skip to content

[PM-46258] [Importer] Preserve displaced values on duplicate KeePass2 XML String keys - #24423

Merged
harr1424 merged 5 commits into
bitwarden:mainfrom
arxhr007:fix/keepass2-duplicate-keys
Nov 18, 2026
Merged

harr1424 merged 5 commits into
bitwarden:mainfrom
arxhr007:fix/keepass2-duplicate-keys

Conversation

@arxhr007

@arxhr007 arxhr007 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🎟️ Tracking

Fixes #24365 (same overwrite class of bug, affecting Clipperz and KeePass XML).

https://bitwarden.atlassian.net/browse/PM-46258
https://bitwarden.atlassian.net/browse/PM-46162

📔 Objective

The KeePass2 XML importer silently dropped data on duplicate <String> keys. KeePass databases merged through KeePass's own sync/merge, or produced by third-party exporters, can contain entries where the same Key appears more than once:

<String><Key>Password</Key><Value>oldsecret</Value></String>
<String><Key>Password</Key><Value>newsecret</Value></String>

The previous code assigned reserved keys (URL, UserName, Password, otp, Title) unconditionally, so the last value won the cipher slot and every earlier value was lost entirely — not even preserved as a custom field.

Changes:

  • Displaced Password and otp values are kept as hidden custom fields; displaced UserName and Title values as text fields. The value that wins the login slot is identical to current behavior.
  • Duplicate URL keys now append to the login's URI list (Bitwarden supports multiple URIs per login) instead of replacing it.
  • Matches the precedent already used by enpass-json-importer (isNullOrWhitespace guard) and safeincloud-xml-importer (secret candidates kept as hidden fields).

📸 Testing

  • Added TestDataDuplicateKeys fixture plus 3 specs covering: displaced password preserved as hidden field, displaced username/title/otp preserved as fields, and duplicate URLs appended to the URI list.
  • Existing KeePass2 specs unchanged and still valid (single-key behavior is untouched — the guards only activate on a second occurrence).

Note: I was unable to run the Jest suite locally (repo requires Node ≥ 24); the routing logic was verified with a distilled harness (15/15 cases). Relying on CI for the full suite.

⏰ Reminders before review

  • Contributor guidelines followed
  • All tests pass in the current environment (via CI)
  • New and updated tests are included

arxhr007 and others added 2 commits November 4, 2026 16:10
…ed fields

Clipperz marks locked fields with hidden: true; they were imported as
plain-text custom fields or silently dropped. Multiple fields sharing an
actionType (e.g. several locked password-type fields) overwrote each
other unconditionally, so the last field won the slot and earlier values
were lost.

- hidden: true fields now import as hidden custom fields
- the password slot prefers a field actually labeled as a password; a
  displaced or additional field becomes a hidden custom field instead of
  vanishing
- the same no-silent-overwrite guard applies to username and url fields

fixes #24365
Duplicate <String> elements with the same Key (produced by KeePass
database merges and third-party exporters) silently overwrote earlier
values: the last Password won the login slot and previous values were
dropped entirely.

Displaced values are now kept as custom fields (hidden for Password and
otp), and duplicate URL keys append to the login's URI list instead of
replacing it.
@arxhr007
arxhr007 requested a review from a team as a code owner November 4, 2026 14:25
@bitwarden-bot

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! We've added this to our internal tracking system for review.
ID: PM-46258
Link: https://bitwarden.atlassian.net/browse/PM-46258

Details on our contribution process can be found here: https://contributing.bitwarden.com/contributing/pull-requests/community-pr-process.

@bitwarden-bot bitwarden-bot changed the title [Importer] Preserve displaced values on duplicate KeePass2 XML String keys [PM-46258] [Importer] Preserve displaced values on duplicate KeePass2 XML String keys Nov 4, 2026
@bitwarden-bot bitwarden-bot added community-pr needs-qa Marks a PR as requiring QA approval labels Nov 4, 2026
@harr1424

Copy link
Copy Markdown
Contributor

Hi @arxhr007 and thanks for your first contribution to Bitwarden! It looks like this PR contains the same proposed changes as your earlier PR, if that's correct, would you mind closing that one? I'll begin reviewing this PR next, and will reach out here with any questions or concerns that arise.

harr1424
harr1424 previously approved these changes Nov 10, 2026
@harr1424 harr1424 added the ci:signed-build Runs fork PR build workflows with secrets (including artifact signing) label Nov 10, 2026
@github-actions github-actions Bot removed the ci:signed-build Runs fork PR build workflows with secrets (including artifact signing) label Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.12500% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.17%. Comparing base (b24d9d8) to head (30e9c80).
⚠️ Report is 10 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...s/importer/src/importers/clipperz-html-importer.ts 68.18% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24423   +/-   ##
=======================================
  Coverage   63.16%   63.17%           
=======================================
  Files        4989     4989           
  Lines      162529   162556   +27     
  Branches    26210    26221   +11     
=======================================
+ Hits       102666   102692   +26     
+ Misses      52890    52883    -7     
- Partials     6973     6981    +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@harr1424

Copy link
Copy Markdown
Contributor

@arxhr007 I've tested these changes against KeePass XML and Clipperz export files and this is a huge improvement. Imports behave exactly as you've described. I've sent the internal ticket corresponding to this PR to QA for a final review.

@harr1424 harr1424 added t:bugfix Change Type - Bugfix and removed needs-qa Marks a PR as requiring QA approval labels Nov 17, 2026
@djsmith85 djsmith85 added browser Browser Extension desktop Desktop Application cli CLI Application web labels Nov 18, 2026
@harr1424 harr1424 added the ci:signed-build Runs fork PR build workflows with secrets (including artifact signing) label Nov 18, 2026
@github-actions github-actions Bot removed the ci:signed-build Runs fork PR build workflows with secrets (including artifact signing) label Nov 18, 2026
@harr1424
harr1424 merged commit ab4d2ea into bitwarden:main Nov 18, 2026
331 of 343 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

browser Browser Extension cli CLI Application community-pr desktop Desktop Application t:bugfix Change Type - Bugfix web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clipperz data import is ignoring "hidden" fields and mapping the wrong password value

5 participants