CSSLP · Domain 1 · 10%

Khái niệm SDLC an toàn

Secure Software Concepts

Nền tảng tư duy bảo mật cho developer: mô hình SDLC an toàn, các nguyên tắc thiết kế cốt lõi, threat modeling, và tích hợp bảo mật ngay từ giai đoạn đầu của vòng đời phần mềm.

Mục tiêu chương / Learning objectives

1. Lý thuyết cốt lõi / Core theory

1.1. Mô hình Secure SDLC (Secure SDLC Models)

Bốn mô hình quan trọng nhất trong kỳ thi CSSLP: Microsoft SDL (Security Development Lifecycle) — quy trình 12 giai đoạn, bắt buộc với phần mềm Microsoft, tập trung vào threat modeling và code review; OWASP SAMM (Software Assurance Maturity Model) — framework đo mức độ trưởng thành AppSec của tổ chức theo 5 Business Functions × 3 Practice; BSIMM (Building Security In Maturity Model) — model dựa trên khảo sát thực tế 130+ tổ chức, mô tả "những gì tổ chức thực sự làm" thay vì prescriptive; CLASP (Comprehensive Lightweight Application Security Process) — tích hợp vào quy trình hiện có qua activity-centric approach.

Khái niệm then chốt — Shift Left Security: Phát hiện và fix lỗi bảo mật càng sớm trong SDLC càng rẻ. Nghiên cứu IBM: fix bug ở giai đoạn requirements tốn $1, ở design $10, coding $100, testing $1,000, production $10,000+. Shift-left nghĩa là đưa security activities về sớm hơn trong pipeline: SAST trong IDE, threat modeling ngay khi design, security requirements khi thu thập yêu cầu.

1.2. CIA Triad cho Phần mềm (CIA for Software, Trust Boundaries, Attack Surface)

Confidentiality trong phần mềm: mã hóa dữ liệu tại rest và transit, access control ở mức API/function, không log sensitive data. Integrity: input validation, output encoding, digital signatures cho artifacts, checksum kiểm tra toàn vẹn dữ liệu. Availability: rate limiting chống DoS, graceful degradation, không để lỗi exception làm crash toàn service.

Trust boundary là ranh giới giữa các vùng có mức tin cậy khác nhau — ví dụ: Internet vs DMZ, external user vs authenticated user, user process vs kernel. Mọi dữ liệu vượt qua trust boundary phải được validate. Attack surface là tổng hợp các điểm tấn công: số lượng API endpoint, input fields, authentication mechanisms, network ports. Nguyên tắc: minimize attack surface — đóng tất cả những gì không cần thiết.

1.3. Nguyên tắc thiết kế an toàn (Secure Design Principles — Saltzer & Schroeder)

Tám nguyên tắc kinh điển (1975, vẫn hoàn toàn applicable):

Defense in Depth: Không dựa vào một lớp bảo vệ duy nhất. Ví dụ web app: WAF (network layer) → TLS (transport) → Authentication (application) → Authorization (business logic) → Encryption (data layer). Mỗi lớp assume lớp trước đã bị vượt qua.

1.4. Threat Modeling (STRIDE, PASTA, Attack Trees, Taint Analysis)

STRIDE (Microsoft) — phân loại threats: Spoofing (giả mạo danh tính → Authentication), Tampering (thay đổi dữ liệu → Integrity), Repudiation (phủ nhận hành động → Non-repudiation), Information Disclosure (lộ thông tin → Confidentiality), Denial of Service (từ chối dịch vụ → Availability), Elevation of Privilege (leo thang đặc quyền → Authorization). Áp dụng STRIDE trên từng element trong DFD (Data Flow Diagram).

PASTA (Process for Attack Simulation and Threat Analysis) — 7-stage risk-centric model: từ business objectives đến attack simulation. Attack Trees — mô hình hóa cách attacker đạt mục tiêu qua cây quyết định (root = mục tiêu, leaves = attack vectors). Taint analysis — theo dõi dữ liệu từ nguồn không tin cậy (user input) qua code đến sink (database query, OS command) để phát hiện injection.

1.5. Privacy by Design & Security Debt (GDPR Art.25, Security Debt)

Privacy by Design (Ann Cavoukian) — 7 nguyên tắc, được GDPR Art.25 luật hóa: proactive not reactive, privacy as default, embedded into design, full functionality, end-to-end security, visibility and transparency, respect for user privacy. Thực tế: data minimization (chỉ thu thập dữ liệu cần thiết), pseudonymization, consent management.

Security debt là tương tự technical debt nhưng cho bảo mật: các lỗ hổng, thiếu control, code không secure tích lũy theo thời gian do áp lực deadline. Security debt nguy hiểm vì: tăng risk exposure, khó repay sau (cần refactor lớn), thường invisible với management. Cần track qua security backlog, đo bằng vulnerability density (số lỗ hổng/KLOC).

2. Bài thực hành / Hands-on labs

🖥️ Nền tảng / Platform: Windows 11 · Ubuntu 22.04 LTS
🛠️ Công cụ / Tools: PowerShell 7 + PSScriptAnalyzer · Bash + Python + pytm

Lab 1 — SAST Quick Scan tìm secret trong codebase (PowerShell)

OS: Windows 11 · Tool: PowerShell 7 + PSScriptAnalyzer module.

  1. Cài PSScriptAnalyzer nếu chưa có: Install-Module PSScriptAnalyzer -Scope CurrentUser -Force
  2. Quét tìm hardcoded credentials trong source code:
# Quét đệ quy tìm pattern credential bị hardcode
Get-ChildItem -Recurse -Include *.ps1,*.py,*.js,*.cs -ErrorAction SilentlyContinue |
    Select-String -Pattern "password\s*=\s*['\`"]|api_key\s*=|secret\s*=|AKIA[0-9A-Z]{16}" |
    Select-Object Path, LineNumber, Line |
    Format-Table -Wrap -AutoSize

# Chạy PSScriptAnalyzer để phát hiện lỗi bảo mật trong PowerShell scripts
# Tạo file mẫu để test
@'
$password = "MyP@ssw0rd123"
Invoke-Expression $userInput
$result = iex $cmd
'@ | Out-File -FilePath "$env:TEMP\test-vuln.ps1"

Invoke-ScriptAnalyzer -Path "$env:TEMP\test-vuln.ps1" -Severity Warning,Error |
    Select-Object RuleName, Severity, Message, Line |
    Format-Table -Wrap

✅ Kết quả mong đợi / Expected output: PSScriptAnalyzer sẽ báo: PSAvoidUsingPlainTextForPassword (dòng chứa $password = "..."), PSAvoidUsingInvokeExpression (dòng iex). Đây chính là SAST tự động phát hiện anti-pattern nguy hiểm. Ý nghĩa: tích hợp vào pre-commit hook để block code kém an toàn trước khi vào repo.

Lab 2 — Threat Modeling với pytm (Bash)

OS: Ubuntu 22.04 · Tool: Bash + Python 3 + pytm library.

  1. Cài pytm: pip install pytm
  2. Tạo script threat model đơn giản cho web app:
cat > /tmp/webapp-tm.py << 'EOF'
from pytm import TM, Actor, Server, Datastore, Dataflow, Boundary

tm = TM("WebApp Threat Model")
tm.description = "Simple e-commerce application"

# Define trust boundaries
internet = Boundary("Internet")
dmz      = Boundary("DMZ")
internal = Boundary("Internal Network")

# Define elements
user    = Actor("End User",      inBoundary=internet)
webapp  = Server("Web Server",   inBoundary=dmz,      isHardened=True)
db      = Datastore("Database",  inBoundary=internal, isEncrypted=True)

