Skip to content

Conversation

@lvalentine6
Copy link
Member

@lvalentine6 lvalentine6 commented Sep 23, 2025

✨ 개요

  • 임시로 적용했던 ua 조건 검사를 삭제하고, x-origin-verify Header를 추가하여 정의된 요청만 WAF를 통과하게 수정하였습니다.
  • 노드서버-서버 간 요청은 x-origin-verify Header 검증, 나머지 기본 CSR 요청은 CORS로 검증합니다.
  • Parameter Store에 CLIENT_HEADER_SECRET을 추가했으며, 클라이언트와 협업하여 적용을 마쳤습니다.
  • 변경 후, 로그인이 정상적으로 완료되는 것을 확인했습니다.

🧾 관련 이슈

Close #202

🔍 참고 사항 (선택)

Summary by CodeRabbit

  • New Features

    • 원본 검증 헤더 기반 허용 규칙과 브라우저 유사 요청 허용 규칙을 추가해 정상 트래픽 통과를 개선했습니다.
    • 로그에서 특정 민감 헤더를 마스킹하도록 로깅 구성을 강화했습니다.
  • Bug Fixes

    • 웹 ACL 기본 동작을 차단으로 변경하고, 레이트 리밋과 AWS 관리 규칙 우선순위를 재정렬해 불필요한 차단을 줄였습니다.
  • Chores

    • 임시 User-Agent 차단 규칙 및 관련 예외를 제거하고 요청 임계값을 상향(200→2000)했습니다.

@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2025

Walkthrough

웹 ACL의 기본 동작을 allow→block으로 변경하고 SSM 파라미터 기반 x-origin-verify 검증 규칙 및 브라우저/검증된 서버 허용 규칙을 추가했습니다. AWS Managed Rules 우선순위를 재배치하고 임시 Non-Node UA 차단 규칙 및 Bot-Control의 action_override를 제거했습니다. 로깅 구성에 x-origin-verify 헤더 redaction을 추가했고, 로컬 변수에서 admin_email을 제거하고 request_threshold를 200→2000으로 변경했습니다.

Changes

Cohort / File(s) Summary
WAF 메인 구성
terraform/common/waf/main.tf
- data "aws_ssm_parameter" "x_origin_verify" 추가 (x-origin-verify 값 조회)
- Web ACL default_action allowblock 변경
- 새 Allow 규칙 Allow-Verified-Server-Requests 추가: User-Agentnode 또는 Vercel 포함 AND x-origin-verify 헤더가 SSM 값과 정확히 일치하면 Allow (byte_match EXACT), 전용 visibility_config 및 metric_name 포함
- 새 Allow 규칙 Allow-Browser-Requests 추가: origin 또는 referer header size_constraint > 0이면 Allow, visibility_config 포함
- Rate-Limit-Rule 우선순위 1 → 20 (action: block, rate-based 유지)
- 여러 AWS Managed Rule 우선순위 재배치(예: Core 10→30, Known-Bad-Inputs 20→40, IP-Reputation 30→50, Bot-Control 40→60) 및 metric_name 업데이트
- AWSManagedRulesBotControlRuleSet 내의 rule_action_override 제거
- 임시 규칙 Block-Non-Node-User-Agents 삭제(관련 action/visibility 제거)
- Anonymous-IP-List, SQLi 등 우선순위 재조정
로컬 변수 변경
terraform/common/locals.tf
- admin_email 항목 제거
- request_threshold 값 200 → 2000으로 증가
로깅 구성 변경
terraform/common/main.tf
- aws_wafv2_web_acl_logging_configuration 리소스에 redacted_fields 블록 추가: x-origin-verify 헤더를 로깅에서 마스킹하도록 설정

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as 클라이언트
  participant E as 엣지(CloudFront/ALB)
  participant W as WAF v2
  participant S as SSM Parameter Store

  C->>E: HTTP 요청 (헤더 포함)
  E->>W: WebACL 평가 시작
  Note over W: 주요 변경사항\n- Allow-Verified-Server-Requests (UA 포함 + x-origin-verify EXACT)\n- Allow-Browser-Requests (origin/referer 존재)\n- Rate-Limit 및 Managed Rule 우선순위 변경\n- 로깅 시 `x-origin-verify` 헤더 마스킹
  W->>S: (plan/apply 시) `x_origin_verify` 파라미터 참조
  alt UA contains "node" or "Vercel" AND x-origin-verify == secret
    W-->>E: Allow (Verified server path)
  else origin or referer size > 0
    W-->>E: Allow (Browser-like path)
  else rate-limit or managed-rule 트리거
    W-->>E: Block (403)
  end
  E-->>C: 응답 반환
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

