Skip to content

Per-request tenant resolution has no caching and soft-fails open instead of closed #42

Description

@umerfaruk

Summary

`LibraryConfigurationMiddleware` does a DB round-trip on every single request to resolve the tenant, and continues the pipeline even when the library can't be resolved.

Details

`LibraryConfigurationMiddleware.Invoke` (src/Inshapardaz.Api/Infrastructure/Middleware/LibraryConfigurationMiddleware.cs:31-43) calls `_libraryRepository.GetLibraryById(libraryId, ...)` unconditionally, and when `library is null` it just logs a warning and calls `next(context)` anyway, leaving `LibraryConfiguration` unconfigured rather than failing the request.

Impact

  • Extra DB hit on every request for data that changes rarely.
  • Given this is the linchpin of the multi-tenant model, silently continuing with a stale/default/unconfigured `LibraryConfiguration` when the library can't be resolved is a soft-fail-open design that's riskier than failing closed (404).

Suggested fix

Cache library configuration (invalidate on library update), and return 404 early when the library can't be resolved instead of continuing the pipeline.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions