Skip to content

Security, Privacy & Governance (HUB-SEC-001)

Field Value
Document ID HUB-SEC-001
Pillar Data
Standard Alignment OWASP ASVS / ISO 27001 / UU PDP No. 27/2022
Status Active / Synchronized with Codebase
Last Updated 2026-11-21
Source of Truth docs/SECURITY.md, docs/p3mdi-sso.md, supabase/migrations/20261024_secure_auth.sql through 20261130080000_kerapian_kamar_review.sql, src/utils/helpers.js, src/store/portal.js, src/lib/supabase.js, src/lib/livePhotoLocation.js, ops/p3mdi-sso/*.ts, ops/authentik/p3mdi_hub/permissions.py, google-apps-script/Code.gs, vercel.json, nginx.conf, .github/workflows/portal.yml, tests/security.test.mjs, tests/sql/*.sql

1. Security Posture & Historical References

Section titled “1. Security Posture & Historical References”

Soedirman Hub transitioned in October 2026 from an unauthenticated client-trusted prototype to a fail-closed database-enforced platform.

  • For the original October 2026 vulnerability remediation baseline (C1–C4, H1–H4, M1–M7), see SECURITY.md.
  • For the P3MDI Authentik OIDC pilot background and operational rollout notes, see p3mdi-sso.md.

This document defines the current end-to-end data classification, authentication architecture, RBAC/RLS matrix, privacy engineering controls, HTTP edge hardening, and CI security gates synchronized with all 39 SQL migrations.


2. Data Classification & PII Inventory (UU PDP Alignment)

Section titled “2. Data Classification & PII Inventory (UU PDP Alignment)”
Classification Examples / Tables / Fields Protection Mechanism
Critical / Credentials & Secrets pin_hash, sessions.token_hash, P3MDI_OIDC_CLIENT_SECRET, P3MDI_ACCOUNT_API_TOKEN, SUPABASE_SECRET_KEY, PORTAL_DEPLOY_KEY Bcrypt (gen_salt('bf', 8)); 32-byte tokens stored only as SHA-256 hashes; portal_private & core_cache revoked from anon/authenticated; Deno broker & CI secrets isolated outside browser bundle; Gitleaks commit scan.
Restricted Personal Data (UU PDP) serdik.telepon, serdik.email, serdik.alamat, serdik.tanggal_lahir; pendampingan_cases/notes; daily_condition_entries; izin_bermalam_checkins selfie + lat/lng; info_digital_screenshots Direct column SELECT revoked on public.serdik; masked in portal_serdik_directory; Pendampingan & Daily Condition locked in portal_private with strict actor scope; IB selfies & coords purged 168h after ends_at; Info Digital strips JPEG EXIF APPn/COM markers & breaks reporter-report linkage.
Confidential Operational Data absensi_apel, absensi_lock, korps_reports, pengasuh_reports, kamar_submissions / kamar_reviews, saran (WBS), live_attendance_photos, sso_audit Enforced via RLS policies reading portal_private.current_session() or SECURITY DEFINER RPCs; anonymous saran entries invisible even to submitter after INSERT; photo GPS accuracy capped <= 100 m, fix age <= 15 s.
Internal Cohort Directory & Metadata serdik (id, nosis, nama, grup, elemen, asal_institusi, role), pengasuh, rundown_harian, commander_intents, rabuan_sessions, korps_bidang Exposed only to active sessions (portal_private.current_session()) or masked directory view (portal_serdik_directory).

3. Dual Authentication & Re-Authentication Architecture

Section titled “3. Dual Authentication & Re-Authentication Architecture”

Soedirman Hub supports two server-verified login paths that both terminate in the same 12-hour opaque session token (x-portal-token, 64 lowercase hex characters = 32 random bytes, SHA-256 hashed in portal_private.sessions):

  1. NOSIS / NRP + 6-Digit PIN (portal_login):
    • Verifies bcrypt pin_hash inside Postgres (pgcrypto). If the user is unknown, performs a dummy crypt(..., gen_salt('bf', 8)) check to equalize timing.
    • Rejects archived/deactivated P3MDI Core members (core_is_active = false, migration 20261129).
    • Enforces sliding 15-minute brute-force lockouts inside portal_private.login_attempts: 5 failed attempts per user_type:code | client_ip (cf-connecting-ip, IPv6 /64 masked) and 50 failed attempts per client IP. Only super_admin can clear locks via portal_admin_unlock_login.
    • Enforces PIN strength server-side (portal_private.is_weak_pin) and client-side (validateNewPin in src/utils/helpers.js): rejects non-6-digit strings, repeated digits (000000), ascending/descending sequences, and weak lists (123456, 654321, 012345, 543210, 123123, 112233, 121212). Changing PIN invalidates all other active sessions (token_hash <> v_token_hash).
  2. P3MDI Authentik OIDC PKCE (ops/p3mdi-sso/ + portal_login_p3mdi):
    • Browser performs PKCE S256 (code_verifier, state, nonce) against https://auth.p3mdi.id/application/o/authorize/.
    • Deno SSO broker exchanges code + client_secret + verifier at /application/o/token/, cryptographically verifies id_token (RS256 against remote JWKS, issuer, aud/azp, nonce, maxTokenAge: 5 minutes), resolves Authentik PK, and calls portal_login_p3mdi via service_role.
    • Authentik Django extension ops/authentik/p3mdi_hub/permissions.py automatically grants soedirman-hub-sso-admin Guardian object permissions solely for internal, non-superuser accounts inside group Soedirman Hub Serdik.
  3. Onboarding Session Boundary (20261116 & 20261126):
    • portal_private.session_identity() resolves users with must_change_pin = true, permitting only portal_me, portal_logout, and /api/sso/setup (portal_setup_*).
    • portal_private.current_session() adds WHERE NOT s.must_change_pin, failing closed for every RLS policy and operational RPC until onboarding finishes (portal_setup_finish).
  4. Fresh OIDC Step-Up Confirmation (20261127):
    • Sensitive SSO mutations (PATCH /api/sso/profile, DELETE /api/sso/link, /api/sso/security password change, /api/sso/sessions, /api/sso/accounts mutations & password resets) require a 5-minute portal_private.sso_confirmations record created only after a prompt=login&max_age=0 OIDC callback verified within [now - 300s, now + 30s] for the same linked user.

4. Role-Based Access Control (RBAC) & Scoped Delegation

Section titled “4. Role-Based Access Control (RBAC) & Scoped Delegation”

4.1 Recognized Roles (serdik_role_check & src/utils/constants.js)

Section titled “4.1 Recognized Roles (serdik_role_check & src/utils/constants.js)”
Role Key Label Operational Scope & Privileges
super_admin Super Admin Full read/write across operational modules, master data CRUD (AdminConsoleView), category/audit management, IB retention control, login unlock, PIN/SSO admin management, and AdminRoleSwitcher preview.
komandan_batch Komandan Batch Batch-wide read (canViewAll), Danbatch report, Commander's Intent authoring, batch Korps & Pengasuh finalization, read-only AdminConsoleView (no write/SSO admin actions), Dokumentasi read-only.
kabid_sdm Kabid SDM Batch attendance monitoring, rundown_harian edit, notulensi_apel write, saran triage (manageSaran), masked PII read in portal_serdik_directory.
kabid_ops Kabid Ops Access to /operasional, calendar/live-photo management (canEditCalendar, canManageLivePhotoAttendance), PAM/package oversight, batch attendance monitoring, rundown_harian edit.
komandan_grup Komandan Grup Group-scoped attendance input, absensi_lock verification/unlock (verifyAbsensi), package review, scoped live photo review, kerapian-kamar & pendampingan (including designated Wadan Grup deputy accounts), saran triage, scoped telephone access.
komandan_elemen Komandan Elemen Element-scoped attendance input restricted to time windows (05:00-08:00 / 19:00-22:00 WIB + PRESENSI_OPEN_BEFORE_HOURS = 2h before apel, blocked once absensi_lock.locked = true), scoped package review, scoped kerapian-kamar read.
poldik Poldik Poldik discipline workspace (/poldik), batch attendance read, PAM/package review, rundown_harian edit, notulensi_apel write.
penerangan Penerangan & Dokumentasi Legacy dokumentasi merged here (20261026). Exclusive non-admin upload/gallery view (/dokumentasi, /dokumentasi/upload, /dokumentasi/laporan-harian/cetak), article approval (canAccArtikel), Commander's Intent co-management, notulensi_apel write, GAS Drive upload.
lemusdik Lemusdik Manages saran / Kotak Aspirasi status & responses (manageSaran).
pengasuh Pengasuh / Pelatih Batch attendance read, Danbatch report, notulensi_apel write/delete, TNI instructor reporting (PengasuhReportsWorkspace), supervising batch matrix (20261130070000), group-scoped kerapian-kamar & pendampingan.
serdik Serdik Personal attendance summary/streak (AbsensiPribadi), daily rundown, learning, peer appreciation (sosiometri), WBS/aspirasi submission, PAM/IB check-in, Info Digital anonymous reporting (5/day quota), self-service SSO profile.

4.2 Delegated Scoped Duties (20261130010000_scoped_duties.sql)

Section titled “4.2 Delegated Scoped Duties (20261130010000_scoped_duties.sql)”
  • portal_private.scoped_grants allows authorized issuers (super_admin, komandan_batch, komandan_grup, komandan_elemen, kabid_ops, kabid_sdm, pengasuh where may_delegate_duty permits) to issue time-bounded (starts_at < ends_at, subject <> issuer) kasi or pic duties over specific unit/grup/elemen/bidang scopes via portal_scoped_duties(), dynamically extending Korps report/proker and Kerapian Kamar (kasi) review access without elevating base roles.

4.3 Security Safeguards for AdminRoleSwitcher (20261120_admin_role_switch.sql)

Section titled “4.3 Security Safeguards for AdminRoleSwitcher (20261120_admin_role_switch.sql)”
  • Only sessions whose real role is super_admin (verified inside Postgres portal_switch_role) can write portal_private.sessions.preview_role.
  • effective_role() invariant: Any komandan_batch, kabid_*, or serdik record with stale or tampered preview_role resolves strictly to p_real_role. Switching to super_admin is disallowed as a preview target (preview_role clears to NULL).
  • Frontend stores preview metadata strictly in sessionStorage['soedirman_admin_role_preview_v1'] (never localStorage), blocks role switching in demo mode, and immediately routes away from restricted tabs via getFallbackRouteForUser() + reloads data.

Data Domain Read (SELECT) Gate Write / Mutate Gate Key Privacy / Fail-Closed Nuances
serdik & portal_serdik_directory Masked columns via portal_serdik_directory (security_barrier = true, security_invoker = false) super_admin only (updateSerdik routes Core-owned fields through /api/sso/core) Critical invariant: portal_serdik_directory MUST keep security_invoker = false and match owner with public.serdik; setting security_invoker = true breaks all syncs with HTTP 42501.
absensi_apel & absensi_lock Serdik reads own rows only; command/ops/pengasuh/poldik read all (can_view_all_absensi()) Insert/Update by super_admin, komandan_grup (own group), komandan_elemen (own group+elemen, open WIB window & unlocked) Post-lock corrections require portal_correct_attendance RPC (komandan_grup / super_admin).
live_attendance_photos Owner, command review scope (can_review_scoped_photo), kabid_ops, komandan_batch, super_admin Owner insert/upsert matching id = tanggal__sessionKey__owner_code Metadata projection strips photoUrl, gps, locationName. GPS constraint enforces accuracy <= 100 m & fix_age_ms <= 15000 ms.
saran (WBS & Aspirasi) super_admin, komandan_batch, lemusdik, kabid_sdm, komandan_grup; reporters see own non-anonymous only (NOT is_anonim) Any active session INSERT (return=minimal); UPDATE by manageSaran roles Frontend sends INSERT without ON CONFLICT so anonymous submitters cannot probe rows via SELECT.
dokumentasi & commander_intents Docs: penerangan, komandan_batch, super_admin; Intents: all active sessions Docs: penerangan (delete own) / super_admin; Intents: komandan_batch, super_admin, penerangan stamp_commander_intent trigger prevents author spoofing.
korps_* & pengasuh_* Denied to anon/authenticated direct REST; served via SECURITY DEFINER RPCs Scope-checked per bidang / tingkat / unit_id + optimistic version lock Batch view opened to pengasuh via 20261130070000 for supervisory visibility.
portal_private.* (pendampingan, daily_condition, info_digital, kamar_*, ib_*, sessions, sso_*) Zero direct REST access (REVOKE ALL ... FROM PUBLIC, anon, authenticated) Exclusively through audited SECURITY DEFINER RPCs checking current_session() Eliminates accidental PostgREST data leakage even if a schema cache reload occurs.

6. Privacy Engineering Controls (Indonesian UU PDP Compliance)

Section titled “6. Privacy Engineering Controls (Indonesian UU PDP Compliance)”
  1. IB Selfie & Coordinate Minimization & Auto-Purge (20261130020000):
    • izin_bermalam_checkins stores coarse coordinates (client rounds GPS coordinates) and is governed by portal_ib_retention.
    • When enabled in AdminConsoleView (Data & Privasi -> IbRetentionPanel), run_ib_retention automatically nulls latitude, longitude, and foto_selfie_url and stamps evidence_removed_at once an IB period’s ends_at + 168 hours (7 days) elapses—preserving attendance/compliance audit metadata. Retention logs append to ib_retention_history.
  2. Info Digital Exif Stripping & Reporter Anonymity (20261130060000):
    • portal_info_digital_clean_jpeg(bytea) strips JPEG APP1..APP15 (0xFFE1–0xFFEF) and COM (0xFFFE) segments inside PostgreSQL before storing evidence (<= 2.1 MB), eradicating device EXIF GPS/camera metadata.
    • Daily quota (5/day WIB) tracks reporter_nosis solely in info_digital_quota with no foreign key or timestamp correlation to info_digital_reports.
  3. Photo GPS Anti-Spoof Validation (src/lib/livePhotoLocation.js & 20261130030000):
    • Client & server require valid GPS fix (accuracy <= 100 m, 0 <= fix_age_ms <= 15000), detect impossible movement jumps / repeated identical precise coordinates (assessPhotoLocation), and optionally reverse-geocode via a same-origin proxy (VITE_NOMINATIM_REVERSE_URL) without transmitting high-precision coordinates to public views (metadata strips gps & locationName).
  4. Full Client Cache & IndexedDB Purge on Logout (src/store/portal.js):
    • logoutUser() invokes purgeBrowserCaches(), removing STORAGE_KEY, p3md_gmaps_api_key, legacy/module localStorage keys, all soedirman-outbox-v1:* entries, ADMIN_ROLE_PREVIEW_KEY, and closing/clearing IndexedDB (soedirman-attendance-photos).

7. HTTP Edge Headers, CORS & CI Security Gates

Section titled “7. HTTP Edge Headers, CORS & CI Security Gates”

7.1 HTTP Security Headers Parity (vercel.json & nginx.conf)

Section titled “7.1 HTTP Security Headers Parity (vercel.json & nginx.conf)”

Both deployment targets enforce identical security headers (using always in nginx.conf):

  • X-Frame-Options: DENY
  • X-Content-Type-Options: nosniff
  • Referrer-Policy: strict-origin-when-cross-origin
  • Strict-Transport-Security: max-age=63072000; includeSubDomains
  • Permissions-Policy: camera=(self), microphone=(), geolocation=(self), payment=() (allows camera & GPS for self-origin attendance/IB while blocking microphone & payments)
  • Content-Security-Policy: default-src 'self'; script-src 'self' https://maps.googleapis.com https://maps.gstatic.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: blob: https:; connect-src 'self' https://*.supabase.co https://script.google.com https://script.googleusercontent.com https://maps.googleapis.com https://maps.gstatic.com https://mapsresources-pa.googleapis.com https://streetviewpixels-pa.googleapis.com; worker-src 'self' blob:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'

7.2 Deno SSO Broker Origin & Body Guards (ops/p3mdi-sso/index.ts & compose.yaml)

Section titled “7.2 Deno SSO Broker Origin & Body Guards (ops/p3mdi-sso/index.ts & compose.yaml)”
  • Enforces strict Origin equality (P3MDI_HUB_ORIGIN) on all mutating HTTP requests (!= GET) and rejects mismatched Origin headers with HTTP 403.
  • Traefik middleware (soedirman-hub-sso-body) caps request bodies at 8192 bytes.
  • Every broker response sends Cache-Control: no-store and Vary: Origin.

7.3 CI Security & Static Invariant Gates (.github/workflows/portal.yml)

Section titled “7.3 CI Security & Static Invariant Gates (.github/workflows/portal.yml)”
  1. npm audit --audit-level=high blocks High/Critical dependency vulnerabilities.
  2. ghcr.io/gitleaks/gitleaks (pinned digest, full Git history git --redact --log-opts=HEAD .) blocks leaked credentials.
  3. tests/security.test.mjs asserts fail-closed env configuration, GAS HTTPS host allowlist, removal of legacy offline tokens/backdoors (LOCAL_STANDALONE_USERS, isOfflineToken, hardcoded URLs), RLS checks across operational migrations, and portal_serdik_directory security_invoker = false.

Risk Current Status / Mitigation Target Remediation
Google Drive Media Storage Governance google-apps-script/Code.gs validates portal_me + role gate, enforces <= 8 MB image MIME allowlist, and still sets uploaded files to ANYONE_WITH_LINK (VIEW) inside Drive. kerapian_kamar (kamar_submission_media) & dokumentasi store resulting URLs. Migrate binary evidence (dokumentasi, sosiometri, live_attendance_photos, kamar_submission_media) to private Supabase Storage buckets accessed exclusively via short-lived signed URLs (createSignedUrl), deprecating Code.gs and ANYONE_WITH_LINK sharing (detailed plan in SECURITY.md).
Dual Client/SQL State on Legacy Modules izin_keluar, catatan_disiplin (poldikService.js), and operasionalService.js tables exist in migrations 20261116_perizinan_ib.sql / 20261116_poldik_operasional.sql with legacy auth.uid() policies while active Vue views read/write localStorage. Migrate izin_keluar, poldik, and operasional to SECURITY DEFINER RPCs backed by portal_private.current_session() (mirroring 20261130020000_ib_retention.sql & 20261130050000_pendampingan.sql).
Client-Entered Google Maps API Key PetaPersebaranView.vue permits users to save a Maps JS key in localStorage (p3md_gmaps_api_key). Replace with HTTP-referrer-restricted build-time key or open-source Leaflet tiles to remove localStorage key storage.
Multi-User Shared Device Caching While logout wipes localStorage + IndexedDB, abrupt browser close leaves p3md_portal_session_v1 valid for up to 12 hours. Users on shared cohort terminals must click Logout; consider configurable idle timeout lock in future release.