# Define dataflows
df1 = Dataflow(user, webapp,  "HTTP Request",   isEncrypted=True,  protocol="HTTPS")
df2 = Dataflow(webapp, db,    "DB Query",       isEncrypted=True,  protocol="TLS")
df3 = Dataflow(db, webapp,    "DB Response",    isEncrypted=True)
df4 = Dataflow(webapp, user,  "HTTP Response",  isEncrypted=True)

tm.process()
EOF
python3 /tmp/webapp-tm.py --json 2>/dev/null | python3 -c "
import json,sys
data = json.load(sys.stdin)
threats = data.get('findings', [])
print(f'Total threats identified: {len(threats)}')
for t in threats[:5]:
    print(f'  [{t.get(\"severity\",\"?\")}] {t.get(\"description\",\"\")}')
" 2>/dev/null || echo "pytm installed — run: python3 /tmp/webapp-tm.py --report-word"

# Alternative: check OWASP Threat Dragon CLI nếu có
which threat-dragon 2>/dev/null && threat-dragon --version || echo "Threat Dragon: install via npm i -g @threatdragon/threat-dragon-core"

✅ Kết quả mong đợi / Expected output: pytm tự động generate danh sách threats theo STRIDE dựa trên model: ví dụ "Spoofing: End User có thể giả mạo danh tính", "Tampering: HTTP Request qua boundary có thể bị modify". Output dạng JSON hoặc Word report. Ý nghĩa: automation threat modeling tích hợp vào CI/CD pipeline, chạy mỗi khi architecture thay đổi.

3. Tình huống doanh nghiệp / Real-world scenario

Bối cảnh:

Một fintech startup phát triển ứng dụng payment với team 15 developer. Sau 2 năm ra mắt, pentest phát hiện 3 lỗ hổng critical (SQL injection, hardcoded API keys, broken auth). CTO yêu cầu xây dựng Secure SDLC từ đầu mà không dừng sprint.

Áp dụng CSSLP Domain 1:

  1. Chọn OWASP SAMM làm baseline — đo maturity score hiện tại (thường 0.5-1.0/3.0 với startup).
  2. Thực hiện threat modeling trên top 3 flow quan trọng nhất (payment, auth, data export) bằng STRIDE.
  3. Tạo security backlog từ kết quả threat model: ưu tiên theo CVSS score × business impact.
  4. Tích hợp PSScriptAnalyzer/Semgrep vào pre-commit hooks ngay lập tức — không cần dừng sprint.
  5. Đặt mục tiêu 6 tháng: SAMM score tăng lên 1.5, 0 critical findings trong CI pipeline.

Bài học: không có Secure SDLC "perfect" ngay từ đầu. Bắt đầu với threat modeling và SAST, đo lường security debt, cải thiện từng sprint. BSIMM data cho thấy top-performing organizations commit ~25% AppSec effort vào threat modeling.

4. Tự kiểm tra / Knowledge check

  1. STRIDE là gì? Mỗi chữ cái tương ứng với mối đe dọa nào và control nào?
  2. Phân biệt OWASP SAMM và BSIMM: cái nào prescriptive, cái nào descriptive?
  3. Nguyên tắc "fail-safe defaults" áp dụng thực tế vào API authorization như thế nào?
  4. Trust boundary là gì? Cho ví dụ 3 trust boundary trong một ứng dụng 3-tier điển hình.
  5. GDPR Article 25 yêu cầu gì từ developer và liên quan đến Privacy by Design như thế nào?
4A-C06: Legal & Risk C02: Yêu cầu bảo mật phần mềm
Thực hành trên công cụPowerShell 7 · Bash · pytm · PSScriptAnalyzer
Nền tảngWindows 11 · Ubuntu 22.04 LTS
Thời điểm phát hànhQ2/2026
Ngày biên soạn24/05/2026
Người biên soạnTrần Văn Hòa (MCT)
Phiên bảnv1.0
Zalo