Repository navigation
Description
Summary
Identifier availability checks incorrectly report soft-deleted usernames, emails, and other identifiers as available, even though the EF Core persistence model reserves their normalized values through a unique index.
The issue affects both EF Core and InMemory implementations of IUserIdentifierStore.ExistsAsync().
This is a consistency and validation bug, not a confirmed authentication bypass.
Root cause
Both store implementations exclude soft-deleted identifiers from existence checks:
EF Core
x.DeletedAt == nullInMemory
!x.IsDeletedHowever, the EF Core model defines an unfiltered unique index on:
Tenant + Type + NormalizedValueAs a result, CheckAvailabilityAsync() may return IsAvailable = true, while subsequent user creation fails when persistence attempts to insert the identifier.
UserCreateValidator uses the same availability service, so the inconsistency also affects server-side validation.
Expected behavior
Under the current identifier reservation model:
- Soft-deleted identifiers remain unavailable for reuse.
- Availability checks must agree with creation-time uniqueness enforcement.
- EF Core and InMemory stores must produce consistent results.
- Normal identifier resolution and authentication must continue excluding soft-deleted identifiers.
Proposed fix
- Update
EfCoreUserIdentifierStore.ExistsAsync()to include soft-deleted identifiers. - Apply the equivalent change to
InMemoryUserIdentifierStore.ExistsAsync(). - Preserve active-only filtering in
GetAsync(type, normalizedValue)and other ordinary retrieval operations. - Review callers of
ExistsAsync(), particularlyUserIdentifierExistsAsync(), and document the resulting existence semantics. - Verify that InMemory insertion behavior is consistent with the identifier reservation policy.
Do not introduce new soft-delete configuration options in this bug fix. Configurable identifier reuse and restoration policies are tracked separately under the broader soft-delete lifecycle issue.
Regression tests
- EF Core
ExistsAsync()finds a soft-deleted identifier. - InMemory
ExistsAsync()finds a soft-deleted identifier. - Availability returns unavailable for a soft-deleted username.
- Availability returns unavailable for a soft-deleted email.
- User creation rejects an identifier reserved by a soft-deleted record during validation.
-
GetAsync(type, normalizedValue)continues excluding soft-deleted identifiers. -
ExcludeIdentifierIdand existence scopes retain their expected behavior. - InMemory and EF Core uniqueness enforcement remain consistent.
Acceptance criteria
- Availability no longer reports reserved soft-deleted identifiers as available.
- Existing uniqueness constraints and authentication behavior remain unchanged.
- Both persistence implementations pass the shared store contract tests.
- No breaking changes to public API signatures.
- No unrelated soft-delete lifecycle or restoration changes.
Activity