Skip to content

3.2.9 · Scorecard + comparison

บทสุดท้ายของ Volume 3.2 สรุป health ของ cu-central-api ตาม dimension เทียบกับ vtrc-api และ outline modernization target


Health scorecard

มิติCurrent StateAfter Wave 0After Wave 2 (target)
Authentication🔴 JWT_SECRET empty default, /auth/signinbypass, hardcoded apiKeys🟡 rotated secrets + hard-fail🟢 go-ldap + golang-jwt + OIDC
Authorization🔴 requires commented out, ignoreAuth bypass🟡 remove bypass + implement RBAC🟢 Casbin + policy test matrix
Data layer🟡 6 connections, SourceDB sharding works + dead dbHRMI_test + HrTimeAttendance miss scope🟡 fix dead dbHRMI_test + missing scope🟢 shard-per-connection + sqlc
Schema🟡 32 SDL files, dead payrollSlip_removed.js, typos in public schema🟡 purge dead files🟢 gqlgen + co-located ops
Integrations🟡 SSO + Conicle + HIS + HRMI + SMS + SMTP — httpRequest.js broken🟡 add timeout/retry + fix axios dep🟢 outbound port adapters
Security🔴 6 Critical + 7 High🟡 Wave 0 ปิดทั้งหมด🟢 strict types + secret manager
Runtime🔴 Node 12 + esm shim + Apollo v2🟡 Node 20 LTS + native ESM🟢 Go runtime
HA / scaling🔴 in-process cron, no rate limit🟡 BullMQ + rate limit🟢 Asynq + autoscaling

Legend

  • 🔴 Critical = active risk
  • 🟡 High = impact จริงแต่มีเงื่อนไข
  • 🟢 Medium/Good = hygiene ที่ทำได้

เปรียบเทียบ cu-central-api vs vtrc-api

Aspectvtrc-apicu-central-api
StackNode 12 + Apollo v2 + Sequelize + MariaDBNode 12 + Apollo v2 + Sequelize + MSSQL
DB connections2 (db + db2)6 (db + dbHr + dbHrTemp + dbMasDb + dbHRMI_test + dbHRMI_Center_HIS)
Auth sourcelocal DB + forward ไป cu-central-apiLDAP/AD direct bind
apiKeyconfig.js (7 prod keys)hardcoded 2 keys ใน controller
JWT default'secret''' (empty)
Schema sizeใหญ่กว่ามาก (queries.js ไฟล์เดียว 4,500 LOC)2,629 LOC SDL + 1,826 LOC resolvers
Multi-tenancysingle DBSourceDB sharding ทุก association
Cronnode-schedule in-processnode-schedule + APP_NO gating
Introspection🔴 true เสมอ🟢 gate ด้วย IS_PRODUCTION
CORS🔴 typo + default *🟢 ไม่ set CORS (delegated ไป nginx)
REST routes77 KB routes.js64 LOC routes.js (5 endpoints)
execSync injection🔴 5 endpoints🟢 ไม่มี
SQL injection🔴 statLog.js🟢 ไม่พบ
File upload🔴 multer no filter🟢 ไม่มี
Rate limit🔴 ไม่มี🔴 ไม่มี
Passwordless signin🟢 ไม่มี🔴 /auth/signinbypass
Modernization targetdecompose เป็นหลาย Go servicesdecompose เป็น identity + hr-data services

cu-central-api ดีกว่า vtrc-api ตรงไหน

  1. ไม่มี execSync injection — ไม่มี PDF/qpdf stack จึงไม่มี vector นี้
  2. ไม่มี SQL injection — ทุก raw query ใช้ parameterized bindings ถูกต้อง
  3. Gate introspection/playground ด้วย IS_PRODUCTION (index.js:77-79) — ไม่ leak schema ใน prod
  4. ไม่มี CORS bug — ไม่ set CORS เลย (delegated ไป nginx)
  5. Session lookup ดีกว่า — Redis key pattern ตรง ไม่ใช่ LIKE '%jwtid%' JSON scan (session.js:18-20)
  6. ไม่มี file upload — ไม่มี multer/path-traversal surface
  7. Error handling ละเอียดกว่า — directive แยก TokenExpiredError vs JsonWebTokenError (directives/auth.js:61-67)

cu-central-api แย่กว่าตรงไหน

  1. JWT_SECRET default empty — แย่กว่า 'secret' ของ vtrc-api เพราะ "" ดูเหมือน "ยังไม่ set" ทำให้มีโอกาสลืม set env
  2. /auth/signinbypass passwordless — endpoint ที่ vtrc-api ไม่มี (routes.js:31-37)
  3. ignoreAuth bypass — pattern ที่ vtrc-api ไม่มี (apiKey อย่างเดียวพอ)
  4. LDAP TLS ปิดrejectUnauthorized: false ใน LDAP connection (activeDirectory.connector.js:21)
  5. 6 DB connections — ซับซ้อนกว่า 2 ของ vtrc-api (และมี dead connection)
  6. SourceDB sharding complexity — pattern ที่ไม่มีใน vtrc-api และมี boilerplate มหาศาล + pattern miss (HrTimeAttendance ไม่มี scope)
  7. apiKeys hardcodedvtrc-api เก็บใน config (แยกไฟล์) แต่ cu-central-api hardcode ใน controller เลย
  8. HrTimeAttendance ไม่มี scope constraint — silent bug ที่อาจทำให้ time attendance ข้าม shard
  9. OTP inconsistencyhrAddress ปิด OTP, hrPhoneNumber ยังเปิด

