</>Học Dev
Bài học

Tuần 1 - Ngày 2: OWASP Top 10 (2021) Overview

Tuần 1 – Ngày 2

Mục tiêu học tập

  • Biết OWASP là tổ chức nào và OWASP Top 10 dùng để làm gì
  • Nhớ tên + ý nghĩa 10 categories A01-A10 của phiên bản 2021
  • So sánh được thay đổi giữa Top 10 2017 vs 2021
  • Hiểu cách dùng Top 10 trong threat modeling và code review
  • Biết category nào sẽ học sâu trong các bài tiếp theo

1. OWASP là gì?

OWASP (Open Worldwide Application Security Project) là tổ chức phi lợi nhuận thành lập 2001, tập trung vào application security. Tất cả tài liệu, tool, framework đều free và open-source.

OWASPcungcpnhnggì?-OWASPTop10(webapprisks,mi3-4năm)-OWASPAPISecurityTop10(API-specific)-OWASPMobileTop10(Android/iOSapp)-OWASPASVS(ApplicationSecurityVerificationStandard)-OWASPCheatSheetSeries(bestpracticengngn)-OWASPZAP,OWASPJuiceShop(tool,labthchành)-OWASPDependency-Check(SCAscanning)

Khi recruiter, auditor, hoặc compliance hỏi "app của bạn có bị các lỗ hổng OWASP Top 10 không?" — họ đang nói đến danh sách này.


2. OWASP Top 10 là gì?

Danh sách 10 nhóm rủi ro nghiêm trọng nhất đối với web application, được cập nhật dựa trên dữ liệu thực tế từ hàng trăm tổ chức + survey chuyên gia.

Cách OWASP xây dựng list

OWASP thu thập data từ:

  • Bug bounty platform (HackerOne, Bugcrowd) — vulnerabilities thật được trả tiền
  • Automated scanner result từ thousand of organizations
  • Industry survey với security professionals
  • CVE database — lỗ hổng được công bố

Mỗi category được tính score dựa trên: Exploitability + Detectability + Impact + Prevalence.

Lưu ý quan trọng

  • OWASP Top 10 không phải checklist đầy đủ — chỉ là 10 nhóm phổ biến/nguy hiểm nhất
  • "Pass OWASP Top 10" không có nghĩa là secure — chỉ là baseline tối thiểu
  • Một bug có thể thuộc nhiều category cùng lúc
  • Top 10 thay đổi mỗi phiên bản — đừng học thuộc lòng số thứ tự, học hiểu bản chất

3. OWASP Top 10 — 2021 Edition

A01BrokenAccessControlA02CryptographicFailuresA03InjectionA04InsecureDesignMIA05SecurityMisconfigurationA06VulnerableandOutdatedComponentsA07IdentificationandAuthenticationFailuresA08SoftwareandDataIntegrityFailuresMIA09SecurityLoggingandMonitoringFailuresA10Server-SideRequestForgery(SSRF)MI

A01 — Broken Access Control

User truy cập được resource/action mà họ không được phép.

Ví dụ:

  • GET /api/users/123/profile — đổi 123 thành ID người khác → đọc được data của họ (IDOR)
  • User thường gọi được DELETE /admin/users/5
  • File upload chui sang folder admin
  • JWT có role claim nhưng backend không verify

Đây là #1 phổ biến nhất trong 2021. Sẽ học sâu Ngày 4 (IDOR).

A02 — Cryptographic Failures (trước: "Sensitive Data Exposure")

Crypto bị sai hoặc thiếu, làm leak data nhạy cảm.

Ví dụ:

  • Lưu password plaintext hoặc MD5/SHA-1 (không salt)
  • Dùng TLS 1.0/1.1 đã deprecated
  • Hard-code AES key trong source code
  • JWT ký bằng alg: none hoặc weak secret secret123
  • Tự viết encryption thay vì dùng library

Sẽ học sâu ở Tuần 2 (password hashing, JWT, TLS).

A03 — Injection

Untrusted input được nhúng vào câu lệnh (SQL, OS command, LDAP, XPath) mà không validate/escape.

Bao gồm:

  • SQL Injection (sẽ học Ngày 4)
  • XSS — gọi là "JavaScript injection" về bản chất (Ngày 3)
  • OS Command Injectionexec("ping " + userInput)exec("ping a.com; rm -rf /")
  • NoSQL injection ({"$ne": null} trong MongoDB)
  • LDAP, XPath, ORM injection

Trong Top 10 2017 đứng #1, 2021 xuống #3 vì frameworks/ORM đã đỡ tốt hơn — nhưng vẫn rất nguy hiểm.

A04 — Insecure Design ⭐ MỚI 2021

Lỗ hổng nằm ở thiết kế chứ không phải implementation. Code đúng theo spec nhưng spec bị sai.

Ví dụ:

  • Quên rate limit "Forgot Password" → attacker brute force OTP
  • Reset password chỉ cần email + ngày sinh (information có thể tìm public)
  • Business logic cho phép total = sum(items) - discount với discount âm không kiểm tra
  • Thiết kế upload file lưu vào thư mục web-accessible bằng tên gốc của user

Cách phòng: threat modeling từ giai đoạn design, secure design pattern, reference architecture chuẩn.

A05 — Security Misconfiguration

Hệ thống có default/insecure configuration.

Ví dụ:

  • S3 bucket public-read khi không cần
  • Database mặc định listen 0.0.0.0 không firewall
  • Default credential admin/admin còn dùng
  • Debug mode DEBUG=true trên production (Django, Flask)
  • Stack trace trả về client (/api/error show file path, library version)
  • CORS Access-Control-Allow-Origin: * với credential
  • Header security thiếu (sẽ học Ngày 5)

Top category bị hacker tự động scan và exploit nhiều nhất.

A06 — Vulnerable and Outdated Components

Dùng library, framework, OS, container image có CVE đã biết.

Ví dụ:

  • Log4j 2.14 (CVE-2021-44228 "Log4Shell")
  • Express 4.16 với prototype pollution vulnerability
  • jQuery 1.x với XSS sinks
  • Docker base image node:14 (EOL, no security patches)
  • Spring4Shell (CVE-2022-22965)

Cách phòng:

  • SCA tools: Snyk, Dependabot, npm audit, pip-audit
  • SBOM (Software Bill of Materials) — biết mình dùng cái gì
  • Patch policy: critical CVE → fix trong 7 ngày

A07 — Identification and Authentication Failures

Lỗi trong cách identify user và xác thực.

Ví dụ:

  • Không có lockout sau N lần login fail → brute force OK
  • Cho phép password yếu 123456 hoặc password = username
  • Session token đoán được (incremental ID)
  • Session không expire, không invalidate sau logout
  • Không có MFA cho admin
  • Password reset link gửi qua HTTP (không HTTPS)
  • "Remember me" cookie dùng vĩnh viễn

Sẽ học sâu Tuần 2 (authentication patterns, MFA, OAuth/OIDC).

A08 — Software and Data Integrity Failures ⭐ MỚI 2021

Code, infrastructure, data thay đổi mà không verify integrity.

Ví dụ:

  • CI/CD pipeline pull dependency từ npm/PyPI không verify
  • Auto-update từ vendor không check signature
  • Deserialization untrusted data (Java ObjectInputStream, Python pickle.loads, PHP unserialize)
  • Webhook receive payload không verify HMAC signature
  • Docker image pull bằng tag :latest (không pin digest)

Đây là cách SolarWinds supply chain attack xảy ra (2020).

Cách phòng:

  • Sign artifact (Sigstore, GPG)
  • Verify signature trong CI
  • Pin version + lockfile (package-lock.json, Pipfile.lock)
  • Code signing cho release

A09 — Security Logging and Monitoring Failures

Không log hoặc log không monitor được → attacker ở trong hệ thống 200 ngày không ai biết.

Ví dụ:

  • Không log login fail, password reset, privilege change
  • Log không có timestamp, IP, user
  • Log lưu trên cùng server, attacker xoá được
  • Có log nhưng không có alert / SIEM
  • Stack trace lộ password trong log

Cách phòng:

  • Log: login attempt, authz failure, input validation failure, admin action
  • Centralize log (CloudWatch, ELK, Datadog)
  • Alert trên anomaly
  • Immutable log (write-once)

A10 — Server-Side Request Forgery (SSRF) ⭐ MỚI 2021

Server fetch URL do user cung cấp mà không validate → attacker buộc server gọi internal service.

Ví dụ classic:

  • Feature "preview URL" hoặc "import from URL"
  • User gửi http://169.254.169.254/latest/meta-data/iam/security-credentials/ (AWS IMDSv1)
  • Server fetch URL đó → trả về IAM credential của EC2 instance → attacker chiếm quyền AWS

