Security
AICR implements enterprise-grade security with multi-tenant isolation, policy enforcement, and comprehensive audit trails.
Tenant Isolation
RealmKey System
Every operation is scoped to a tenant via RealmKey:
class RealmKey {
readonly tenantId: string;
readonly env: 'lab' | 'stage' | 'prod';
static async fromSlug(slug: string): Promise<RealmKey>;
static async fromRequest(request: NextRequest): Promise<RealmKey>;
}Tenant Context
AsyncLocalStorage-based context propagation:
import { withTenantContext } from '@/lib/auth/context';
const result = await withTenantContext(
{ userId: 'user-123', tenantId: 'tenant-abc' },
async () => {
// All Prisma queries automatically scoped to tenant
return prisma.task.findMany();
}
);Prisma Middleware
Automatic tenant filtering on all database operations:
- Query filtering adds
tenantIdto WHERE clauses - Create operations inject
tenantId - Cross-tenant access blocked at database layer
Policy Enforcement
AI Interceptor
All AI model invocations go through 7-step gating:
- Context extraction
- Policy lookup
- Policy evaluation
- Risk classification
- Approval check
- Execution/proposal creation
- Evidence recording
Proposal Governance
Significant actions require formal proposals:
- Automatic approval for low-risk actions
- Human approval for high-risk actions
- Audit trail for all decisions
Audit Trail (Spine)
Immutable event log for compliance:
- All governance events recorded
- Cryptographic integrity
- Evidence chain for proposals
- Compliance reporting
Security Headers
Standard security headers applied:
- CORS restricted to allowed origins
- Content-Type enforcement
- X-Tenant-ID header required for API calls
Best Practices
- Always use
RealmKeyfor tenant context - Wrap database operations in
withTenantContext - Never expose tenant IDs in URLs
- Log all security-relevant events to Spine
- Use policy engine for access decisions