Security Code Review
& Scanning Tools

Hands-on Workshop | 3 Hours


DEVDAY EP.3

Learn to find and fix security vulnerabilities
through manual code review and automated scanning tools

Agenda

TimeSession
09:00 - 09:45Security Fundamentals & OWASP Top 10
09:45 - 10:15Manual Code Review + Exercise
10:15 - 10:25Break
10:25 - 10:45Security Scanning Tools Overview
10:45 - 11:35Hands-on Lab — Security Scanning
11:35 - 11:55CI/CD Integration & Best Practices
11:55 - 12:00Q&A & Wrap-up
BonusAppendix: Security Dockerfile & Docker Compose (Self-study)

Course Overview

เรียนรู้การตรวจสอบความปลอดภัยของ source code ด้วย manual code review
และการใช้เครื่องมือ security scanning tools เพื่อค้นหาช่องโหว่
และความเสี่ยงด้านความปลอดภัย ก่อนนำ code ไป deploy จริง

5
Sessions
3h
Hands-on
4+
Tools

Learning Objectives

เมื่อจบ workshop นี้ ผู้เรียนจะสามารถ:

  • เข้าใจหลักการ secure coding และช่องโหว่ที่พบบ่อย (OWASP Top 10)
  • ทำ manual code review เพื่อหาจุดอ่อนด้านความปลอดภัย
  • ใช้ security scanning tools วิเคราะห์ code อัตโนมัติ
  • ตีความและแก้ไขผลลัพธ์จาก security tools
  • บูรณาการ security scanning เข้ากับ CI/CD pipeline

Prerequisites

Required

  • ประสบการณ์พัฒนา software อย่างน้อย 1 ปี
  • เข้าใจพื้นฐาน web application security
  • รู้จักใช้ Git พื้นฐาน
  • Laptop + internet connection

Recommended

  • Git, IDE/Text editor
  • Docker (optional)
  • ติดตั้ง tools ล่วงหน้า:
  • Semgrep, Syft, Gitleaks

Session 1

Security Fundamentals
& OWASP Top 10

45 minutes

Why Security Code Review?


$4.45M
Average cost per breach
(IBM 2023)
287 days
Average time to identify
& contain a breach
85%
of breaches involve
a human element

Shift-Left Security


ยิ่งเจอช่องโหว่เร็ว ค่าใช้จ่ายในการแก้ไขยิ่งต่ำ


PhaseCost to Fix
Design1x
Development6.5x
Testing15x
Production100x

OWASP Top 10 (2025)

10 ความเสี่ยงด้านความปลอดภัยที่สำคัญที่สุดสำหรับ Web Applications


A01 Broken Access Control

A02 Security Misconfiguration

A03 Supply Chain Failures

A04 Cryptographic Failures

A05 Injection

A06 Insecure Design

A07 Auth Failures

A08 Integrity Failures

A09 Logging & Alerting

A10 Exceptional Conditions

A01: Broken Access Control

ผู้ใช้เข้าถึงข้อมูลหรือ function ที่ไม่ได้รับอนุญาต


ตัวอย่างช่องโหว่

  • IDOR — เปลี่ยน /api/user/123 เป็น /api/user/456
  • Privilege escalation — user เข้า admin panel
  • Force browsing — เข้า /admin โดยตรง

แนวทางแก้ไข

  • Authorization check ทุก request
  • Role-Based Access Control (RBAC)
  • Deny by default

// Bad: ไม่มี authorization check
app.get('/api/user/:id', (req, res) => {
    return db.getUser(req.params.id);
});

SSRF (เพิ่มใน 2025)

# Bad: server fetch URL อะไรก็ได้
resp = requests.get(user_provided_url)
# Attacker: http://169.254.169.254 → AWS metadata!
# Good: allowlist + block internal IPs
ALLOWED_DOMAINS = ["api.example.com"]
parsed = urlparse(user_provided_url)
if parsed.hostname not in ALLOWED_DOMAINS:
    raise ValueError("URL not allowed")

A02: Security Misconfiguration

ตั้งค่าไม่ถูกต้อง ปล่อย default settings เปิด features ไม่จำเป็น


ตัวอย่างช่องโหว่

  • DEBUG=True ใน production — stack trace รั่ว
  • Default credentials: admin/admin
  • S3 bucket public, directory listing
  • Missing security headers

แนวทางแก้ไข

  • Hardening checklist
  • Environment-specific configs
  • Automated config scanning
  • Security headers (CSP, HSTS)

# Bad: DEBUG ใน production
app.run(debug=True)
# → stack trace + credentials รั่ว!
# Good: env-based config
app.run(debug=env.get('DEBUG', 'false') == 'true')

A03: Software Supply Chain Failures

ใช้ library CI/CD pipeline หรือ dependency ที่ถูก compromise


XZ Utils
CVE-2024-3094 — backdoor แทรกใน xz/liblzma
ใกล้เข้าไปใน production SSH ทั่วโลก

ตัวอย่างช่องโหว่

  • XZ Utils backdoor
  • Dependency confusion attack
  • SolarWinds supply chain
  • Compromised npm/PyPI packages

แนวทางแก้ไข

  • SBOM generation (Syft)
  • Lock files (package-lock.json)
  • Private registries
  • Verify checksums + signatures

# Bad: ไม่ pin version, ไม่ verify
pip install requests
npm install lodash
# Good: pin version + verify integrity
pip install requests==2.31.0 \
  --hash=sha256:abc123...
npm ci  # uses lockfile

A04: Cryptographic Failures

การเข้ารหัสที่ไม่เหมาะสม ไม่มี หรือใช้ algorithm ล้าสมัย


ตัวอย่างช่องโหว่

  • เก็บ password เป็น plain text หรือ MD5
  • TLS 1.0/1.1 ยังใช้อยู่
  • Hardcode encryption key ใน source
  • Weak IV/salt management

แนวทางแก้ไข

  • bcrypt / argon2 สำหรับ password
  • TLS 1.3 สำหรับ data in transit
  • AES-256-GCM สำหรับ data at rest
  • Key rotation, ไม่ hardcode

# Bad
hash = md5(password)
# Good
hash = bcrypt.hashpw(password, bcrypt.gensalt())

A05: Injection

ข้อมูล user ถูกนำไป execute โดยตรงโดยไม่ผ่าน sanitize


SQL Injection

# Bad: string concatenation
query = "SELECT * FROM users WHERE id = '" + user_input + "'"
# Attacker: ' OR 1=1 -- → ได้ทั้ง database!
# Good: parameterized query
cursor.execute("SELECT * FROM users WHERE id = %s", (user_input,))

XSS (Cross-Site Scripting)

// Bad: render user input directly
document.innerHTML = userInput;
// Attacker: <script>steal(document.cookie)</script>

A05: Injection (cont.)

Command Injection

# Bad: direct OS command
os.system('ping ' + user_input)
# Attacker: ; rm -rf / → ลบทั้ง server!
# Good: use subprocess with list args
subprocess.run(['ping', '-c', '4', validated_host], capture_output=True)

แนวทางป้องกัน Injection ทุกประเภท

  • Parameterized queries / Prepared statements
  • Input validation (whitelist approach)
  • Output encoding
  • ไม่เรียก OS command โดยตรง

XXE (XML External Entities)

<!-- Bad: DTD enabled by default -->
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<data>&xxe;</data>
# Good: disable DTD processing
from defusedxml import ElementTree
tree = ElementTree.parse(untrusted_input)

A06: Insecure Design

ปัญหาจากการออกแบบที่ไม่ปลอดภัยตั้งแต่แรก
ไม่สามารถแก้ได้ด้วย code fix อย่างเดียว


  • ไม่มี rate limiting สำหรับ login — brute force ได้ไม่จำกัด
  • Forgot password ถามคำถามที่เดาได้ง่าย
  • ไม่มี threat modeling ก่อนเริ่ม development

แนวทางแก้ไข

  • Threat modeling ตั้งแต่ design phase
  • Secure design patterns
  • Abuse case testing

A07: Authentication Failures

ระบบยืนยันตัวตนที่อ่อนแอ


  • อนุญาต password อ่อนแอ: 123456, password
  • ไม่มี MFA สำหรับ sensitive operations
  • Session ID อยู่ใน URL
  • Credential stuffing ไม่มี rate limiting

แนวทางแก้ไข

  • Strong password policy
  • Multi-Factor Authentication (MFA)
  • Secure session management
  • Rate limiting + account lockout

A08: Software or Data Integrity Failures

ไม่ตรวจสอบความถูกต้องของ software updates หรือ CI/CD pipeline


