From 9d2179e47a8d04c827383c96c2c85b6b5eb05bd3 Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Fri, 10 Apr 2026 09:52:53 +0900 Subject: [PATCH] =?UTF-8?q?security:=20=EC=9B=B9=EB=A3=A8=ED=8A=B8=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20=E2=80=94=20COPY=20.=20=E2=86=92=20COPY=20?= =?UTF-8?q?public/=20+=20nginx=20deny=203=EC=A4=91=20=EB=B0=A9=EC=96=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3개 서비스(system1/system2/system3 web)에서 Dockerfile, nginx.conf, docker-compose.yml이 외부 노출되는 취약점 수정. [구조 수정] - Dockerfile: COPY . → COPY public/ (정적 파일만 웹루트에 복사) - system3 uploads: plain prefix → ^~ (regex deny 우선순위 충돌 방지) [nginx deny (defense in depth)] - exact match: /Dockerfile, /docker-compose.yml, /nginx.conf, /.env, /.gitignore - prefix: ^~ /.git/ 디렉토리 전체 차단 - regex: 하위 경로 + 변형 대비 [CI 보안 게이트] - scripts/check-webroot-security.sh: 화이트리스트 방식, find + exact match Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/check-webroot-security.sh | 94 +++++++++++++++++++++++++++ system1-factory/web/Dockerfile | 12 +--- system1-factory/web/nginx.conf | 16 +++++ system2-report/web/Dockerfile | 5 +- system2-report/web/nginx.conf | 16 +++++ system3-nonconformance/web/Dockerfile | 5 +- system3-nonconformance/web/nginx.conf | 20 +++++- 7 files changed, 148 insertions(+), 20 deletions(-) create mode 100755 scripts/check-webroot-security.sh diff --git a/scripts/check-webroot-security.sh b/scripts/check-webroot-security.sh new file mode 100755 index 0000000..2bae06c --- /dev/null +++ b/scripts/check-webroot-security.sh @@ -0,0 +1,94 @@ +#!/bin/bash +set -euo pipefail + +# ============================================================================= +# 웹루트 보안 검증 스크립트 +# 배포 후 실행: docker 이미지 내 /usr/share/nginx/html에 허용된 파일만 있는지 확인 +# 화이트리스트 방식 — 허용되지 않은 파일이 있으면 FAIL +# ============================================================================= + +SERVICES=("system1-web" "system2-web" "system3-web") + +# 허용 목록 (줄바꿈 구분 — 공백 파일명 안전) +ALLOWED_system1_web="index.html +manifest.json +sw.js +logo.png +components +css +img +js +pages +static" + +ALLOWED_system2_web="push-sw.js +css +img +js +pages" + +ALLOWED_system3_web="ai-assistant.html +app.html +favicon.ico +issue-view.html +issues-archive.html +issues-dashboard.html +issues-inbox.html +issues-management.html +m +push-sw.js +reports-daily.html +reports-monthly.html +reports-weekly.html +reports.html +static +sw.js +uploads" + +FAIL=0 + +for service in "${SERVICES[@]}"; do + varname="ALLOWED_${service//-/_}" + allowed="${!varname}" + + echo "Checking $service..." + + # 컨테이너 생성만 (실행 안 함) → exec으로 검사 → 제거 + docker compose create --no-deps "$service" >/dev/null 2>&1 + container=$(docker compose ps -q "$service" | head -n1) + if [ -z "$container" ]; then + echo " FAIL: container not found for $service" + FAIL=1; continue + fi + + entries=$(docker exec "$container" \ + find /usr/share/nginx/html -maxdepth 1 -mindepth 1 -printf '%f\n' 2>/dev/null || true) + docker compose rm -f "$service" >/dev/null 2>&1 + + # 빈 webroot 체크 (COPY public/ 실패 감지) + if [ -z "$entries" ]; then + echo " FAIL: $service webroot is empty" + FAIL=1; continue + fi + + while IFS= read -r f; do + [ -z "$f" ] && continue + # -xF: 정확히 일치하는 줄만 (substring 매칭 방지) + if ! echo "$allowed" | grep -qxF "$f"; then + echo " FAIL: unexpected file in webroot → $f" + FAIL=1 + fi + done <<< "$entries" + + if [ $FAIL -eq 0 ]; then + echo " OK" + fi +done + +echo "" +if [ $FAIL -eq 0 ]; then + echo "✓ All web roots clean" +else + echo "✗ Security check FAILED — fix before deploying" +fi +exit $FAIL diff --git a/system1-factory/web/Dockerfile b/system1-factory/web/Dockerfile index bff6595..9ae7682 100644 --- a/system1-factory/web/Dockerfile +++ b/system1-factory/web/Dockerfile @@ -1,13 +1,5 @@ FROM nginx:alpine - -# 정적 파일 복사 -COPY . /usr/share/nginx/html/ - -# 디렉토리 권한 보정 (macOS에서 복사 시 700이 되는 문제 방지) -RUN find /usr/share/nginx/html -type d -exec chmod 755 {} + - COPY nginx.conf /etc/nginx/conf.d/default.conf - +COPY public/ /usr/share/nginx/html/ EXPOSE 80 - -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] diff --git a/system1-factory/web/nginx.conf b/system1-factory/web/nginx.conf index c3b6ed6..926063f 100644 --- a/system1-factory/web/nginx.conf +++ b/system1-factory/web/nginx.conf @@ -12,6 +12,22 @@ server { root /usr/share/nginx/html; index index.html; + # 민감 파일 차단 — exact match (^~ 우회 불가) + location = /Dockerfile { return 404; } + location = /docker-compose.yml { return 404; } + location = /nginx.conf { return 404; } + location = /.env { return 404; } + location = /.gitignore { return 404; } + + # .git 디렉토리 전체 차단 + location ^~ /.git/ { return 404; } + location = /.git { return 404; } + + # 민감 파일 차단 — regex (하위 경로 + 변형 대비) + location ~* (Dockerfile|docker-compose|\.env|nginx\.conf) { + return 404; + } + # HTML 캐시 비활성화 location ~* \.html$ { expires -1; diff --git a/system2-report/web/Dockerfile b/system2-report/web/Dockerfile index 7adfc79..9ae7682 100644 --- a/system2-report/web/Dockerfile +++ b/system2-report/web/Dockerfile @@ -1,8 +1,5 @@ FROM nginx:alpine - -COPY . /usr/share/nginx/html/ COPY nginx.conf /etc/nginx/conf.d/default.conf - +COPY public/ /usr/share/nginx/html/ EXPOSE 80 - CMD ["nginx", "-g", "daemon off;"] diff --git a/system2-report/web/nginx.conf b/system2-report/web/nginx.conf index c8150c0..80277a4 100644 --- a/system2-report/web/nginx.conf +++ b/system2-report/web/nginx.conf @@ -13,6 +13,22 @@ server { # 사진 업로드를 위한 body 크기 제한 (base64 인코딩 시 원본 대비 ~33% 증가) client_max_body_size 50m; + # 민감 파일 차단 — exact match (^~ 우회 불가) + location = /Dockerfile { return 404; } + location = /docker-compose.yml { return 404; } + location = /nginx.conf { return 404; } + location = /.env { return 404; } + location = /.gitignore { return 404; } + + # .git 디렉토리 전체 차단 + location ^~ /.git/ { return 404; } + location = /.git { return 404; } + + # 민감 파일 차단 — regex (하위 경로 + 변형 대비) + location ~* (Dockerfile|docker-compose|\.env|nginx\.conf) { + return 404; + } + # 정적 파일 캐시 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires 1h; diff --git a/system3-nonconformance/web/Dockerfile b/system3-nonconformance/web/Dockerfile index 7adfc79..9ae7682 100644 --- a/system3-nonconformance/web/Dockerfile +++ b/system3-nonconformance/web/Dockerfile @@ -1,8 +1,5 @@ FROM nginx:alpine - -COPY . /usr/share/nginx/html/ COPY nginx.conf /etc/nginx/conf.d/default.conf - +COPY public/ /usr/share/nginx/html/ EXPOSE 80 - CMD ["nginx", "-g", "daemon off;"] diff --git a/system3-nonconformance/web/nginx.conf b/system3-nonconformance/web/nginx.conf index 3bfc72b..234158d 100644 --- a/system3-nonconformance/web/nginx.conf +++ b/system3-nonconformance/web/nginx.conf @@ -12,6 +12,22 @@ server { root /usr/share/nginx/html; index issues-dashboard.html; + # 민감 파일 차단 — exact match (^~ 우회 불가) + location = /Dockerfile { return 404; } + location = /docker-compose.yml { return 404; } + location = /nginx.conf { return 404; } + location = /.env { return 404; } + location = /.gitignore { return 404; } + + # .git 디렉토리 전체 차단 + location ^~ /.git/ { return 404; } + location = /.git { return 404; } + + # 민감 파일 차단 — regex (하위 경로 + 변형 대비) + location ~* (Dockerfile|docker-compose|\.env|nginx\.conf) { + return 404; + } + # gzip 압축 gzip on; gzip_types text/plain text/css application/javascript application/json; @@ -79,8 +95,8 @@ server { } } - # 업로드 파일 - location /uploads/ { + # 업로드 파일 (^~ 로 regex deny보다 우선 매칭) + location ^~ /uploads/ { alias /usr/share/nginx/html/uploads/; expires 1y; add_header Cache-Control "public, immutable";