Notice: Testing and improvement activities are currently in progress. Some areas may experience temporary disruptions.

BAYAKA
— Home
← All posts
Cybersecurity, Zero-Trust & RBAC3 min read·

Zero-Trust RBAC and Multi-Tenant Architecture in Enterprise SaaS Platforms

How we enforce strict tenant isolation, server-side permission guards, and immutable audit trails in Next.js 14 and PostgreSQL.

SECURITY COREBAY · YA · KA
ZERO-TRUST · RBAC · OWASP
Share𝕏
Table of contents

Why Client-Side Role Checks Are Never Enough

In enterprise B2B software, hiding a button in the UI is not security. Every Server Action, API Route, and database query must independently verify both the user's session and their tenant boundary.

Security Principle: Never trust client-supplied tenant IDs or role flags; always resolve identity from the server-side session token.

Our 3-Layer Isolation Pattern at BAYAKA Yazılım

  1. 1Session & Origin Verification: HTTP-only signed session tokens combined with strict Origin / Host CSRF validation.
  2. 2Permission Matrix (`can(role, permission)`): Centralized RBAC matrix separating SUPER_ADMIN, ADMIN, PROJECT_MANAGER, DEVELOPER, and CUSTOMER.
  3. 3Row-Level Query Scoping: Customer portal queries explicitly scope every Prisma call with where: { customerId: user.customerId } so cross-tenant data leakage is mathematically impossible.
typescript
BAYAKA CODE
export async function requirePortalProject(projectId: string) {
  const user = await requireSessionUser();
  if (!user.customerId) throw new HttpError(403, "forbidden");
  return db.project.findFirstOrThrow({
    where: { id: projectId, customerId: user.customerId },
  });
}

Immutable Audit Logging

Every administrative mutation—whether updating a quotation, changing a role, or exporting subscriber lists—is recorded in AuditLog with actor ID, entity reference, and timestamp.

BAY

Written by

Hakan Bayat

Co-founder of BAYAKA Software.

Meet the team →