260322:1648 Correct Coresspondence / Doing RFA / Correct CI
CI Pipeline / build (push) Failing after 12m41s
Build and Deploy / deploy (push) Failing after 2m44s

This commit is contained in:
admin
2026-03-22 16:48:12 +07:00
parent e5deedb42e
commit 11984bfa29
683 changed files with 105251 additions and 29068 deletions
@@ -4,12 +4,12 @@
โครงสร้างประกอบด้วย:
* Objectives
* Deliverables
* Task Breakdown (ละเอียดเป็นลำดับงาน)
* Developer Checklist
* Test Coverage
* Dependencies & Risks
- Objectives
- Deliverables
- Task Breakdown (ละเอียดเป็นลำดับงาน)
- Developer Checklist
- Test Coverage
- Dependencies & Risks
---
@@ -19,73 +19,73 @@
## ✔ Deliverables
* Global ValidationPipe
* Sanitization Layer
* Rate Limit Rules (anonymous/authenticated)
* Security Headers (Helmet)
* XSS / SQL Injection safeguards
* Security Tests
- Global ValidationPipe
- Sanitization Layer
- Rate Limit Rules (anonymous/authenticated)
- Security Headers (Helmet)
- XSS / SQL Injection safeguards
- Security Tests
## 🛠 Task Breakdown
### 2A.1 Validation Pipeline
* ตั้งค่า Global ValidationPipe
* เปิด whitelist, forbidNonWhitelisted
* เพิ่ม custom exception mapping → ErrorModel
* เชื่อม RequestIdInterceptor
- ตั้งค่า Global ValidationPipe
- เปิด whitelist, forbidNonWhitelisted
- เพิ่ม custom exception mapping → ErrorModel
- เชื่อม RequestIdInterceptor
### 2A.2 Input Sanitization Layer
* ติดตั้ง sanitize-html หรือ DOMPurify server-side
* เพิ่ม sanitization middleware สำหรับ:
- ติดตั้ง sanitize-html หรือ DOMPurify server-side
- เพิ่ม sanitization middleware สำหรับ:
- query params
- body JSON
- form inputs
* query params
* body JSON
* form inputs
* เพิ่ม unit test: sanitized input → safe output
- เพิ่ม unit test: sanitized input → safe output
### 2A.3 Security Headers (Helmet)
* เปิดใช้งาน Helmet ทั้งระบบ
* ปรับ policy: `contentSecurityPolicy`, `xssFilter`, `noSniff`
* เพิ่ม config per environment
- เปิดใช้งาน Helmet ทั้งระบบ
- ปรับ policy: `contentSecurityPolicy`, `xssFilter`, `noSniff`
- เพิ่ม config per environment
### 2A.4 Rate Limiting
* Rate limit แบบ 2 ชั้น:
- Rate limit แบบ 2 ชั้น:
- anonymous (เช่น 30 req/min)
- authenticated (100 req/min)
* anonymous (เช่น 30 req/min)
* authenticated (100 req/min)
* สร้าง Redis key pattern: `ratelimit:{ip}`
* สร้าง RateLimitGuard + decorator
* ทดสอบ burst traffic (locust หรือ autocannon)
- สร้าง Redis key pattern: `ratelimit:{ip}`
- สร้าง RateLimitGuard + decorator
- ทดสอบ burst traffic (locust หรือ autocannon)
### 2A.5 SQL Injection / XSS Protection
* เปิด TypeORM parameterized queries
* Sanitizer ตรวจจับ script tags
* เขียน test ที่ inject payload จำลอง
- เปิด TypeORM parameterized queries
- Sanitizer ตรวจจับ script tags
- เขียน test ที่ inject payload จำลอง
### 2A.6 Logging + Error Model Integration
* ผูก SecurityException → Error Model
* เพิ่ม request_id logging
- ผูก SecurityException → Error Model
- เพิ่ม request_id logging
## ✔ Developer Checklist (Phase 2A)
* [ ] ทุก controller มี ValidationPipe ครอบ
* [ ] Sanitization ทำงานในทุก input source
* [ ] Error ทั้งหมดออกตาม Error Model กลาง
* [ ] RateLimitGuard ทำงานผ่าน Redis
* [ ] มี security test อย่างน้อย 10 ชุด
- [ ] ทุก controller มี ValidationPipe ครอบ
- [ ] Sanitization ทำงานในทุก input source
- [ ] Error ทั้งหมดออกตาม Error Model กลาง
- [ ] RateLimitGuard ทำงานผ่าน Redis
- [ ] มี security test อย่างน้อย 10 ชุด
## ✔ Test Coverage (Phase 2A)
* Input injection tests
* Rate limit tests
* Validation rejects undefined fields
* ErrorModel mapping
- Input injection tests
- Rate limit tests
- Validation rejects undefined fields
- ErrorModel mapping
---
@@ -95,60 +95,60 @@
## ✔ Deliverables
* Schema Registry
* Schema Versioning
* Schema Validation Service
* Compatibility Rules
* Schema Migration Tests
- Schema Registry
- Schema Versioning
- Schema Validation Service
- Compatibility Rules
- Schema Migration Tests
## 🛠 Task Breakdown
### 2B.1 Schema Registry
* Entity: `json_schemas`, `json_schema_versions`
* Endpoint: `POST /json-schemas`
* ฟิลด์สำคัญ: schema_id, version, schema_json
* สร้าง SchemaStore class
- Entity: `json_schemas`, `json_schema_versions`
- Endpoint: `POST /json-schemas`
- ฟิลด์สำคัญ: schema_id, version, schema_json
- สร้าง SchemaStore class
### 2B.2 Schema Versioning
* Version rule: semantic versioning (major.minor.patch)
* Migration notes per version
* นโยบาย: Breaking change → major bump
* API: `GET /json-schemas/:id?version=`
- Version rule: semantic versioning (major.minor.patch)
- Migration notes per version
- นโยบาย: Breaking change → major bump
- API: `GET /json-schemas/:id?version=`
### 2B.3 Schema Validation Service
* ใช้ AJV หรือ Fastest-Validator
* preload schema เมื่อ boot server
* mapping validation error → Error Model
* เพิ่ม test: invalid schema / missing fields / wrong types
- ใช้ AJV หรือ Fastest-Validator
- preload schema เมื่อ boot server
- mapping validation error → Error Model
- เพิ่ม test: invalid schema / missing fields / wrong types
### 2B.4 Compatibility Rules
* ตรวจสอบ backward compatibility:
- ตรวจสอบ backward compatibility:
- field removal → major version
- enum shrink → major version
* field removal → major version
* enum shrink → major version
* เพิ่ม script ตรวจ schema diff
- เพิ่ม script ตรวจ schema diff
### 2B.5 Schema Migration Tests
* ทดสอบ schema upgrade (v1 → v2)
* ทดสอบ payload ที่ใช้ version เก่า
- ทดสอบ schema upgrade (v1 → v2)
- ทดสอบ payload ที่ใช้ version เก่า
## ✔ Developer Checklist (Phase 2B)
* [ ] ทุก JSON field อ้างอิง schema version
* [ ] ทุก schema ผ่าน validation
* [ ] Schema diff pass
* [ ] Schema test ครอบครบทุก field
- [ ] ทุก JSON field อ้างอิง schema version
- [ ] ทุก schema ผ่าน validation
- [ ] Schema diff pass
- [ ] Schema test ครอบครบทุก field
## ✔ Test Coverage (Phase 2B)
* Schema version switch tests
* Incompatible payload rejection
* Schema registry CRUD
- Schema version switch tests
- Incompatible payload rejection
- Schema registry CRUD
---
@@ -158,76 +158,76 @@
## ✔ Deliverables
* JSON size validator
* JSON sanitizer
* JSON compressor (gzip/deflate)
* Sensitive fields encryption
* JSON transformation layer
- JSON size validator
- JSON sanitizer
- JSON compressor (gzip/deflate)
- Sensitive fields encryption
- JSON transformation layer
## 🛠 Task Breakdown
### 2C.1 JSON Size Controls
* ตั้ง global limit (เช่น 2MB ต่อฟิลด์)
* เพิ่ม JSONSizeGuard
* เขียน test: oversize JSON → error_code: `JSON.TOO_LARGE`
- ตั้ง global limit (เช่น 2MB ต่อฟิลด์)
- เพิ่ม JSONSizeGuard
- เขียน test: oversize JSON → error_code: `JSON.TOO_LARGE`
### 2C.2 JSON Sanitization (ลึกกว่า Phase 2A)
* ล้าง nested fields
* ล้าง `<script>`, `<iframe>`, inline JS
* รองรับ JSON array sanitization
- ล้าง nested fields
- ล้าง `<script>`, `<iframe>`, inline JS
- รองรับ JSON array sanitization
### 2C.3 Compression Layer
* ใช้ gzip ด้วย `zlib`
* เก็บ compressed JSON ใน DB
* สร้าง helper: `compressJson()`, `decompressJson()`
* Test: compression ratio > 30%
- ใช้ gzip ด้วย `zlib`
- เก็บ compressed JSON ใน DB
- สร้าง helper: `compressJson()`, `decompressJson()`
- Test: compression ratio > 30%
### 2C.4 Sensitive Fields Encryption
* AES-256-GCM สำหรับฟิลด์ที่กำหนด เช่น:
- AES-256-GCM สำหรับฟิลด์ที่กำหนด เช่น:
- personal fields
- confidential fields
* personal fields
* confidential fields
* สร้าง decorator: `@EncryptedField()`
* Test: decrypt → original JSON
- สร้าง decorator: `@EncryptedField()`
- Test: decrypt → original JSON
### 2C.5 JSON Transformation Layer
* Map JSON fields → internal format
* ใช้กับ Correspondence / RFA
* รองรับ schema version migration (เชื่อมกับ Phase 2B)
- Map JSON fields → internal format
- ใช้กับ Correspondence / RFA
- รองรับ schema version migration (เชื่อมกับ Phase 2B)
## ✔ Developer Checklist (Phase 2C)
* [ ] JSON size guard ครอบทุก endpoint
* [ ] Compression + encryption ทำงานก่อน persist
* [ ] Sanitizer ผ่าน nested objects
* [ ] Transform layer มี test ครบ
- [ ] JSON size guard ครอบทุก endpoint
- [ ] Compression + encryption ทำงานก่อน persist
- [ ] Sanitizer ผ่าน nested objects
- [ ] Transform layer มี test ครบ
## ✔ Test Coverage (Phase 2C)
* Oversize JSON tests
* Encryption/decryption tests
* Compression tests
* Schema-versioned transformation tests
- Oversize JSON tests
- Encryption/decryption tests
- Compression tests
- Schema-versioned transformation tests
---
# 🔗 Dependencies
* Phase 2A → จำเป็นก่อน 2B, 2C
* Phase 2B → ต้องเสร็จเพื่อให้ 2C ทำ transformation
- Phase 2A → จำเป็นก่อน 2B, 2C
- Phase 2B → ต้องเสร็จเพื่อให้ 2C ทำ transformation
---
# ⚠ Risks
* Schema versioning อาจกระทบ payload เดิม → ต้องมี migration plan
* Compression/encryption ทำให้ debug ยาก → ต้องพึ่ง request_id + audit logs
* Rate limiting ไม่เหมาะสมอาจ block ผู้ใช้จริง
- Schema versioning อาจกระทบ payload เดิม → ต้องมี migration plan
- Compression/encryption ทำให้ debug ยาก → ต้องพึ่ง request_id + audit logs
- Rate limiting ไม่เหมาะสมอาจ block ผู้ใช้จริง
---