SolarWinds
แทรก malicious code เข้า build pipeline
ส่งไปถึง 18,000+ องค์กร


  • Library จาก untrusted source ไม่ verify checksum
  • Insecure deserialization

แนวทางแก้ไข

  • Digital signatures, verify integrity
  • Secure CI/CD pipeline
  • ไม่ deserialize untrusted data

A09: Logging and Alerting Failures

ไม่มี logging เพียงพอ ตรวจจับ attack ไม่ได้


  • ไม่ log failed login attempts
  • Log แค่เก็บไว้ ไม่มี alerting
  • Log sensitive data เช่น passwords (ละเมิด privacy)
  • ไม่มี audit trail สำหรับ admin actions

แนวทางแก้ไข

  • Log security events อย่างเพียงพอ (ไม่ log sensitive data)
  • Centralized logging (ELK, Splunk)
  • Alerting + Incident response plan

A10: Mishandling of Exceptional Conditions

การจัดการ errors/exceptions ไม่ดี ทำให้เกิดช่องโหว่ร้ายแรง


ตัวอย่างช่องโหว่

  • Fail-open แทน fail-closed
  • Crash DoS จาก unhandled exception
  • Sensitive data ใน error messages
  • Stack trace เปิดเผยใน production

แนวทางแก้ไข

  • Fail-closed by default
  • Global exception handlers
  • Sanitize error messages
  • Log internally, generic message to user

# Bad: fail-open + expose internals
try:
    result = db.query(sql)
except Exception as e:
    return {"error": str(e)}  # leaks DB schema!
# Good: fail-closed + sanitize
try:
    result = db.query(sql)
except DatabaseError:
    log.exception("Query failed")
    return {"error": "Service unavailable"}

Session 2

Manual Code Review
Techniques

30 minutes

Security Code Review Checklist


CategoryCheck
Input Validationทุก user input ต้อง validate ทั้ง type, length, format
AuthenticationPassword policy, session timeout, MFA
Authorizationทุก endpoint มี auth check หรือไม่
SessionSecure, httpOnly, sameSite cookies
CryptographyAlgorithm ทันสมัย ไม่ hardcode keys
Error Handlingไม่ expose stack trace ให้ user
Sensitive Dataไม่เก็บ credentials ใน source code

Exercise 1: Manual Code Review

กลุ่มละ 2-3 คน | 10 นาที


หาช่องโหว่ให้มากที่สุดใน sample code


ช่องโหว่ที่ซ่อนไว้:

SQL Injection XSS Hardcoded Password Missing Auth Path Traversal Weak Hashing Verbose Errors Missing Validation

ใช้ checklist จากหัวข้อก่อนหน้าเป็นแนวทาง

Code: lab/vulnerable-app/

Break

10 minutes | 10:15 - 10:25

Session 3

Security Scanning
Tools Overview

20 minutes

3 Categories of Security Tools


SAST

Static Application Security Testing

วิเคราะห์ source code โดยไม่ต้อง run

Semgrep

SCA

Software Composition Analysis

ตรวจสอบ dependencies ที่มีช่องโหว่

Syft + Dependency-Track


Secret Scanning

ค้นหา credentials ที่ commit เข้า repo

Gitleaks

SAST: Semgrep

Open source, pattern-based code scanning | 30+ ภาษา


# Scan with auto config
semgrep scan --config auto .

# Output JSON
semgrep scan --config auto --json --output results.json .

  • Pattern-based — เข้าใจโครงสร้าง code ไม่ใช่แค่ regex
  • เขียน custom rules ได้ง่าย
  • รองรับ Python, JavaScript, Java, Go, Ruby, etc.

SCA: Syft + Dependency-Track


Syft

SBOM Generator

# Generate SBOM
syft . -o cyclonedx-json > sbom.json

# Scan container
syft <image> -o cyclonedx-json

Dependency-Track

Vulnerability Management

  • Import SBOM แล้ววิเคราะห์ CVEs
  • Dashboard risk score
  • Policy violations
  • REST API สำหรับ CI/CD

DefectDojo

รวมผลจาก tools ทั้งหมด (150+ importers) — deduplicate, track, report

Secret Scanning: Gitleaks

ค้นหา API keys, passwords, tokens ที่หลุดเข้า Git


# Scan repo
gitleaks detect --source . \
  --report-format json \
  --report-path gitleaks-report.json

