Skip to content

refactor: 크롤링 봇에 대한 요청 차단 nginx 로직 추가#43

Open
Hexeong wants to merge 2 commits into
mainfrom
refactor/21-deny-crawling-bot
Open

refactor: 크롤링 봇에 대한 요청 차단 nginx 로직 추가#43
Hexeong wants to merge 2 commits into
mainfrom
refactor/21-deny-crawling-bot

Conversation

@Hexeong

@Hexeong Hexeong commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

작업 내용

크롤링 봇의 취약점 탐색 요청을 Nginx 수준에서 차단하여 서버 로그 오염을 방지합니다.

변경 파일: modules/app_stack/scripts/nginx_setup.sh.tftpl

1차 차단 — IP 직접 접근 및 알 수 없는 Host 헤더 차단

default_server 블록을 80/443 포트에 추가하여 도메인과 일치하지 않는 모든 요청을 444로 차단합니다.

  • IP 직접 접근(예: http://1.2.3.4/)
  • 등록되지 않은 Host 헤더를 사용하는 요청

444는 응답 body 없이 연결을 즉시 종료하는 nginx 전용 코드로, 봇 입장에서 포트가 닫힌 것처럼 인식됩니다.

2차 차단 — 취약점 탐색용 정적 파일 확장자 요청 차단

Spring Boot API 서버에 도달할 이유가 없는 정적 파일 확장자 요청을 location 블록으로 차단합니다.

차단 대상: .php .asp .aspx .jsp .cgi .env .git .sql .bak .backup .config .ini .log .sh .xml .txt .html .htm

특이 사항

  • prod, stage 두 환경 모두 terraform plan 검증 완료 — null_resource.update_nginx 1개 replace만 발생, 다른 리소스 변경 없음
  • upstream.confif [ ! -f ] 가드가 있어 재프로비저닝 시에도 현재 Blue/Green 슬롯이 유지됨

리뷰 요구사항 (선택)

  • 2차 차단 확장자 목록(.txt, .html, .xml 등)이 서비스 운영 상 문제없는지 프론트 담당자 확인이 필요합니다

Summary by CodeRabbit

보안 개선

  • 버그 수정
    • Nginx 서버 설정에 보안 차단 기능 추가됨
    • Host 미일치 요청에 대한 연결 차단 구성 추가
    • 취약점 스캔 및 악성 파일 확장자 요청 차단 기능 추가

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Hexeong, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 24 minutes and 23 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84038235-9044-402f-8092-97667737b3b7

📥 Commits

Reviewing files that changed from the base of the PR and between d5d4555 and 0c7dc50.

📒 Files selected for processing (1)
  • modules/app_stack/scripts/nginx_setup.sh.tftpl
📝 Walkthrough

Walkthrough

nginx_setup.sh.tftpl 템플릿에 23줄이 추가됨. 80/443 포트의 default_server에서 server_name _로 Host 불일치 요청을 return 444로 즉시 종료하는 서버 블록 2개가 삽입되고, 443 SSL 서버 내부에 취약점 탐색에 사용되는 정적 파일 확장자 패턴(php, asp, env, git, sql 등)을 정규식으로 매칭해 return 444로 차단하는 location ~* 블록 1개가 추가됨.

Changes

Nginx 보안 차단 설정

Layer / File(s) Summary
default_server Host 불일치 및 악성 확장자 차단
modules/app_stack/scripts/nginx_setup.sh.tftpl
80/443 default_server에서 server_name _ 요청을 return 444로 즉시 종료하는 서버 블록 2개를 추가하고, 443 SSL 서버 내부에 php·asp·env·git·sql 등 취약점 탐색 확장자 패턴을 location ~* 정규식으로 매칭해 return 444로 차단하는 로케이션 블록 1개를 추가함.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 토끼가 서버 앞을 지킵니다
낯선 Host가 오면 444로 쫓아버려요
.php, .env, .git… 다 막아낼게요!
크롤링 봇아, 오늘도 헛발질이야 🥕
우리 서버 로그는 항상 깨끗해요 ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 주요 변경사항인 크롤링 봇 요청 차단 nginx 로직 추가를 명확히 반영하고 있습니다.
Description check ✅ Passed PR 설명이 템플릿의 필수 섹션을 모두 포함하며 변경사항, 특이사항, 리뷰 요구사항을 완벽히 기술했습니다.
Linked Issues check ✅ Passed 코드 변경사항이 #21 이슈의 모든 요구사항을 충족합니다: 1차 도메인별 필터링, 2차 정적 파일 확장자 차단.
Out of Scope Changes check ✅ Passed 모든 변경사항이 #21의 크롤링 봇 요청 차단 목표에 직접 관련되며 범위 벗어난 변경은 없습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/21-deny-crawling-bot

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

Terraform Plan: stage

Plan: 1 to add, 0 to change, 1 to destroy.

전체 plan 결과는 보안을 위해 댓글에 포함되지 않습니다. 워크플로우 실행 아티팩트를 확인하세요.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

Terraform Plan: prod

Plan: 1 to add, 0 to change, 1 to destroy.

전체 plan 결과는 보안을 위해 댓글에 포함되지 않습니다. 워크플로우 실행 아티팩트를 확인하세요.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/app_stack/scripts/nginx_setup.sh.tftpl`:
- Around line 95-98: The nginx location block regex in nginx_setup.sh.tftpl
currently uses a `$` anchor that only matches if the blocked extensions appear
at the very end of the path, allowing scanners to bypass it with paths like
`/backup.sql/download` or `/.env.production`. Modify the regex pattern to match
these extensions even when followed by a forward slash, query string, or other
path segments. Replace the strict end-of-string anchor with a pattern that
catches extensions followed by `/`, `?`, or end of string, and add explicit
dotfile patterns (like `\.env` without requiring an extension) to handle variant
forms like `.env.production` that scanners commonly exploit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb998afe-9b29-4a02-abc5-620c6c62bcdc

📥 Commits

Reviewing files that changed from the base of the PR and between c68bdbd and d5d4555.

📒 Files selected for processing (1)
  • modules/app_stack/scripts/nginx_setup.sh.tftpl

Comment thread modules/app_stack/scripts/nginx_setup.sh.tftpl
@Hexeong Hexeong self-assigned this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: nginx 수준에서 크롤링 봇에 대한 요청을 거부하도록 리팩토링

1 participant