SSO-API · Persistence + Scorecard (branch: master)
Data model — SSOUsers
sso-api/src/entities/sso-user.entity.ts — ตารางเดียวที่ service นี้เป็นเจ้าของ
| Column | Purpose |
|---|---|
empCode | รหัสบุคลากร |
ssoId | SSO username ที่ provision จาก upstream |
IsFirstTime | flag first-login / verify state |
| (timestamps/audit) | ตาม entity definition |
Cross-schema reads (ไม่ใช่ของตัวเอง)
| Table | Schema | Usage |
|---|---|---|
temp_pee_na_table | dbHRMI_Center.dbo | lookup พนักงานตอน provision (app.service.ts:78-96) |
emPerson | dbHRMI_Center.dbo | JOIN กับ 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 var | Used at | Risk |
|---|---|---|
JWT_SECRET_KEY | app.module.ts:17, jwt.strategy.ts:14 | Required; no default; no .env.example |
AES_SECRET_KEY, AES_INIT_VECTOR | aes-encrypt.ts, aes-decrypt.ts | Crypto keys; no length validation |
SSO_END_POINT | app.service.ts:22 | Upstream URL |
SSO_USERNAME, SSO_PASSWORD | app.service.ts:23-24 | Basic Auth to external SSO |
SSO_APP_ID | app.service.ts:25 | App registration |
DB_* | configuration.ts | MSSQL credentials |
BASE_PATH, API_VERSION_PATH | main.ts | Route 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:
- Inject
JwtServiceใน constructor - Uncomment + finish
sign()หรือ document ว่า JWT มาจากแหล่งอื่น - หรือลบ 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
| ID | Finding | ที่มา |
|---|---|---|
| SEC-SSO-03 | signIn catch accesses error.response.data without null-check | app.service.ts:186-189 |
| SEC-SSO-04 | checkEmpLogin catch re-throws raw error → stack leak | app.service.ts:137-139 |
| SEC-SSO-05 | JwtAuthGuard logs full JWT payload | jwt-auth.guard.ts:38-39 |
| SEC-SSO-06 | MSSQL trustServerCertificate: true, encrypt: false | configuration.ts:17-18 |
| SEC-SSO-07 | signOut/verify2FA return raw axios response | app.service.ts:213,278 |
| SEC-SSO-08 | Cross-schema temp_pee_na_table ไม่มี ownership | app.service.ts:78-96 |
| QUAL-SSO-01 | verifySession stub | app.service.ts:220-223 |
| QUAL-SSO-02 | process.env vs ConfigService inconsistent | app.service.ts:22-25 |
| OBS-SSO-01 | ไม่มี Dockerfile / CI / .env.example | repo-wide |
Severity: Low
| ID | Finding | ที่มา |
|---|---|---|
| SEC-SSO-09 | Swagger addBearerAuth() commented | document.config.ts:10 |
| SEC-SSO-10 | Binds 0.0.0.0 | main.ts:35 |
| SEC-SSO-11 | strictNullChecks: false | tsconfig.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
- ตัดสินใจ JWT design — ออก token จาก
signInหรือลบ guard จาก 2FA — ปิด CORR-SSO-01 - เพิ่ม ValidationPipe — ปิด SEC-SSO-02
- Implement หรือลบ
verifySession— ปิด QUAL-SSO-01 - เพิ่ม
.env.example+ Dockerfile — ปิด OBS-SSO-01 - Wire เข้า production callers หรือ document ว่า deprecated เทียบ
vtrc-api/SSOService/* - หยุด log JWT payload — ปิด SEC-SSO-05
Legacy comparison
| Path | Who serves it |
|---|---|
{vtrcapi}/SSOService/checkEmpLogin | vtrc-api gateway (what frontends call) |
{sso-api}/checkEmpLogin | This microservice (no proven callers) |
Direct SSO in cu-central-api | Parallel implementation |
Direct SSO in 2way-api | Parallel implementation |
กลับไป index →