Skip to content

fix: isolate in-memory key store per container - #83

Merged
brunobritodev merged 2 commits into
masterfrom
fix/in-memory-store-isolation
Nov 17, 2026
Merged

brunobritodev merged 2 commits into
masterfrom
fix/in-memory-store-isolation

Conversation

@brunobritodev

Copy link
Copy Markdown
Member

Problem

PersistKeysInMemory() stored keys in a static List<KeyMaterial>. Every host in the same process shared the same keys: two apps (or parallel integration tests, as seen in NetDevPack.Identity) overwrote and validated against each other's keys. The SemaphoreSlim was per instance while the list was static, so writes weren't really synchronized either.

Fix

  • InMemoryStore keeps an instance list guarded by a lock.
  • PersistKeysInMemory() registers it as a singleton: scopes of the same application still share keys (same behaviour as before inside one app), different service providers no longer do.
  • Vault note docs/Architecture/Stores.md updated.

Tests

  • New InMemoryStoreIsolationTests: two service providers don't share keys (fails on the old code), and scopes of one provider do.
  • All tests pass on net8.0 / net9.0 / net10.0 (516 + 2 per TFM).

Based on fix/vulnerable-deps (#82), since master doesn't restore with NuGet Audit until it's merged. Merge #82 first.

Releases as 10.0.1 (fix:).

System.Security.Cryptography.Xml/Pkcs 10.0.12 (pulled by 10.0.0) have high
severity advisories. Pin the patched versions per TFM (8.0.5/8.0.2,
9.0.23, 10.0.15) and bump the Microsoft.* packages to the latest patch of
each line (8.0.34, 9.0.23, 10.0.15).

The PR vulnerability check now ignores only the accepted IdentityServer4
advisory (ADR-002).
PersistKeysInMemory kept the keys in a static list, so every host in the
same process (e.g. parallel integration tests) shared and overwrote the
same keys. The store is now a singleton with an instance list guarded by
a lock, so scopes of one application still share keys and different
service providers don't.
@brunobritodev
brunobritodev merged commit a8eed00 into master Nov 17, 2026
1 check passed
@brunobritodev
brunobritodev deleted the fix/in-memory-store-isolation branch November 17, 2026 23:58
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.

1 participant