tenancy-enforcer

Enforce communityId in MongoDB query filters for multi-tenant isolation.

Updated Jan 5, 2026
One-click install
npx skills add https://github.com/muhammadcaeed/aegis --skill tenancy-enforcer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tenancy-enforcer
Source: https://github.com/muhammadcaeed/aegis/tree/main/.claude/skills/tenancy-enforcer.md
Command: npx skills add https://github.com/muhammadcaeed/aegis --skill tenancy-enforcer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Multi-tenant data isolation by enforcing communityId in every database filter, preventing cross-tenant access.

Core Features & Use Cases

  • Enforces presence of communityId in all find, update, delete, and aggregate operations.
  • Provides repository/service patterns to consistently apply tenancy rules across code paths.
  • Highlights common anti-patterns to avoid insecure queries.

Quick Start

Apply this skill to all MongoDB interactions by ensuring every query includes communityId from the JWT context.

Frequently Asked Questions about tenancy-enforcer

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

FAQPage Schema
How do I enforce multi-tenant data isolation in MongoDB queries?▼

Multi-tenant data isolation in MongoDB queries is enforced by requiring a communityId field in every database filter. This prevents cross-tenant access by ensuring all find, update, delete, and aggregate operations are scoped to the correct tenant.

Why should communityId come from the JWT context instead of the request body?▼

CommunityId should come from the JWT context to prevent tenants from spoofing access to other communities. Extracting it from authenticated controller context rather than user-supplied request bodies ensures consistent and secure tenant scoping across all repository methods.

What's the best way to prevent cross-community access in repository service layers?▼

The best way to prevent cross-community access is applying repository and service patterns that consistently inject communityId into all database operations. This approach standardizes tenancy rules across code paths and highlights common anti-patterns to avoid insecure queries.

Does multi-tenant isolation apply to MongoDB aggregate operations as well as find queries?▼

Yes, multi-tenant isolation applies to MongoDB aggregate operations, find, update, and delete queries. Strict data isolation requires communityId to appear in every database filter to prevent cross-tenant access across all operation types.

What are common anti-patterns when writing multi-tenant MongoDB queries?▼

Common anti-patterns include omitting communityId from database filters, accepting it from request bodies, and applying inconsistent tenancy rules across code paths. These insecure queries allow cross-tenant data access and break strict multi-tenant isolation.