# Pre-commit hook (ป้องกันก่อน commit)
gitleaks protect --staged

  • Scan ทั้ง Git history + uncommitted changes
  • ตรวจจับด้วย regex + entropy analysis
  • Custom rules ผ่าน .gitleaks.toml

Session 4

Hands-on Lab
Security Scanning

50 minutes

Lab Setup

# Clone workshop repo
git clone https://github.com/Wsangsrichan/DEVDAY-EP-3.git
cd DEVDAY-EP-3/lab/vulnerable-app

# Verify tools
semgrep --version
syft --version
gitleaks version

Lab checklist: docs/lab-checklist.md

Part A: SAST with Semgrep

15 minutes


# Step 1: Run scan
semgrep scan --config auto --json --output results.json .

# Step 2: View results
cat results.json | python3 -m json.tool | less

วิเคราะห์ผลลัพธ์

  • จัดกลุ่มตาม severity: Critical High Medium
  • ดู rule ID, message, file path, line number
  • เปรียบเทียบกับ manual review — tool พบอะไรที่พลาด?

Part B: SCA with Syft + Dependency-Track

10 minutes


# Step 1: Generate SBOM
syft . -o cyclonedx-json > sbom.json

# Step 2: View SBOM contents
cat sbom.json | python3 -m json.tool | head -50

# Step 3: Upload to Dependency-Track (Web UI or API)
curl -X POST "http://localhost:8081/api/v1/bom" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -F "project=PROJECT_UUID" \
  -F "bom=@sbom.json"

  • ดู dashboard: vulnerabilities แบ่งตาม severity
  • ตรวจสอบ CVE ID, CVSS score, fixed version

Part C: Secret Scanning with Gitleaks

10 minutes


# Step 1: Run scan
gitleaks detect --source . \
  --report-format json \
  --report-path gitleaks-report.json

# Step 2: View results
cat gitleaks-report.json | python3 -m json.tool

วิเคราะห์ผลลัพธ์

  • Secret type: API key, password, token, private key
  • แยก true positive vs false positive
  • แนวทาง: ย้ายไป env vars, rotate credentials ทันที

Exercise 3: Fix & Validate

10 minutes


เลือก 3-5 critical vulnerabilities แล้วแก้ไข:


  • SQL concatenation → parameterized query
  • เพิ่ม input validation / output encoding
  • ลบ hardcoded secrets → env variables
  • Update vulnerable dependencies

# Re-scan to verify fixes
semgrep scan --config auto .
gitleaks detect --source .

Solutions: lab/solutions/

Part D: Docker Security Review

10 minutes


ตรวจสอบ Dockerfile และ docker-compose.yml ใน lab/vulnerable-app/


ช่องโหว่ที่ซ่อนไว้:

root container secrets in plaintext no resource limits no healthcheck unpinned image debug port exposed DB port to host no auth on Redis no .dockerignore shell form CMD

Why Docker Security Matters

Container ≠ Isolation — ขอบเขตที่โดนเปิดเผยโดยการ misconfiguration


Container ≠ VM

  • Container แชร์ kernel กับ host — ไม่ใช่ VM
  • Default: container มี full Linux capabilities
  • Root in container = root on host (เรื่อง kernel exploit)
  • Shared kernel = container escape เป็นไปได้

Attack Surface

  • Image layer: ไม่ pin version = อาจมี CVE ใน base image
  • Build context: COPY . ดึง .git, .env เข้า image
  • Runtime: root + no limits = DDoS + privilege escalation
  • Network: exposed ports + no segmentation
  • Secrets: env vars visible in docker inspect

84%
ของ production containers มี critical/high vulnerabilities
(Sysdig 2024 State of Container Security Report)

Image Security: Layers & Supply Chain


Container Image = Stack of Read-Only Layers


Layer 1 (base):    python:3.12-slim-bookworm     ← OS + runtime
Layer 2 (deps):    pip install -r requirements.txt  ← Your dependencies
Layer 3 (app):     COPY app.py /app/                 ← Your code
Layer 4 (config):  CMD ["python", "app.py"]         ← Entrypoint

Common Image Vulnerabilities

  • Base image มี CVE — พ.ค. 2024 Alpine ถูกตรวจพบ backdoor 3 ปี
  • Supply chain attack — malicious package ปลอยเป็น legit library
  • Stale images — ไม่ rebuild นาน = CVEs สะสม
  • Fat images — เลือก -slim แทน full image ลด attack surface