Capital One breach 2019 (100M+ customers) xảy ra qua SSRF + IMDSv1.

Sẽ học sâu Ngày 4.


4. So sánh OWASP Top 10: 2017 vs 2021

20172021Thay đổi
A1 InjectionA3 InjectionTụt từ #1 xuống #3 (ORM, framework tốt hơn)
A2 Broken AuthenticationA7 Identification and Authentication FailuresĐổi tên, tụt hạng
A3 Sensitive Data ExposureA2 Cryptographic FailuresĐổi tên (chính xác hơn về nguyên nhân)
A4 XML External Entities (XXE)(gộp vào A5 Misconfiguration)XXE giảm vì XML giảm dùng
A5 Broken Access ControlA1 Broken Access ControlLên #1 — exploit nhiều nhất 2021
A6 Security MisconfigurationA5 Security MisconfigurationLên hạng
A7 Cross-Site Scripting (XSS)(gộp vào A3 Injection)XSS = JS injection
A8 Insecure Deserialization(gộp vào A8 Integrity Failures)Mở rộng phạm vi
A9 Using Components with Known VulnerabilitiesA6 Vulnerable and Outdated ComponentsĐổi tên ngắn gọn
A10 Insufficient Logging and MonitoringA9 Security Logging and Monitoring FailuresLên hạng
A4 Insecure DesignMỚI — design-level threat
A8 Software and Data Integrity FailuresMỚI — supply chain attack
A10 SSRFMỚI — cloud era threat

Quan sát quan trọng

Top 10 2017 nặng về CODING bugs (XSS, SQLi, XXE)
Top 10 2021 nặng về DESIGN + SUPPLY CHAIN bugs
       ↓
Lý do: ngày càng nhiều app dùng framework (chống bug code-level tự động)
       nhưng nhiều supply chain attack + cloud config bugs hơn

3 category mới đều phản ánh xu hướng: cloud (SSRF), DevOps/CI-CD (Integrity), thinking ahead (Insecure Design).


5. Lộ trình học các category trong khoá này

CategoryHọc ởNgày
A01 Broken Access Control (IDOR)Tuần 1Ngày 4
A02 Cryptographic FailuresTuần 2Password hashing, JWT, TLS
A03 Injection (XSS)Tuần 1Ngày 3
A03 Injection (SQLi)Tuần 1Ngày 4
A04 Insecure DesignTuần 1Ngày 1 (threat modeling)
A05 Security MisconfigurationTuần 1Ngày 5 (security headers)
A06 Vulnerable ComponentsTuần 4SCA, dependency scanning
A07 Authentication FailuresTuần 2Auth deep dive
A08 Integrity FailuresTuần 4Supply chain security
A09 Logging FailuresTuần 4Security logging
A10 SSRFTuần 1Ngày 4

6. Dùng OWASP Top 10 trong threat modeling thế nào?

Khi review code hoặc thiết kế feature mới, dùng Top 10 như checklist nhanh:

[ ] A01: Mỗi endpoint có check authorization không?
        Object ownership có verify không?
[ ] A02: Có lưu/truyền dữ liệu nhạy cảm? Encrypt ở đâu?
        Hash password đúng cách (bcrypt/argon2)?
[ ] A03: Input nào đi vào SQL/shell/HTML?
        Có dùng parameterized query / escape không?
[ ] A04: Có rate limit feature dễ abuse không?
        Business logic có "happy path bypass" không?
[ ] A05: Default config đã hardened?
        Debug mode tắt? CORS đúng?
[ ] A06: Dependency có CVE không? (npm audit / snyk)
[ ] A07: Có brute force protection?
        Session/token strong + expire?
[ ] A08: Webhook verify signature?
        CI/CD pin version + verify?
[ ] A09: Có log security event quan trọng?
        Có alert + retention đủ lâu?
[ ] A10: Có feature fetch URL từ user input?
        Có whitelist + block metadata IP?

Tích hợp vào quy trình

  • Design review: áp Top 10 cho feature spec
  • Code review: PR template hỏi "category nào liên quan?"
  • QA: test case cho từng category áp dụng
  • Release checklist: scan SCA, secret scan trước deploy

