- Home
- Skills
- APIs & Backend
- Spring Boot Multi-tenant SaaS
Works with the AI tools you already use
Spring Boot Multi-tenant SaaS
Audit Spring Boot and Java SaaS backends for tenant isolation, context propagation, and cross-tenant data leaks.
$19
Spring Boot Multi-tenant SaaS
Example session with this skill installed
Audit our multi-tenancy in the /app folder. We use Spring Boot with a schema-per-tenant approach and PgBouncer. Check for data leaks.
- Read your context and instructions
- Compiled the spring boot multi-tenant
I have completed the multi-tenant architecture audit for the /app directory. I identified a
schema-per-tenant model with high confidence based on the TenantIdentifierResolver implementation.
Multi-Tenant Audit Report — backend-service @ 2023-10-24
Scope: src/main/java/**, src/main/resources/**. Tenancy model: Schema-per-tenant (High confidence).
Summary — P0: 1 | P1: 2 | P2: 0 | Can't-tell: 1
Findings
[P0] MT-02 — Session-level SET with Connection Pooler
- Evidence:
src/main/java/com/saas/config/TenantSchemaInterceptor.java:42
statement.execute("SET search_path TO " + tenantId);
Why it matters: Using SET instead of SET LOCAL inside a transaction while using PgBouncer can leak the schema context to the next tenant using the same physical connection.
How to verify: Deploy to a staging env with PgBouncer in transaction mode and trace schema resolution across concurrent requests.
Suggested fix: Wrap in a transaction and use SET LOCAL search_path TO... or use a dedicated MultiTenantConnectionProvider.
[P1] MT-06 — Async path without tenant propagation
- Evidence:
src/main/java/com/saas/service/ReportService.java:112
Why it matters: The @Async method generateExport() triggers without capturing the TenantContext. The background thread will default to the 'public' schema or fail.
- Suggested fix: Use a
TaskDecoratorto copy theThreadLocalcontext to the new thread.
[P1] MT-04 — Cache keys without tenant prefix
- Evidence:
src/main/java/com/saas/repository/ProductRepo.java:15
Why it matters: @Cacheable(value = "products") lacks a tenant discriminator. Tenant A may see Tenant B's cached products.
- Suggested fix: Update the cache key to include
tenantId:key = "#root.target.tenantId + #id".
Next steps
- Patch the
SET LOCALP0 finding immediately to prevent cross-contamination in production. - Implement a
TaskDecoratorfor theThreadPoolTaskExecutorto fix the async leaks. - Update the
RedisCacheManagerconfiguration to globally prefix keys with the tenant identifier.
Connects securely to your tools. The creator never sees your data.
About this skill
Building multi-tenant SaaS on Spring Boot is high-stakes. A single missing ThreadLocal cleanup or a forgotten SET LOCAL search_path can lead to cross-tenant data leaks. This skill performs a targeted static analysis of your Java backend to ensure tenant isolation is ironclad across synchronous and asynchronous execution paths.
What it does
- Identify tenancy models by detecting schema-per-tenant, row-level, or database-per-tenant patterns in your source code.
- Trace context propagation through HTTP filters,
@Asyncmethods,@Scheduledjobs, and Kafka consumers. - Audit data access for native queries that bypass scoping and connection pooler misconfigurations like session-level
SETcommands. - Scan cache and logs to ensure Redis keys and audit trails are correctly scoped with tenant prefixes.
- Check provisioning logic for idempotency and migration safety across per-tenant Flyway instances.
How it works
- Recon Phase: Scans for
tenant_idcolumns,search_pathwiring, and JWT parsing to establish the current isolation strategy. - Propagation Trace: Maps every execution path to verify the
TenantContextis set before business logic executes and cleared infinallyblocks. - Severity Audit: Executes a checklist of P0 to P2 findings, verifying each against specific file and line references.
- Report Generation: Produces a structured audit report with evidence snippets, risk assessments, and concrete remediation steps.
Frameworks & tools
Built specifically for Spring Boot and Java environments. It analyzes components like Spring Security, Hibernate, Flyway, Redis, Kafka, and PostgreSQL connection poolers like PgBouncer.
Why this beats prompting it yourself
Generic AI reviews often miss the subtle lifecycle of a ThreadLocal or the nuances of how a connection pooler interacts with PostgreSQL schemas. This skill uses a rigid severity-ordered checklist designed specifically for SaaS architecture, ensuring no execution path or caching layer is left unverified.
Use cases
- Reviewing a new microservice for tenant isolation before it goes to production.
- Auditing legacy code for potential data leaks after migrating from row-level to schema-per-tenant.
- Verifying that background workers and cron jobs are correctly scoped to specific tenants.
- Ensuring per-tenant database migrations won't conflict during auto-provisioning.
Known limitations
This is a static analysis tool that reads code only. It cannot detect runtime environmental misconfigurations or infrastructure-level leaks outside of the application code.
How to use
Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 2 days ago
- Passed all security checks, Safe to install