# Scan image for vulnerabilities
docker scout cve python:3.12-slim-bookworm

# Pin by digest (immutable) — ไม่แปลี่ยนถ้าไม่อัปเดตระบุ
FROM python:3.12-slim-bookworm@sha256:abc123...

# Or pin by version + use SBOM
syft python:3.12-slim-bookworm -o cyclonedx-json

Container Escape: What Happens When Root?


ถ้า container รันเป็น root + kernel CVE:

# Inside container (root)
# CVE-2024-1086 (netfilter) — container escape exploit
python3 exploit.py
# → ได้ shell บน host machine เลย!

# Attack chain:
# 1. App vulnerability (SQLi, RCE) → code execution in container
# 2. Container root → exploit kernel capability
# 3. Container escape → full access to host
# 4. Host access → pivot ไป containers/processes อื่นใน cluster

Defense: Drop Capabilities

# docker-compose.yml
security_opt:
  - no-new-privileges:true     # ห้าม escalate privileges
  - cap-drop:                 # ทิ้งทุก Linux capabilities
    - ALL
  - cap-add:
    - NET_BIND_SERVICE         # เฉพาะที่จำเป็นจริง

# Dockerfile
USER appuser  # เรียบร้อย — ไม่มี root เลย

Default container มี ~14 capabilities เปิดอยู่ — ส่วนใหญ่ไม่จำเป็น

Secrets Management in Containers


ทำไม env vars ไม่ปลอดภัย?

# ทุกคนเห็น secrets ถ้ามี access ถึง container
$ docker inspect vulnerable-app
# → environment section: แสดงทุก env var รวม passwords

$ docker compose config
# → แสดงทุก secret ใน compose file อ่านง่าย

# ถ้า push image ไป registry:
# → env vars อยู่ใน image layers (ใคร pull ก็เห็น)

Better Approaches

MethodProsCons
Docker Secretsencrypted at rest, not in layersSwarm only (ไม่มี K8s)
K8s Secretsencrypted, RBAC, versionedต้องมี K8s cluster
Vault / AWS SMrotation, audit, centralizedcomplexity, dependency
_FILE suffixง่าย, ใช้ได้กับ secretsยังต้องจัดการ file permissions

Docker Scanning Tools


ToolScansใช้ใน CI/CD
Docker Scout Image CVEs, SBOM, advice Built-in Docker CLI
Trivy Image, filesystem, IaC, secrets Free, comprehensive
Syft SBOM generation (CycloneDX/SPDX) Already in our lab
Grype Vulnerabilities from SBOM Pairs with Syft
Hadolint Dockerfile best practices Lint rules
Dockle Image analysis, size, policy Free

# Scan image for CVEs
trivy image python:3.12-slim-bookworm

# Scan Dockerfile for best practices
hadolint Dockerfile

# Generate SBOM + scan for vulns
syft . -o cyclonedx-json | grype sbom:

Dockerfile Vulnerabilities


#VulnerabilityRiskImpact
1FROM python:latest — ไม่ pin versionMediumImage ไม่ reproducible, อาจมี CVE
2ไม่มี USER — รันเป็น rootCriticalContainer escape → host compromise
3COPY . — ไม่มี .dockerignoreMedium.git, .env, secrets หลุดเข้า image
4ไม่มี HEALTHCHECKHighDead container ไม่ถูก restart
5CMD python app.py — shell formLowSIGTERM ไม่ถึง app, zombie processes
6ไม่มี multi-stage buildMediumBuild tools + source อยู่ใน final image
7ไม่มี resource limitsHighDDoS, crypto mining, fork bomb

docker-compose.yml Vulnerabilities


#VulnerabilityRiskImpact
8Secrets เป็น plaintext env varsCriticaldocker inspect, image layers
9ports: "5000:5000" — bind all interfacesHighทุกคนบน internet เข้าถึงได้
10DB port 5432 exposed to hostHighBrute force DB, extract data
11Redis ไม่มี requirepassCriticalอ่าน/เขียน cache ได้ทุกคน
12ไม่มี network segmentationHighcompromised app → pivot to DB
13Host volume mounts ./uploads:/appMediumContainer อ่าน/เขียน host filesystem
14ไม่มี no-new-privilegesHighSetuid binary → privilege escalation

Secure Dockerfile — Key Fixes

# Pin version + use slim image (reduced attack surface)
FROM python:3.12-slim-bookworm

