Skip to content

refactor(vault): eliminate global mutable state for search identity#361

Merged
danieljustus merged 5 commits into
mainfrom
session/20260603-223216
Jun 3, 2026
Merged

refactor(vault): eliminate global mutable state for search identity#361
danieljustus merged 5 commits into
mainfrom
session/20260603-223216

Conversation

@danieljustus
Copy link
Copy Markdown
Owner

@danieljustus danieljustus commented Jun 3, 2026

refactor(vault): eliminate global mutable state for search identity

Move searchIdentity atomic.Pointer from package-level variable to a field
on the Vault struct. Remove rememberSearchIdentity, currentSearchIdentity,
and the standalone CurrentSearchIdentity function. Replace with a method
on Vault that reads from the per-instance cache.

Update all callers of List() and FindWithOptions() to pass identity
explicitly instead of relying on the global cache. Doctor health checks,
audit logger, and UI code now pass nil identity when no vault session
is active, handling the missing-identity case gracefully.

This eliminates a cross-vault identity leakage risk where opening a
second vault would overwrite the first vault's search identity in the
global atomic pointer.

Milestone: v0.4.1

Move searchIdentity atomic.Pointer from package-level variable to a field
on the Vault struct. Remove rememberSearchIdentity, currentSearchIdentity,
and the standalone CurrentSearchIdentity function. Replace with a method
on Vault that reads from the per-instance cache.

Update all callers of List() and FindWithOptions() to pass identity
explicitly instead of relying on the global cache. Doctor health checks,
audit logger, and UI code now pass nil identity when no vault session
is active, handling the missing-identity case gracefully.

This eliminates a cross-vault identity leakage risk where opening a
second vault would overwrite the first vault's search identity in the
global atomic pointer.

Closes #334
Update tui_test.go List calls to pass vault.Identity.
Update coverage_expansion_test.go to use Vault.CurrentSearchIdentity() method.

Refs #334
@danieljustus danieljustus added the auto-pr Pull request opened by an automated run label Jun 3, 2026
Update all test callers of List(), FindWithOptions(), and removed
rememberSearchIdentity/currentSearchIdentity to match the new function
signatures that require an explicit *age.X25519Identity parameter.

- Add nil identity to List() calls that don't need decryption
- Pass stored identity to FindWithOptions() calls where previously set
  via rememberSearchIdentity()
- Rewrite TestCurrentSearchIdentity tests to use Vault struct field
- Remove references to deleted package-level searchIdentity variable

Refs PR #361
- TestFindWithNoIdentity and TestFindConcurrentNoIdentity must pass
  nil identity to verify error when no search identity is available.
- TestEncryptedIndexFilterPathsUsingIndexLoadsFromDisk must pass
  a valid identity (not nil) since filterPathsUsingIndex returns
  early when identity is nil.
- Fix gofmt formatting in affected files.

Refs PR #361
golangci-lint flagged nilness: impossible condition nil != nil.
The second error check was left from the original code structure
where identity was validated before calling VerifyManifestIntegrity.
Now nil identity is passed directly and the first error check
handles the session-needed case.

Refs PR #361
@danieljustus danieljustus marked this pull request as ready for review June 3, 2026 21:46
@danieljustus danieljustus merged commit 1d43069 into main Jun 3, 2026
9 of 12 checks passed
@danieljustus danieljustus deleted the session/20260603-223216 branch June 3, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-pr Pull request opened by an automated run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global mutable state risks cross-vault identity leakage

1 participant