Repository navigation
[PAM-466] (B10) Vault: keep restricted ciphers out of upsert and URL matching - #24281
Conversation
| // When every item is kept, skip the write: an unchanged record clears the cache but emits | ||
| // nothing in the extension, the case replace() also guards against. | ||
| userId ||= await firstValueFrom(this.stateProvider.activeUserId$); | ||
| const stored = (await firstValueFrom(this.encryptedCiphersState(userId).state$)) ?? {}; | ||
| if (ciphers.length > 0 && ciphers.every((c) => keepsStored(stored[c.id as CipherId], c))) { | ||
| logKept(ciphers.length); | ||
| return stored; |
There was a problem hiding this comment.
Changed from pam/uat in this PR (also pushed to pam/uat as d2aa1dd)
Problem: updateEncryptedCipherState always clears the decrypted cache before it writes. When the guard below keeps every incoming item, upsert wrote a record identical to the stored one. In the extension, state$ emits only on chrome.storage.onChanged, and Chrome fires no event for an unchanged value. So nothing rebuilt the cache. Autofill, the inline menu and the context menu then found no items for any site until the next real change or full sync.
When it happens:
- An extension user has an active lease on a restricted item.
- An admin edits the item, or the access connector rotates it, and the server sends a push update.
- Push sync fetches the item, gets the full copy, and calls
upsert. - The guard keeps the stored restricted copy, and the write changes nothing.
Fix: read the stored copies first. If every incoming item would be kept, log the count and return without clearing the cache or writing. replace() already skips identical writes for the same reason. A mixed call (some items kept, some written) still writes, so the cache rebuilds as before.
Test: "skips the write and keeps the cache when every item is kept" checks that neither clearCache nor the state write runs. It fails without the fix.
There was a problem hiding this comment.
Not sure if there is a cleaner way to do this, or if we want to drop the console debug calls.
There was a problem hiding this comment.
I've created a tech debt ticket for Vault to clean these up here: https://bitwarden.atlassian.net/browse/PM-46064
We should be fine to merge as is for now though.
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE This PR adds two guards to |
There was a problem hiding this comment.
@shane-melton Let me know if you don't like these comments
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24281 +/- ##
==========================================
+ Coverage 61.05% 61.06% +0.01%
==========================================
Files 4872 4872
Lines 156182 156201 +19
Branches 25000 25006 +6
==========================================
+ Hits 95352 95382 +30
+ Misses 54297 54279 -18
- Partials 6533 6540 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| // When every item is kept, skip the write: an unchanged record clears the cache but emits | ||
| // nothing in the extension, the case replace() also guards against. | ||
| userId ||= await firstValueFrom(this.stateProvider.activeUserId$); | ||
| const stored = (await firstValueFrom(this.encryptedCiphersState(userId).state$)) ?? {}; | ||
| if (ciphers.length > 0 && ciphers.every((c) => keepsStored(stored[c.id as CipherId], c))) { | ||
| logKept(ciphers.length); | ||
| return stored; |
There was a problem hiding this comment.
I've created a tech debt ticket for Vault to clean these up here: https://bitwarden.atlassian.net/browse/PM-46064
We should be fine to merge as is for now though.
…#24313) * [PAM-472] (B11) Platform: sync push tests for restricted local copies Take the syncUpsertCipher tests in default-sync.service.spec.ts from pam/uat (PAM-318). Core sync hands every fetched cipher to CipherService.upsert, and B10 (#24281) keeps a stored restricted copy there. Keep main's LogoutReason import from ../../auth/logout (PM-46016, #24275). * [PAM-472] Say restricted, not partial, in the sync push test titles The block's first test says "restricted local copy" for the state that the next three call "partial". Use the one word that Vault's RestrictedCipherPolicy uses on main. * [PAM-472] Name the no-local-copy case in plain words "Lease-widened read" is a PAM-only term. Say what the client cannot tell apart: a cipher shared with the user, or one a lease made readable. * [PAM-472] Give the logged-out sync push test a local copy to fetch
🎟️ Tracking
PAM-466 (Vault review: PAM-295), bundle B10 of the clients
pam/uat->mainextraction, tracked under PAM-173.📔 Objective
Brings over the last
CipherServicechanges onpam/uat. All three files are Vault-owned, and there are no new strings. A restricted cipher is a PAM-gated item that the client stores without its secret fields (partialDataset). The two guards keep that stored copy restricted.upsertkeeps a stored restricted copy. If the stored copy of an item is restricted and the incoming copy is full,upsertkeeps the stored copy and logs a debug count. Full sync (replace) stays authoritative, so the next full sync still writes what the server sends. Push sync is the only caller onmainthat reaches this guard: archive, unarchive and folder delete already pass restricted copies through.upsertskips the write when it keeps every item.updateEncryptedCipherStatealways clears the decrypted cache before it writes. In the extension, an unchanged write fires no storage change, so nothing rebuilt the cache and autofill found no items.upsertnow returns early in that case, the same wayreplaceskips identical writes. This part is new in this PR. It was also pushed topam/uat.filterCiphersForUrlexcludes restricted ciphers. Its callers already read streams without restricted ciphers, so this is a second guard for autofill. A view withpartialfalse still matches.ciphers$,filterCiphersForUrlandupsert. ThecipherListViewsIncludingRestricted$comment now says it serves every vault list, not only the web one.cipher.service.speccovers both guards: kept, replaced and mixed upserts, the skipped write, and a restricted login with a matching URI. Some existing describe and test titles now say "restricted" instead of "partial".Known trade-off: during an active lease, a push update for a restricted item keeps the stored copy. So an admin rename, move or soft delete of that item shows only after the next full sync. The same applies when an item stops being gated, because the server sends no push for a removed rule.