Modernization target

ตาม audit/05-tech-debt-register.md §5.3 ลำดับ Wave 2

OrderBounded ContextTarget
1document-renderer (จาก vtrc-api)
2identity (รวม cu-central-api auth)Go + Casbin + Postgres
3payroll
4time-attendance
5leave
6welfare
7hr-data (cu-central-api HR queries)Go + per-shard connection

cu-central-api จะถูก decompose เป็น 2 contexts หลัก

identity-service

รับผิดชอบ

  • LDAP/AD bind (ผ่าน go-ldap/ldap/v3)
  • JWT issuance (ผ่าน golang-jwt/jwt/v5)
  • Session store (ผ่าน go-redis)
  • RBAC policy (ผ่าน Casbin)
cmd/
└── identity-service/
internal/identity/
├── domain/         (User, Session, Role, Grant)
├── port/           (Authenticator, SessionStore)
├── adapter/
│   ├── ldap/       (go-ldap adapter)
│   ├── redis/      (session store)
│   └── jwt/        (token signer)
└── usecase/        (login, refresh, logout, authorize)

hr-data-service

รับผิดชอบ

  • HR data read/write (MSSQL per-shard)
  • SourceDB sharding เป็นรายละเอียดภายใน service (ผู้เรียกไม่ต้องรู้)
  • HRMI HTTP API integration
  • HIS heal-card integration
cmd/
└── hr-data-service/
internal/hrdata/
├── domain/         (Employee, Organization, Payroll, ...)
├── port/           (EmployeeRepo, OrgRepo)
├── adapter/
│   ├── mssql/      (per-shard connection pool)
│   ├── hrmi/       (HTTP API client)
│   └── his/        (heal-card API client)
└── usecase/        (getEmployee, updateAddress, ...)

Cross-reference ไป volume อื่น

VolumeTopicRelevance
Volume 2Architecture & Topologycu-central-api ใน topology
Volume 3.1vtrc-api Deep Divecomparison + centralize bridge
Volume 3.3centralize-apiคนละ service (NestJS)
Volume 8Data Model & PersistenceMSSQL schemas
Volume 12Security.env.develop-test + secrets
Volume 19RoadmapGo target

สรุป Volume 3.2

cu-central-api เป็น satellite service ที่โครงสร้างคล้าย vtrc-api ในหลายด้าน แต่มีจุดเด่นเฉพาะตัว

  1. LDAP/AD auth — เป็นเจ้าของ credential verification จริง (vtrc-api forward มา) ผ่าน 2-stage bind (service account → user bind)
  2. SourceDB sharding — pattern ที่ไม่มีใน vtrc-api และเป็นแก่นของ repo (ทุก HR association ต้อง scope)
  3. 6 MSSQL connections — กระจาย 5 schemas + 1 dead (dbHRMI_test)
  4. External integrations — SSO + Conicle + HIS + HRMI + SMS + SMTP (เป็น service เดียวที่เรียก)
  5. Severity — 🔴 6 Critical + 🟡 7 High + 🟢 5 Medium (น้อยกว่า vtrc-api แต่ก็ยังมีจำนวนมาก)

Security posture โดยรวม ดีกว่า vtrc-api ในหลายด้าน (ไม่มี execSync, ไม่มี SQLi, gate introspection ถูก) แต่มี risk เฉพาะตัว (sign-in bypass, LDAP TLS ปิด, JWT empty default, ignoreAuth bypass)

Modernization path ชัดเจน — decompose เป็น identity-service + hr-data-service ใน Go (Volume 19 Roadmap)


Debt ID index ของ Volume นี้

IDSeverityTopicบทที่ detail
SEC-CU-01🔴JWT_SECRET default empty3.2.8
SEC-CU-02🔴apiKeys hardcoded3.2.4, 3.2.8
SEC-CU-03🔴.env.develop-test committed3.2.8, Volume 12
SEC-CU-04🔴/auth/signinbypass passwordless3.2.3, 3.2.8
SEC-CU-05🔴ignoreAuth bypass3.2.4, 3.2.8
SEC-CU-06🔴LDAP rejectUnauthorized: false3.2.3, 3.2.8
LEG-CU-01🔴axois typosquat3.2.8
LEG-CU-02🟡error-ex git URL3.2.8
LEG-CU-03🟡ldapjs unmaintained3.2.8
LEG-CU-04🟡jsonwebtoken@8 CVE3.2.8
LEG-CU-05🟡Node 12 + esm shim3.2.8
LEG-CU-06🟡xlsx CVE history3.2.8
CORR-CU-01🔴httpRequest.js broken import3.2.7, 3.2.8
CORR-CU-02🟡OTP inconsistency3.2.6
CORR-CU-03🟢syncModelToTable ใน prod3.2.2
QUAL-CU-01🟡requires commented out3.2.4
QUAL-CU-02🟢clockTolerance misuse3.2.3, 3.2.8
QUAL-CU-03🟢signInDomains hardcoded3.2.6
OBS-CU-01🟢dbHRMI_test dead connection3.2.2
PERF-CU-01🟢ไม่มี timeout/retry/circuit breaker3.2.7
PERF-CU-02🟢decode token 2 ครั้ง3.2.4
CORR-CU-04🔴HrTimeAttendance ไม่มี scope3.2.5

กลับไป ภาพรวม Volume 3.2 · ไป Volume ถัดไป 3.3 centralize-api