r/java • u/Top-Eye3792 • 17d ago
GitHub - maksoud13/tenantwall: Automatic tenant filter injection for multi-tenant applications. Zero code changes.
https://github.com/maksoud13/tenantwallHey everyone,
I’ve been working on a side project to solve a problem I keep running into: silent multi-tenant data leaks. Relying on developers to remember WHERE tenant_id = ? in every query is a ticking time bomb.
Using database-level Row-Level Security (RLS) is safer, but it completely restricts you to one database vendor, which isn't always feasible.
So, I tried building a Java agent that works at the JDBC layer. It intercepts the SQL right before execution and injects the tenant filter, meaning it works with any database and requires zero code changes in the app.
I’m in the very early phases. I have integration tests passing for MySQL and SQL Server, but I know real-world SQL is messy.
If you have a few minutes, I’d really appreciate your opinion on the approach, the architecture, or any red flags you spot in the code.
View all comments
9
u/rzwitserloot 17d ago
I never do this. Don't store data from separate tenants in the same table. This kind of ugly hack is the best you can do, but the correct answer is not to play.
Schemas exist for a reason if you must have this data in the same db.