# Non-root user — container escape ยากขึ้นมาก
RUN groupadd -r appuser && useradd -r -g appuser appuser

# Multi-stage build — final image: app code + runtime only
FROM python:3.12-slim-bookworm AS builder
COPY --from=builder /root/.local /home/appuser/.local

# Healthcheck — Docker รู้ว่า app ตาย แล้ว restart
HEALTHCHECK CMD python -c "..."

# Exec form — PID 1 = app, SIGTERM ทำงาน
CMD ["python", "app.py"]

# Run as non-root (ทำที่สุดท้าย!)
USER appuser

Secure docker-compose.yml — Key Fixes

Secrets

secrets:
  db_password:
    file: ./secrets/db_password.txt

services:
  app:
    secrets:
      - db_password
    environment:
      - DB_PASSWORD_FILE=/run/secrets/db_password

Hardening

services:
  app:
    ports:
      - "127.0.0.1:5000:5000"
    security_opt:
      - no-new-privileges:true
    read_only: true
    deploy:
      resources:
        limits:
          cpus: "1.0"
          memory: 256M
    healthcheck:
      test: ["CMD", "python", "-c", "..."]

networks:
  backend:
    internal: true

Session 5

CI/CD Integration
& Best Practices

20 minutes

Security in CI/CD Pipeline


StageToolAction
Pre-commitGitleaksBlock secrets before commit
Pull RequestSemgrepSAST scan, block on Critical/High
BuildSyftGenerate SBOM
Post-buildDependency-TrackAnalyze vulnerabilities
WeeklyFull scanReport to team

GitHub Actions Example

name: Security Scan
on: [pull_request]

jobs:
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Semgrep SAST
        uses: semgrep/semgrep-action@v1
        with:
          config: auto

      - name: Gitleaks Secret Scan
        uses: gitleaks/gitleaks-action@v2

      - name: Generate SBOM
        run: |
          curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s
          syft . -o cyclonedx-json > sbom.json

      - name: Upload SBOM
        uses: actions/upload-artifact@v4
        with:
          name: sbom
          path: sbom.json

Best Practices


  • Scan Early, Scan Often — ยิ่ง scan เร็ว ค่าแก้ยิ่งต่ำ
  • Automate Everything — security เป็นส่วนหนึ่งของ pipeline
  • Fix Critical First — จัดลำดับตาม severity
  • Track Security Debt — บันทึกและติดตาม issues
  • Regular Updates — อัพเดท dependencies สม่ำเสมอ
  • Security in Every PR — ทุก review มีมุมมอง security
  • Security Champions — มี champion ในแต่ละทีม

Wrap-up


What We Covered

  • OWASP Top 10
  • Manual code review
  • Semgrep (SAST)
  • Syft + Dependency-Track (SCA)
  • Gitleaks (Secrets)
  • Docker security (Dockerfile + compose)
  • CI/CD integration

Tools Summary

SASTSemgrep
SCASyft
Vuln MgmtDependency-Track
AggregatorDefectDojo
SecretsGitleaks
ContainerTrivy, Syft
CI/CDGitHub Actions

Q&A


Resources:

  • OWASP Top 10 — owasp.org/Top10/2025
  • Semgrep — semgrep.dev
  • Syft — github.com/anchore/syft
  • Dependency-Track — dependencytrack.org
  • Gitleaks — github.com/gitleaks/gitleaks

Workshop materials: github.com/Wsangsrichan/DEVDAY-EP-3

Thank You!

Happy Secure Coding

Appendix

Security Dockerfile & Docker Compose

Self-study / Reference Material

Docker Security Scanning Checklist

#Check Item
1ใช้ minimal base image (Alpine/Distroless/slim)
2ไม่ run เป็น root (มี USER instruction)
3ใช้ multi-stage builds
4Pin base image version (SHA256 digest)
5มี .dockerignore (ไม่ COPY .git, .env, node_modules)
6ไม่มี secrets hardcode ใน Dockerfile/Compose
7ใช้ COPY แทน ADD
8มี HEALTHCHECK
9read_only: true + tmpfs สำหรับ writable dirs
10cap_drop: ALL + no-new-privileges
11Resource limits (CPU, memory, pids)
12Network segmentation (internal networks)
13Ports bind เฉพาะ localhost สำหรับ internal services
14Log size limits + centralized logging
15Scan image ด้วย Trivy/Syft ก่อน deploy