Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(#64): cors 적용 에러 #65

Merged
merged 3 commits into from
Feb 6, 2025
Merged

Conversation

pythonstrup
Copy link
Member

@pythonstrup pythonstrup commented Feb 6, 2025

작업 개요

  • cors 에러 수정

문제 원인

  • 기존 설정인 WebMvcConfig가 Spring Security에 의해 무시됨
  • Spring Security의 CorsConfig를 사용하는 방식으로 수정

@pythonstrup pythonstrup self-assigned this Feb 6, 2025
@pythonstrup pythonstrup linked an issue Feb 6, 2025 that may be closed by this pull request
Copy link

github-actions bot commented Feb 6, 2025

Test Results

57 tests   56 ✅  2s ⏱️
34 suites   1 💤
34 files     0 ❌

Results for commit ed25b65.

♻️ This comment has been updated with latest results.

Copy link
Member

@NaMinhyeok NaMinhyeok left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 !!

PR 제목이 컨벤션과 맞지않아요..!!

corsConfiguration.setAllowedOrigins(List.of(API_DOC_HOST, LOCAL_URL, JAKNAESO_WEB_VERCEL_APP));
corsConfiguration.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE"));
corsConfiguration.addAllowedHeader("*");
corsConfiguration.setAllowCredentials(true);
Copy link
Member

Choose a reason for hiding this comment

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

저도 찾아보니까 이거 쿠키관련 설정이라고 하던데 저희 쿠키안쓰는데 true로 해야되는건가요 ??

Copy link
Member Author

Choose a reason for hiding this comment

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

그렇네요. 쿠키 사용 안 하네요! 제거하도록 하겠습니다.

@@ -32,6 +34,7 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
.permitAll()
.anyRequest()
.authenticated())
.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource))
Copy link
Member

Choose a reason for hiding this comment

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

이건 그냥 궁금해서 물어보는건데 제가 공식문서를 제대로 읽은건지 모르겠는데..기존 세팅에서

Suggested change
.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource))
.cors(withDefaults())

쓰면 저희 Mvc 설정 따라가는걸까요 ??

https://docs.spring.io/spring-security/reference/servlet/integrations/cors.html
해당문서참고했습니다 ! PR머지 후 확인해봐도 될것같습니다

Copy link
Member Author

Choose a reason for hiding this comment

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

넵 감사합니다! 확인해볼게요!

Copy link
Member Author

@pythonstrup pythonstrup Feb 6, 2025

Choose a reason for hiding this comment

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

민혁님 말씀이 맞는 것 같아요. withDefaults()를 MVC 설정을 따라가는 것 같습니다. 이 메소드를 사용했으면 더 빨리 해결할 수 있었겠네요. 다만 CorsConfigurationSource를 사용하면 조금 더 세밀한 설정이 가능하다는 장점이 있어서 CorsConfigurationSource를 사용하는 게 좋다고 생각해요.
ex) API 엔드포인트별로 서로 다른 CORS 제어가 가능

@pythonstrup pythonstrup changed the title Fix/#64 cors 적용 에러 Fix(#64): cors 적용 에러 Feb 6, 2025
@pythonstrup pythonstrup merged commit 874fa6a into main Feb 6, 2025
2 checks passed
@NaMinhyeok NaMinhyeok deleted the fix/#64-cors-적용-에러 branch February 15, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: cors 정책 수정
2 participants