Taryana
Zero-Leak Property GuardSecurity & Authorization
TESTER READY • LIVE ENGINE

Multi-Tier Scoped RBAC

Zero-Leak Property Scoping & Cross-Tenant IDOR Prevention

Hirarki 4 peran (Superadmin, Admin, Manager, Frontdesk) dengan pembatasan domain (scoping) ketat untuk mencegah kebocoran data antar-penyewa properti.

Diagram Alur Data & Arsitektur Sistem

Visual Interaktif

Diagram Keputusan Otorisasi PropertyScopeGuard

Verifikasi hak akses hirarki peran dan isolasi properti tenant

client
Auth

Incoming Request

JWT Bearer Token

Bearer Token
guard
Identity

JwtAuthGuard

Extract user & role

user { role, propertyId }
guard
Enforcement

PropertyScopeGuard

user.propertyId === target

Matches / Operator role
service
Granted

Controller Access

200 OK (Authorized)

Property mismatch
guard
IDOR Blocked

Security Rejection

403 Forbidden (Blocked)

Zero-Leak Scope Guarantee: PropertyScopeGuard mengecek kesamaan user.propertyId dan target sebelum akses ke layer database diizinkan.
100% IDOR-Safe

Problem & Latar Belakang Kebutuhan

Platform melayani puluhan hotel dan pengelola properti sekaligus dalam satu basis data terpusat (multi-tenancy). Tanpa scoped authorization guard, celah Insecure Direct Object Reference (IDOR) dapat terjadi di mana Manager Hotel A dapat memodifikasi video sambutan, tarif amenities, atau daftar tamu milik Hotel B hanya dengan mengganti parameter propertyId pada URL request.

Implementasi Rekayasa Backend NestJS

NestJS mengimplementasikan PropertyScopeGuard. Jika caller adalah Superadmin atau Admin, akses granted ke seluruh properti terdaftar untuk keperluan pemeliharaan platform. Jika caller adalah Manager atau Frontdesk, guard memverifikasi apakah user.propertyId pada token JWT cocok dengan target propertyId pada route parameter atau body payload. Jika tidak cocok, request langsung diputus dengan HTTP 403 Forbidden.

Aspek Model Database MongoDB

Setiap dokumen konten, perangkat, dan log selalu memiliki field propertyId yang terindeks secara unik: db.property_contents.createIndex({ propertyId: 1 }). Kueri tenant dipastikan selalu menyertakan filter propertyId yang divalidasi guard.

Keamanan, Idempotensi & Kepatuhan SLA

Mencegah eksploitasi horizontal privilege escalation secara deterministik di layer guard sebelum kode controller sempat memanggil database.

NestJS PropertyScopeGuard ImplementationNestJS (TypeScript)
// PropertyScopeGuard: Pencegah IDOR Lintas-Penyewa
@Injectable()
export class PropertyScopeGuard implements CanActivate {
  canActivate(context: ExecutionContext): boolean {
    const { user, params, body } = context.switchToHttp().getRequest();
    const targetProperty = params.propertyId || body.propertyId;

    // Superadmin & Admin memiliki akses operator penuh
    if (user.role === 'superadmin' || user.role === 'admin') {
      return true;
    }

    // Manager & Frontdesk dibatasi hanya pada propertinya sendiri
    if (user.role === 'manager' || user.role === 'frontdesk') {
      if (user.propertyId?.toString() === targetProperty) {
        return true;
      }
      throw new ForbiddenException('Akses Ditolak: Anda tidak memiliki izin untuk properti ini.');
    }

    throw new ForbiddenException('Role tidak memiliki izin akses.');
  }
}

Live Simulator & Execution Sandbox

Interactive State Tester
Execution Telemetry Console
HTTP 201 Created
POST/api/v1/properties/contracts
> Guard Evaluation Trace:

RolesGuard verified caller is 'admin'. Idempotency Key verified in Redis. MongoDB document updated.

> Database & State Result:

Contract for 'Grand Horizon Hotel & Resort' persisted into Property document with 1-Year validity.

Audit Trail MongoDB (2 events)Auto-Appended
[10:14:02]ADMIN(Rian (Platform Admin))•PROPERTY_CONTRACT_PROVISIONED

Provisioned 1-Year Platinum Contract #PKS-2026-042 via manual B2B order.

SUCCESS
[10:22:15]MANAGER(Ahmad (IT Manager))•WELCOME_CONTENT_MUTATED

Updated welcome video banner and personalized TV dining directory.

SUCCESS