7. Câu hỏi ôn tập

  1. OWASP Top 10 2021 category nào lên #1 và lý do?

    Xem đáp án

    A01 — Broken Access Control lên #1 (từ #5 năm 2017). Lý do: dữ liệu từ HackerOne, Bugcrowd cho thấy access control bugs (IDOR, missing authorization check, privilege escalation) chiếm tỉ lệ exploit cao nhất và impact lớn nhất. Framework không tự động bảo vệ access control như chống SQLi — developer phải code đúng từng endpoint.

  2. Tại sao "Insecure Design" được thêm vào 2021 trong khi nó không phải lỗi code cụ thể?

    Xem đáp án

    Vì rất nhiều breach xảy ra do thiết kế sai, không phải code sai. Code có thể đúng theo spec, nhưng spec không tính đến threat. Ví dụ: feature "forgot password" thiết kế gửi OTP 6 số không có rate limit — code OTP generation đúng, nhưng design cho phép brute force. Thêm A04 nhằm nhấn mạnh threat modeling từ giai đoạn design, không chỉ coding.

  3. Bạn maintain một Node.js API. Sự khác biệt giữa A06 (Vulnerable Components) và A08 (Integrity Failures) trong context dependency là gì?

    Xem đáp án
    • A06: bạn dùng version có CVE biết trước (vd express@4.16 có vulnerability). Fix bằng update, dùng SCA tool. Lỗi do chưa patch.
    • A08: bạn pull dependency mà không verify nguồn (không pin version, không verify checksum, không scan malicious package). Fix bằng lockfile + signature verification + supply chain scanning. Lỗi do không tin được nguồn.

    A06 = dùng cái có lỗ hổng đã biết. A08 = bạn không biết mình đang dùng cái gì hoặc nó có bị thay đổi không. Một số attacks (typosquatting, dependency confusion) thuộc A08.

  4. Một developer nói: "App của tôi pass OWASP Top 10 nên đã secure." Có đúng không?

    Xem đáp án

    Không đúng. OWASP Top 10 chỉ là baseline tối thiểu — 10 nhóm rủi ro phổ biến nhất, không bao gồm mọi lỗ hổng. App có thể có business logic bug, race condition, side channel attack, mobile-specific issues, infrastructure misconfig khác mà Top 10 không cover. Top 10 là điểm bắt đầu, không phải đích đến. Để comprehensive hơn nên dùng OWASP ASVS (Application Security Verification Standard) hoặc NIST SP 800-53.

  5. Sếp yêu cầu bạn review một feature "import contact từ Google account". Top 10 category nào đáng lo nhất và tại sao?

    Xem đáp án

    Top concerns:

    • A10 SSRF: nếu feature fetch URL từ Google API, có thể bị manipulate để fetch internal URL.
    • A07 Auth Failures: OAuth flow phải đúng — verify state param, redirect URI whitelist, không leak access token.
    • A02 Cryptographic Failures: access token Google phải encrypt at rest nếu lưu lại.
    • A01 Broken Access Control: contact import vào account nào? Có check ownership không?
    • A09 Logging: log mọi OAuth grant để audit.

    Một feature đơn giản nhưng động đến 5 category cùng lúc — đó là lý do threat modeling cần thiết.

Bài tập thực hành

# 1. Đọc bản gốc OWASP Top 10 2021
open https://owasp.org/Top10/

# 2. Chạy OWASP Juice Shop (intentionally vulnerable app để học)
docker run --rm -p 3000:3000 bkimminich/juice-shop
# Mở http://localhost:3000
# Thử tìm bug — bắt đầu từ "Score Board" challenge

# 3. Audit dependencies của project mình
# Node.js
npm audit
npm audit fix

# Python
pip install pip-audit
pip-audit

# 4. Map Top 10 vào codebase của bạn
# Mở repo, đánh dấu file/endpoint nào liên quan category nào
# Ví dụ:
#    src/api/users.ts          → A01 (access control)
#    src/lib/passwordHash.ts   → A02 (crypto)
#    src/api/search.ts         → A03 (SQLi nếu query động)
#    src/api/imageProxy.ts     → A10 (SSRF)

# 5. Threat model cho 1 endpoint dùng Top 10 checklist
# Chọn 1 endpoint, đi qua từng category A01-A10
# Liệt kê threat tìm được + plan mitigation

Tài liệu tham khảo chính thức


Tiếp theo: Ngày 3 — XSS và CSRF