Skip to content

[Chore/#194] SecurityConfig CORS 설정 추가 - #195

Merged
tnals0924 merged 2 commits into
mainfrom
chore/#194-cors-config
Oct 29, 2026
Merged

tnals0924 merged 2 commits into
mainfrom
chore/#194-cors-config

Conversation

@tnals0924

Copy link
Copy Markdown
Member

#️⃣연관된 이슈

🎯 해결하려는 문제가 무엇인가요?

  • SecurityConfig에 CORS 설정이 없어, 다른 origin에서 뜬 웹 클라이언트가 API를 호출하면 브라우저가 막습니다.
  • 특히 Authorization 헤더가 붙은 요청은 preflight(OPTIONS)를 거치는데, 이 요청에 CORS 응답 헤더가 없어 실제 요청이 나가지 못합니다.

❓ 왜 해결해야 하나요?

  • 운영진 콘솔·학생 웹 등 브라우저 클라이언트가 API 서버와 다른 origin에서 서비스되므로 CORS 허용이 필요합니다.
  • 허용 origin은 dev/prod 환경마다 다르므로 코드가 아닌 설정값으로 관리해야 합니다.

⭐ 어떻게 해결했나요?

  • application-gateway-auth.yml에 cors.allowed-origins: ${CORS_ALLOWED_ORIGINS} 추가 (쉼표 구분으로 여러 개)
  • CorsProperties record(@ConfigurationProperties(prefix = "cors"))로 List<String> 바인딩
  • SecurityConfig에 .cors(...)로 CorsConfigurationSource 연결, 전체 경로(/**)에 적용
    • 허용 메서드: GET, POST, PUT, PATCH, DELETE, OPTIONS
    • 허용 헤더: Authorization, Content-Type
    • credentials: 설정하지 않음(기본값 비허용)
  • .env.example에 CORS_ALLOWED_ORIGINS 추가
  • 테스트 클래스패스의 application-gateway-auth.yml(main 파일을 가림)에 더미 origin 추가

🧩 이 PR의 한계 & 트레이드오프

  • 허용 헤더를 Authorization, Content-Type으로 좁혔습니다. 클라이언트가 다른 헤더를 보내게 되면 목록에 추가해야 합니다.
  • credentials를 허용하지 않으므로 쿠키 기반 인증(예: refresh token 쿠키)을 도입하면 설정을 바꿔야 합니다. 현재 JWT는 Authorization 헤더로만 전달합니다.
  • 응답 헤더 노출(exposedHeaders), preflight 캐시(maxAge)는 설정하지 않았습니다.

⛓️ 기존 기능에 미치는 영향

  • CORS_ALLOWED_ORIGINS는 기본값이 없는 필수값이라, 설정하지 않으면 앱이 시작되지 않습니다. 머지 전에 dev/prod 배포 환경변수와 각자 로컬 .env에 추가가 필요합니다.
  • 브라우저가 아닌 클라이언트(모바일 앱, 서버 간 호출)는 Origin 헤더를 보내지 않으므로 영향이 없습니다.

🔀 Edge Case & 실패 시나리오

  • 허용 목록에 없는 origin의 요청은 Spring Security CorsFilter가 403으로 거절합니다.
  • origin은 스킴·호스트·포트까지 정확히 일치해야 합니다(http://localhost:5173 ≠ http://127.0.0.1:5173). 끝에 /를 붙이지 않습니다.
  • preflight 요청은 CorsFilter가 인가 필터보다 앞에서 처리하므로 인증 없이 응답됩니다.

📋 검토한 대안과 선택 이유

  • origin을 yml에 직접 나열: 환경별로 값이 달라 매번 코드 수정이 필요하므로, KCONNECT_ALLOWED_REDIRECT_URIS처럼 쉼표 구분 환경변수로 받았습니다.
  • allowedHeaders = *: 편하지만 현재 쓰는 헤더가 두 개뿐이라 필요한 헤더만 열었습니다.
  • CorsConfigurationSource를 @Bean으로 등록: 다른 곳에서 쓰지 않아 SecurityConfig 안의 private 메서드로 두었습니다.

💬 리뷰 포인트

  • [r] dev/prod 배포 환경변수에 CORS_ALLOWED_ORIGINS 등록 후 머지해야 합니다. 등록할 origin 목록 확인 부탁드립니다.
  • 프론트에서 Authorization, Content-Type 외에 보내는 헤더가 있는지 확인 부탁드립니다.

@tnals0924 tnals0924 self-assigned this Oct 29, 2026
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between dd208d1 and 27f2239.

Files selected for processing: 5
  • .env.example
  • bootstrap/src/test/resources/application-gateway-auth.yml
  • gateway/auth/src/main/java/kr/ac/kookmin/stream/security/config/CorsProperties.java
  • gateway/auth/src/main/java/kr/ac/kookmin/stream/security/config/SecurityConfig.java
  • gateway/auth/src/main/resources/application-gateway-auth.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

CORS 허용 출처를 환경변수 설정으로 바인딩하고, 보안 필터 체인에 CORS 정책을 추가했습니다. 정책은 모든 경로에 적용되며 지정된 HTTP 메서드와 헤더를 허용합니다.

Changes: CORS 설정

Layer / File(s) Summary
허용 출처 설정 바인딩
.env.example, bootstrap/src/test/resources/application-gateway-auth.yml, gateway/auth/src/main/java/kr/ac/kookmin/stream/security/config/CorsProperties.java, gateway/auth/src/main/resources/application-gateway-auth.yml
cors.allowed-origins를 CORS_ALLOWED_ORIGINS 환경변수에서 읽고 CorsProperties에 바인딩합니다. 예시 및 테스트 설정에는 http://localhost:5173을 지정합니다.
보안 필터 체인에 CORS 정책 연결
gateway/auth/src/main/java/kr/ac/kookmin/stream/security/config/SecurityConfig.java
보안 필터 체인에 CORS 설정을 연결합니다. 구성된 허용 출처와 GET, POST, PUT, PATCH, DELETE, OPTIONS 메서드 및 Authorization, Content-Type 헤더를 모든 경로에 적용합니다.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: xeoxxn

Merge Risk: Minimal · up to 27f22

This change adds configurable CORS origins and connects them to the security filter chain. No code defect was found. Before deploying, make sure CORS_ALLOWED_ORIGINS is set in the dev and prod environments, because the app will not start without it.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning 직접 연결된 이슈 #194의 CORS 코딩 요구사항 대부분을 구현했습니다. gateway/auth/src/main/resources/application-gateway-auth.yml은 CORS_ALLOWED_ORIGINS를 cors.allowed-origins에 바인딩합니다. CorsProperties는 `@ConfigurationPrope… dev/prod 배포 환경에 실제 CORS_ALLOWED_ORIGINS 값을 등록하고, 해당 등록이 완료되었음을 검증 가능한 저장소 또는 배포 설정 근거로 남기십시오.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed PR 제목이 SecurityConfig의 CORS 설정 추가라는 주요 변경 사항을 명확하고 간결하게 설명합니다.
Description check Passed 연관 이슈, 문제와 원인, 구현 방식, 한계, 영향 범위, 실패 시나리오, 대안, 리뷰 포인트를 모두 작성했습니다. CORS_ALLOWED_ORIGINS를 배포 환경에 등록해야 한다는 후속 조건도 명시했습니다.
Out of Scope Changes check Passed 변경 범위는 이슈 #194의 CORS 설정과 직접 연결됩니다. 모듈별 yml, 루트 .env.example, 설정 바인딩 record, SecurityConfig의 CORS 필터 연결, 테스트 클래스패스 설정만 변경했습니다. 문서의 설정 컨벤션인 모듈별 yml 관리, 환경변수 참조, @ConfigurationProperties record 사용과…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Out of Scope Changes check

Explanation

변경 범위는 이슈 #194의 CORS 설정과 직접 연결됩니다. 모듈별 yml, 루트 .env.example, 설정 바인딩 record, SecurityConfig의 CORS 필터 연결, 테스트 클래스패스 설정만 변경했습니다. 문서의 설정 컨벤션인 모듈별 yml 관리, 환경변수 참조, @ConfigurationProperties record 사용과도 일치합니다.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files. (3 skipped: 3 unsupported.)

Full details: Linked Issues check

Explanation

직접 연결된 이슈 #194의 CORS 코딩 요구사항 대부분을 구현했습니다. gateway/auth/src/main/resources/application-gateway-auth.yml은 CORS_ALLOWED_ORIGINS를 cors.allowed-origins에 바인딩합니다. CorsProperties는 @ConfigurationProperties(prefix = "cors") record입니다. SecurityConfig는 /** 경로에 지정된 메서드와 Authorization, Content-Type 헤더를 적용하고 credentials를 활성화하지 않습니다. .env.example와 테스트 설정도 갱신했습니다. 그러나 이슈 #194가 요구한 dev/prod 배포 환경의 CORS_ALLOWED_ORIGINS 등록 변경은 PR diff에 없습니다. PR 설명도 이 작업이 머지 전에 필요하다고 명시합니다.

Resolution

dev/prod 배포 환경에 실제 CORS_ALLOWED_ORIGINS 값을 등록하고, 해당 등록이 완료되었음을 검증 가능한 저장소 또는 배포 설정 근거로 남기십시오.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@tnals0924
tnals0924 merged commit 9cf43c6 into main Oct 29, 2026
2 checks passed
@tnals0924
tnals0924 deleted the chore/#194-cors-config branch October 29, 2026 08:26
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.

SecurityConfig CORS 설정 추가

2 participants