Skip to content

[Bug]: Identifier availability ignores soft-deleted identifiers reserved by uniqueness constraints #120

Closed

Description

@mckaragoz

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 == null

InMemory

!x.IsDeleted

However, the EF Core model defines an unfiltered unique index on:

Tenant + Type + NormalizedValue

As 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

  1. Update EfCoreUserIdentifierStore.ExistsAsync() to include soft-deleted identifiers.
  2. Apply the equivalent change to InMemoryUserIdentifierStore.ExistsAsync().
  3. Preserve active-only filtering in GetAsync(type, normalizedValue) and other ordinary retrieval operations.
  4. Review callers of ExistsAsync(), particularly UserIdentifierExistsAsync(), and document the resulting existence semantics.
  5. 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.
  • ExcludeIdentifierId and 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

  1. added this to the v0.2.0 milestone on Oct 29, 2026
  2. added theissue type on Oct 29, 2026
  3. added
    bug
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions