We Built Multi-Tenancy Into a Blazor App. Here's Every Layer Preventing Data Leaks.
Last year our team shipped a Blazor app to a client running three tenants. Within a week, a support ticket came in: "I can see another company's data." Turned out we'd forgotten a query filter on o...

Source: DEV Community
Last year our team shipped a Blazor app to a client running three tenants. Within a week, a support ticket came in: "I can see another company's data." Turned out we'd forgotten a query filter on one entity. One table. We rebuilt the entire multi-tenancy layer after that. Not just the query filters. Everything. Four separate layers of isolation so that if any single one has a bug, the others still block the leak. For that reason, I built BlazorBluePrint, a production-ready Blazor WebAssembly template, and multi-tenancy was the hardest part to get right. This is exactly how it works, with real code from the project. Four Layers, One Goal Here's the stack: Middleware figures out which tenant owns this request EF Core query filters scope every database read to that tenant SaveChanges override stamps every new record with the tenant ID JWT claims carry the tenant ID in a signed token If the query filter has a bug, the middleware already blocked unauthorized access. If the middleware has a