토끼가 킁킁, 비밀 헤더 냄새 맡아 🐇
검증된 서버엔 길을 터주고,
브라우저 손님엔 문을 활짝 열고,
로그 속 비밀은 살포시 가려주네,
로그인 길은 다시 당근처럼 반짝.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning PR에는 WAF 관련 변경 외에 terraform/common/locals.tf에서 admin_email 제거 및 request_threshold를 200→2000으로 상향한 변경이 포함되어 있는데 이는 링크된 이슈의 설명에 명시되지 않은 항목으로 운영 영향(레이트 리밋 민감도 등)을 줄 수 있어 범위를 벗어난 변경으로 판단됩니다. 반면 SSM 파라미터 조회 추가와 x-origin-verify 헤더 로그 마스킹 등은 이슈 목적과 연관된 변경입니다. 전체적으로 일부 로컬 변수 변경은 별도 검토가 필요합니다. locals.tf에서의 admin_email 삭제와 request_threshold 변경은 별도 PR로 분리하거나 변경 사유와 영향(레이트 리밋 동작, 모니터링/알림 영향)을 PR 설명에 명확히 기재해 주세요; 변경이 의도된 경우 관련 리소스 참조 제거와 동작 검증 결과를 첨부해 주세요. 필요 시 팀 합의를 거쳐 해당 변경을 적용하고, 그렇지 않으면 해당 커밋을 되돌려 WAF 관련 변경만 머지하도록 하십시오.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 제목은 PR의 핵심 변경사항인 "UA 조건 제거"와 "x-origin-verify 헤더 검사 추가"를 간결하게 요약하고 있으며 변경 의도를 명확하게 전달합니다. 불필요한 파일 목록이나 이모지 없이 읽기 쉬운 한 문장 구조로 작성되어 있어 히스토리 스캔 시 주요 변경을 바로 파악할 수 있습니다. 따라서 제목은 적절합니다.
Linked Issues Check ✅ Passed 제안된 코드 변경은 링크된 이슈 #202의 목표와 일치합니다; UA 기반 임시 허용을 제거하고 노드 서버 요청에 대해 x-origin-verify 헤더로 검증하도록 구현했으며 SSM 파라미터 조회와 해당 헤더 로그 마스킹도 추가되어 보안과 기능 양쪽 요구를 충족합니다. PR 설명에서 로그인 성공이 확인되었다고 명시되어 있어 로그인 차단 문제 해결 목적을 달성한 것으로 보입니다. 따라서 코드 변경은 이슈 요구사항을 충족합니다.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hotfix/PRODUCT-284

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
Copy link

📄 Terraform Plan Summary

🛡️ Common Infrastructure


No plan summary

Status: ✅ No Changes


🛠️ Development Environment


No plan summary

Status: ✅ No Changes


📋 Full Results: View in Actions

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
terraform/common/waf/main.tf (2)

1-3: SSM 파라미터가 SecureString이면 복호화 옵션 추가 필요

SecureString일 경우 with_decryption 미설정 시 plan/apply 실패하거나 암호문이 들어갈 수 있습니다. 또한 state에 평문 비밀값이 저장되므로(필연적) 백엔드(S3/KMS 등) 암호화·권한을 반드시 확인하세요. Terraform IAM에 ssm:GetParameter, kms:Decrypt 권한도 점검 바랍니다.

다음 수정 제안:

 data "aws_ssm_parameter" "x_origin_verify" {
   name = "/common/CLIENT_HEADER_SECRET"
+  with_decryption = true
 }

33-64: 회전(로테이션) 가능하게 2개 토큰 동시 허용 고려

무중단 비밀 회전을 위해 현재값과 차기값을 OR로 허용하도록 구성(RegexPatternSet 또는 두 개의 byte_match OR)하면 롤아웃/롤백이 수월합니다. 운영 정책에 맞으면 추후 반영을 권장합니다.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0d300f and d37db31.

