Skip to content

SSO-API · Persistence + Scorecard (branch: master)


Data model — SSOUsers

sso-api/src/entities/sso-user.entity.ts — ตารางเดียวที่ service นี้เป็นเจ้าของ

ColumnPurpose
empCodeรหัสบุคลากร
ssoIdSSO username ที่ provision จาก upstream
IsFirstTimeflag first-login / verify state
(timestamps/audit)ตาม entity definition

Cross-schema reads (ไม่ใช่ของตัวเอง)

TableSchemaUsage
temp_pee_na_tabledbHRMI_Center.dbolookup พนักงานตอน provision (app.service.ts:78-96)
emPersondbHRMI_Center.dboJOIN กับ temp table

temp_pee_na_table shared กับ chat-center-api — ไม่มี ownership contract

DB config

configuration.ts — MSSQL main connection:

  • trustServerCertificate: true, encrypt: false — weak TLS (SEC-SSO-06)
  • Parameterized queries (@0, @1) — ไม่มี SQL injection findings

Env var reference

Env varUsed atRisk
JWT_SECRET_KEYapp.module.ts:17, jwt.strategy.ts:14Required; no default; no .env.example
AES_SECRET_KEY, AES_INIT_VECTORaes-encrypt.ts, aes-decrypt.tsCrypto keys; no length validation
SSO_END_POINTapp.service.ts:22Upstream URL
SSO_USERNAME, SSO_PASSWORDapp.service.ts:23-24Basic Auth to external SSO
SSO_APP_IDapp.service.ts:25App registration
DB_*configuration.tsMSSQL credentials
BASE_PATH, API_VERSION_PATHmain.tsRoute prefix — UNVERIFIED

.env gitignored (ดี) — แต่ ไม่มี .env.example, ไม่มี Dockerfile/CI ใน repo

AppService อ่าน SSO_* ผ่าน raw process.env แทน ConfigService — inconsistent (QUAL-SSO-02)


Severity: Critical / High

CORR-SSO-01 · JWT issuance commented + JwtService not injected

ที่: app.service.ts:27,166-181; app.controller.ts:36-56

Impact: guarded endpoints (signOut, verifySession, request2FA, verify2FA) unreachable ผ่าน normal signIn flow

Remediation:

  1. Inject JwtService ใน constructor
  2. Uncomment + finish sign() หรือ document ว่า JWT มาจากแหล่งอื่น
  3. หรือลบ JWT guard ออกจาก 2FA endpoints ถ้าตั้งใจให้ public หลัง signIn

SEC-SSO-02 · No ValidationPipe — DTO validators dead

ที่: DTOs มี class-validator decorators แต่ main.ts ไม่มี ValidationPipe

Impact: invalid input ผ่านได้ทั้งหมด — validation เป็น documentation เท่านั้น

Remediation: app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }))


Severity: Medium

IDFindingที่มา
SEC-SSO-03signIn catch accesses error.response.data without null-checkapp.service.ts:186-189
SEC-SSO-04checkEmpLogin catch re-throws raw error → stack leakapp.service.ts:137-139
SEC-SSO-05JwtAuthGuard logs full JWT payloadjwt-auth.guard.ts:38-39
SEC-SSO-06MSSQL trustServerCertificate: true, encrypt: falseconfiguration.ts:17-18
SEC-SSO-07signOut/verify2FA return raw axios responseapp.service.ts:213,278
SEC-SSO-08Cross-schema temp_pee_na_table ไม่มี ownershipapp.service.ts:78-96
QUAL-SSO-01verifySession stubapp.service.ts:220-223
QUAL-SSO-02process.env vs ConfigService inconsistentapp.service.ts:22-25
OBS-SSO-01ไม่มี Dockerfile / CI / .env.examplerepo-wide

Severity: Low

IDFindingที่มา
SEC-SSO-09Swagger addBearerAuth() commenteddocument.config.ts:10
SEC-SSO-10Binds 0.0.0.0main.ts:35
SEC-SSO-11strictNullChecks: falsetsconfig.json

Health Scorecard

Dimensionสถานะเหตุผล
Auth pipeline🔴JWT issue commented — flow แตก
Endpoint completeness🔴verifySession stub; 2FA blocked by JWT
Persistence🟡Parameterized OK; cross-schema coupling
Secrets hygiene🟡.env gitignored แต่ไม่มี .env.example
Input validation🔴ValidationPipe ไม่มี
Observability🟡File logger มี; JWT payload log leak
Test coverage🔴Spec แตก (Hello World! vs Running)
Consumer wiring🔴ไม่มี caller ใน monorepo
Deploy artifacts🔴ไม่มี Dockerfile/CI

คะแนนรวม: 0 🟢 / 3 🟡 / 6 🔴


Modernization priority

  1. ตัดสินใจ JWT design — ออก token จาก signIn หรือลบ guard จาก 2FA — ปิด CORR-SSO-01
  2. เพิ่ม ValidationPipe — ปิด SEC-SSO-02
  3. Implement หรือลบ verifySession — ปิด QUAL-SSO-01
  4. เพิ่ม .env.example + Dockerfile — ปิด OBS-SSO-01
  5. Wire เข้า production callers หรือ document ว่า deprecated เทียบ vtrc-api/SSOService/*
  6. หยุด log JWT payload — ปิด SEC-SSO-05

Legacy comparison

PathWho serves it
{vtrcapi}/SSOService/checkEmpLoginvtrc-api gateway (what frontends call)
{sso-api}/checkEmpLoginThis microservice (no proven callers)
Direct SSO in cu-central-apiParallel implementation
Direct SSO in 2way-apiParallel implementation

กลับไป index