Skip to content

encrypt with item key when editing keyed entries - #366

Open
NanShanFish wants to merge 1 commit into
doy:mainfrom
NanShanFish:fix/edit-item-key
Open

encrypt with item key when editing keyed entries#366
NanShanFish wants to merge 1 commit into
doy:mainfrom
NanShanFish:fix/edit-item-key

Conversation

@NanShanFish

Copy link
Copy Markdown

Problem

rbw edit corrupts entries that have an individual encryption key (an entry
with a key field). After editing such an entry, its password/notes can no
longer be decrypted by any client (including rbw), failing with invalid mac.
See #364.

Root cause:

  • The edit path re-encrypts the new password/notes with the master key (or org
    key) via the encrypt action, ignoring the entry's item key
  • CiphersPutReq (PUT /api/ciphers/{id}) never sends the cipher's key field,
    so the server keeps the stale item key

The result is a mixed-key cipher: name/username encrypted with the item key,
password/notes encrypted with the master key, tagged with an item key that
matches neither. No client can decrypt the whole item.

Changes

  • src/protocol.rs: add entry_key to Action::Encrypt
  • src/bin/rbw/actions.rs: pass entry_key through the encrypt action
  • src/bin/rbw-agent/actions.rs: when entry_key is provided, unwrap the item
    key (decrypt it with the master/org key) and encrypt with the item key
    instead of the master key. Extracted as a testable encrypt_with_key helper
  • src/bin/rbw-agent/agent.rs: dispatch the new entry_key argument
  • src/bin/rbw/commands.rs: the edit flow passes the entry's key when
    re-encrypting, so keyed entries are edited with their own key
  • src/api.rs: add key to CiphersPutReq and send it in Client::edit, so
    the server keeps the correct item key
  • src/actions.rs: thread key through edit / edit_once
  • Tests: round-trip test proving data encrypted via the item key decrypts only
    with the item key (and not with the master key)

Result

Editing an entry with an individual key now encrypts the new field values with
the entry's item key and sends the key field on update, so all clients
decrypt the item correctly. Entries without a key field behave exactly as
before.

Testing

  • cargo test (all targets) passes
  • cargo fmt / cargo clippy --all-targets clean

Fixes #364

pschmitt added a commit to pschmitt/rbw that referenced this pull request Aug 17, 2026
find_entry, find_entry_multi, find_entries_all, find_deleted_entry(_all),
list's structured and table output, search, and the TUI's search-index
rebuild all propagated a single entry's decrypt failure into failing the
entire scan -- so one corrupt cipher anywhere in the vault could make
`rbw list`/`get`/`remove`/`set --bulk`/etc. fail across every other,
perfectly fine entry too. Skip the bad entry and log a warning instead,
everywhere that's scanning/searching across many entries; single-target
lookups (`rbw get <uuid>` on the corrupted entry itself) still fail
loudly, which is correct there.

Matches the second half of upstream doy#364/doy#366 (fixed in the fork
only, no PR sent upstream).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

rbw edit corrupts entries that have an individual encryption key

1 participant