📒 Files selected for processing (1)
  • terraform/common/waf/main.tf (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test

@github-actions
Copy link

📄 Terraform Plan Summary

🛡️ Common Infrastructure


No plan summary

Status: ✅ No Changes


🛠️ Development Environment


No plan summary

Status: ✅ No Changes


📋 Full Results: View in Actions

@github-actions
Copy link

📄 Terraform Plan Summary

🛡️ Common Infrastructure

  ~ update in-place
  ~ resource aws_wafv2_web_acl this {
Plan: 0 to add, 1 to change, 0 to destroy.

Status: 🔄 Changes Detected


🛠️ Development Environment


No plan summary

Status: ✅ No Changes


📋 Full Results: View in Actions

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
terraform/common/waf/main.tf (1)

133-136: 레이트 제한 값 참조 오류 가능성 — var → local 정합성

현재 limit = var.request_threshold인데, 변경된 값은 locals.tflocal.request_threshold입니다. 불일치로 인해 2000이 적용되지 않을 수 있습니다. 한쪽으로 통일하세요.

즉시 적용 예:

-        limit              = var.request_threshold
+        limit              = local.request_threshold
🧹 Nitpick comments (1)
terraform/common/waf/main.tf (1)

79-124: 브라우저 식별 강화를 검토

Origin/Referer 존재만으로 허용하면 비브라우저가 임의 헤더로 우회 가능합니다. Sec-Fetch-Site(또는 Sec-Fetch-Mode) 존재 조건을 추가하면 완화됩니다.

예시(OR에 추가):

       or_statement {
         statement { ... origin size > 0 ... }
         statement { ... referer size > 0 ... }
+        statement {
+          size_constraint_statement {
+            field_to_match { single_header { name = "sec-fetch-site" } }
+            comparison_operator = "GT"
+            size                = 0
+            text_transformation { priority = 0 type = "NONE" }
+          }
+        }
       }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a400c77 and b08b672.

📒 Files selected for processing (2)
  • terraform/common/locals.tf (1 hunks)
  • terraform/common/waf/main.tf (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
terraform/common/locals.tf (1)

253-254: Rate limit 값 변경이 WAF에 반영되지 않을 수 있음 — var vs local 불일치 확인 필요

위치: terraform/common/locals.tf:253-254
local.request_threshold = 2000으로 설정했으나 WAF가 var.request_threshold를 참조하면 변경이 반영되지 않습니다. WAF가 local.request_threshold를 사용하도록 수정하거나 variables.tf의 기본값/모듈 입력을 2000으로 업데이트하세요.

자동 검색이 실패했습니다. 레포 루트에서 사용처/변수 정의를 직접 확인하세요:
rg -n 'var.request_threshold|local.request_threshold' || true
rg -n 'variable\s*"request_threshold"' || true

@github-actions
Copy link

📄 Terraform Plan Summary

🛡️ Common Infrastructure

  ~ update in-place
  ~ resource aws_wafv2_web_acl_logging_configuration this {
  ~ resource aws_wafv2_web_acl this {
Plan: 0 to add, 2 to change, 0 to destroy.

Status: 🔄 Changes Detected


🛠️ Development Environment


No plan summary

Status: ✅ No Changes


📋 Full Results: View in Actions

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
terraform/common/main.tf (1)

77-81: 민감 헤더 추가 스크러빙 제안 (Authorization, Cookie).

운영 로그에 자격증명/세션 정보가 남지 않도록 Authorization, Cookie도 함께 마스킹하는 것을 권장합니다.

아래와 같이 redacted_fields 블록을 추가해 주세요:

 resource "aws_wafv2_web_acl_logging_configuration" "this" {
   log_destination_configs = [trimsuffix(aws_cloudwatch_log_group.waf_logs.arn, ":*")]
   resource_arn            = module.waf.web_acl_arn
   redacted_fields {
     single_header {
       name = "x-origin-verify"
     }
   }
+  redacted_fields {
+    single_header {
+      name = "authorization"
+    }
+  }
+  redacted_fields {
+    single_header {
+      name = "cookie"
+    }
+  }
 }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b08b672 and 86a7f42.

📒 Files selected for processing (1)
  • terraform/common/main.tf (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
terraform/common/main.tf (1)

77-81: 로그 스크러빙에 x-origin-verify 추가 — WAF 매칭 확인됨

terraform/common/main.tf의 redacted_fields와 terraform/common/waf/main.tf의 single_header(byte_match_statement)에서 동일한 소문자 "x-origin-verify" 사용을 확인했습니다.

@lvalentine6
Copy link
Member Author

/noti
알림보내줘~

Copy link
Member

@leegwichan leegwichan left a comment

Choose a reason for hiding this comment

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

/noti 서비스 신경써주셔서 감사함니다 LGTM~!

@lvalentine6 lvalentine6 merged commit f7539c6 into develop Sep 24, 2025
10 checks passed
@lvalentine6 lvalentine6 deleted the hotfix/PRODUCT-284 branch September 24, 2025 15:04
@github-actions
Copy link

🎉 This PR is included in version 1.8.0-develop.16 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Oct 1, 2025

🎉 This PR is included in version 1.9.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

[PRODUCT-284] [Hotfix] WAF 설정으로 인한 로그인 실패 해결

3 participants