multi-tenant-safety

Enforces tenant isolation rules to prevent cross-tenant data leaks in backend code.

1.0k|109|Updated Jan 4, 2026
One-click install
npx skills add https://github.com/doccker/cc-use-exp --skill multi-tenant-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: multi-tenant-safety
Source: https://github.com/doccker/cc-use-exp/tree/main/.cursor/skills/multi-tenant-safety
Command: npx skills add https://github.com/doccker/cc-use-exp --skill multi-tenant-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Multi-tenant systems often leak data across tenants because developers trust request headers, forget tenant filters in queries, or rely on frontend-only feature gating. This Skill provides a checklist-driven set of rules to prevent tenant privilege escalation and cross-tenant data access.

Core Features & Use Cases

  • Tenant Context Validation: Ensures the tenant identity comes from the authenticated token, not forgeable headers like X-Tenant-Code, with 403 responses on mismatch.
  • Query-Level Isolation: Detects unsafe patterns like bare findById calls that bypass Hibernate filters, and mandates tenant-aware repository methods such as findByTenantIdAndId.
  • Feature-Level Authorization: Distinguishes data isolation from functional authorization, requiring backend endpoint checks instead of hiding buttons in the frontend.
  • Use Case: When reviewing a Spring Boot service that queries orders by ID, the Skill flags missing tenantId filters and provides corrected repository and interceptor code, plus grep commands for auditing.

Quick Start

Review this Spring Boot service and repository code for multi-tenant isolation issues using the multi-tenant-safety rules.

Frequently Asked Questions about multi-tenant-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent cross-tenant data leaks in Spring Boot?

Combine a global tenant filter (Hibernate @Filter or MyBatis interceptor) with tenant-aware repository methods like findByTenantIdAndId. Bare findById calls can bypass entity filters through the persistence context or second-level cache, so Service-layer queries should always include tenantId.

Why is trusting the X-Tenant-Code header insecure?

Request headers can be forged by any client, so an attacker can pair their own token with another tenant's header to read foreign data. The header should only route requests, and the tenantId from the authenticated token must be validated against it, returning 403 on mismatch.

What is the difference between data isolation and feature-level authorization?

Data isolation controls which rows a tenant can see, while feature-level authorization controls which functionality a tenant, role, or subscription tier can use. Hiding a button in the frontend is not a security boundary; the backend endpoint must independently validate eligibility and return 403.

Does this multi-tenant guidance work with Go Gin or Node.js Express?

Yes, the references directory includes complete implementations for Go Gin middleware factories, Express handlers, and NestJS Guards alongside the Java Spring Boot AOP examples. The same principles apply to Python FastAPI with SQLAlchemy.

How do I audit existing code for missing tenant filters?

Grep the Service layer for bare findById, getOne, getReferenceById, and findAllById calls, which bypass entity filters. Also check that every Repository defines findByTenantIdAndId and findByTenantIdAndIdIn methods, and optionally fail CI builds on violations.